diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/audio_driver_jandroid.cpp | 13 | ||||
-rw-r--r-- | platform/android/audio_driver_jandroid.h | 2 | ||||
-rw-r--r-- | platform/android/audio_driver_opensl.cpp | 14 | ||||
-rw-r--r-- | platform/android/audio_driver_opensl.h | 2 | ||||
-rw-r--r-- | platform/android/export/export.cpp | 28 | ||||
-rw-r--r-- | platform/haiku/audio_driver_media_kit.cpp | 11 | ||||
-rw-r--r-- | platform/haiku/audio_driver_media_kit.h | 2 | ||||
-rw-r--r-- | platform/javascript/export/export.cpp | 27 | ||||
-rw-r--r-- | platform/uwp/os_uwp.cpp | 1 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 2 | ||||
-rw-r--r-- | platform/x11/joypad_linux.cpp | 28 | ||||
-rw-r--r-- | platform/x11/joypad_linux.h | 2 |
12 files changed, 51 insertions, 81 deletions
diff --git a/platform/android/audio_driver_jandroid.cpp b/platform/android/audio_driver_jandroid.cpp index 5a8e3b94da..e94dad9ac6 100644 --- a/platform/android/audio_driver_jandroid.cpp +++ b/platform/android/audio_driver_jandroid.cpp @@ -48,7 +48,7 @@ int AudioDriverAndroid::mix_rate = 44100; bool AudioDriverAndroid::quit = false; jobject AudioDriverAndroid::audioBuffer = NULL; void *AudioDriverAndroid::audioBufferPinned = NULL; -Mutex *AudioDriverAndroid::mutex = NULL; +Mutex AudioDriverAndroid::mutex; int32_t *AudioDriverAndroid::audioBuffer32 = NULL; const char *AudioDriverAndroid::get_name() const { @@ -58,7 +58,6 @@ const char *AudioDriverAndroid::get_name() const { Error AudioDriverAndroid::init() { - mutex = Mutex::create(); /* // TODO: pass in/return a (Java) device ID, also whether we're opening for input or output this->spec.samples = Android_JNI_OpenAudioDevice(this->spec.freq, this->spec.format == AUDIO_U8 ? 0 : 1, this->spec.channels, this->spec.samples); @@ -133,7 +132,7 @@ void AudioDriverAndroid::thread_func(JNIEnv *env) { int16_t *ptr = (int16_t *)audioBufferPinned; int fc = audioBufferFrames; - if (!s_ad->active || mutex->try_lock() != OK) { + if (!s_ad->active || mutex.try_lock() != OK) { for (int i = 0; i < fc; i++) { ptr[i] = 0; @@ -143,7 +142,7 @@ void AudioDriverAndroid::thread_func(JNIEnv *env) { s_ad->audio_server_process(fc / 2, audioBuffer32); - mutex->unlock(); + mutex.unlock(); for (int i = 0; i < fc; i++) { @@ -167,14 +166,12 @@ AudioDriver::SpeakerMode AudioDriverAndroid::get_speaker_mode() const { void AudioDriverAndroid::lock() { - if (mutex) - mutex->lock(); + mutex.lock(); } void AudioDriverAndroid::unlock() { - if (mutex) - mutex->unlock(); + mutex.unlock(); } void AudioDriverAndroid::finish() { diff --git a/platform/android/audio_driver_jandroid.h b/platform/android/audio_driver_jandroid.h index d3d1641c20..b1cc3f9aa0 100644 --- a/platform/android/audio_driver_jandroid.h +++ b/platform/android/audio_driver_jandroid.h @@ -37,7 +37,7 @@ class AudioDriverAndroid : public AudioDriver { - static Mutex *mutex; + static Mutex mutex; static AudioDriverAndroid *s_ad; static jobject io; static jmethodID _init_audio; diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp index 6e9864c803..307bc3a169 100644 --- a/platform/android/audio_driver_opensl.cpp +++ b/platform/android/audio_driver_opensl.cpp @@ -44,8 +44,8 @@ void AudioDriverOpenSL::_buffer_callback( if (pause) { mix = false; - } else if (mutex) { - mix = mutex->try_lock() == OK; + } else { + mix = mutex.try_lock() == OK; } if (mix) { @@ -58,8 +58,8 @@ void AudioDriverOpenSL::_buffer_callback( } } - if (mutex && mix) - mutex->unlock(); + if (mix) + mutex.unlock(); const int32_t *src_buff = mixdown_buffer; @@ -107,7 +107,6 @@ Error AudioDriverOpenSL::init() { void AudioDriverOpenSL::start() { - mutex = Mutex::create(); active = false; SLresult res; @@ -330,13 +329,13 @@ AudioDriver::SpeakerMode AudioDriverOpenSL::get_speaker_mode() const { void AudioDriverOpenSL::lock() { if (active && mutex) - mutex->lock(); + mutex.lock(); } void AudioDriverOpenSL::unlock() { if (active && mutex) - mutex->unlock(); + mutex.unlock(); } void AudioDriverOpenSL::finish() { @@ -359,7 +358,6 @@ void AudioDriverOpenSL::set_pause(bool p_pause) { AudioDriverOpenSL::AudioDriverOpenSL() { s_ad = this; - mutex = Mutex::create(); //NULL; pause = false; active = false; } diff --git a/platform/android/audio_driver_opensl.h b/platform/android/audio_driver_opensl.h index 57d9b30af6..569e2aa54b 100644 --- a/platform/android/audio_driver_opensl.h +++ b/platform/android/audio_driver_opensl.h @@ -40,7 +40,7 @@ class AudioDriverOpenSL : public AudioDriver { bool active; - Mutex *mutex; + Mutex mutex; enum { diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 50bf671a84..c618177475 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -257,7 +257,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { Vector<Device> devices; volatile bool devices_changed; - Mutex *device_lock; + Mutex device_lock; Thread *device_thread; volatile bool quit_request; @@ -288,7 +288,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { ldevices.push_back(d); } - ea->device_lock->lock(); + MutexLock lock(ea->device_lock); bool different = false; @@ -381,8 +381,6 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { ea->devices = ndevices; ea->devices_changed = true; } - - ea->device_lock->unlock(); } uint64_t sleep = 200; @@ -1432,11 +1430,8 @@ public: virtual int get_options_count() const { - device_lock->lock(); - int dc = devices.size(); - device_lock->unlock(); - - return dc; + MutexLock lock(device_lock); + return devices.size(); } virtual String get_options_tooltip() const { @@ -1447,16 +1442,14 @@ public: virtual String get_option_label(int p_index) const { ERR_FAIL_INDEX_V(p_index, devices.size(), ""); - device_lock->lock(); - String s = devices[p_index].name; - device_lock->unlock(); - return s; + MutexLock lock(device_lock); + return devices[p_index].name; } virtual String get_option_tooltip(int p_index) const { ERR_FAIL_INDEX_V(p_index, devices.size(), ""); - device_lock->lock(); + MutexLock lock(device_lock); String s = devices[p_index].description; if (devices.size() == 1) { // Tooltip will be: @@ -1464,7 +1457,6 @@ public: // Description s = devices[p_index].name + "\n\n" + s; } - device_lock->unlock(); return s; } @@ -1479,7 +1471,7 @@ public: return ERR_UNCONFIGURED; } - device_lock->lock(); + MutexLock lock(device_lock); EditorProgress ep("run", "Running on " + devices[p_device].name, 3); @@ -1487,7 +1479,6 @@ public: // Export_temp APK. if (ep.step("Exporting APK...", 0)) { - device_lock->unlock(); return ERR_SKIP; } @@ -1502,7 +1493,6 @@ public: #define CLEANUP_AND_RETURN(m_err) \ { \ DirAccess::remove_file_or_error(tmp_export_path); \ - device_lock->unlock(); \ return m_err; \ } @@ -2570,7 +2560,6 @@ public: run_icon.instance(); run_icon->create_from_image(img); - device_lock = Mutex::create(); devices_changed = true; quit_request = false; device_thread = Thread::create(_device_poll_thread, this); @@ -2579,7 +2568,6 @@ public: ~EditorExportPlatformAndroid() { quit_request = true; Thread::wait_to_finish(device_thread); - memdelete(device_lock); memdelete(device_thread); } }; diff --git a/platform/haiku/audio_driver_media_kit.cpp b/platform/haiku/audio_driver_media_kit.cpp index b7f6b57244..0a5df14743 100644 --- a/platform/haiku/audio_driver_media_kit.cpp +++ b/platform/haiku/audio_driver_media_kit.cpp @@ -67,7 +67,6 @@ Error AudioDriverMediaKit::init() { ERR_FAIL_COND_V(player == NULL, ERR_CANT_OPEN); } - mutex = Mutex::create(); player->Start(); return OK; @@ -108,14 +107,14 @@ void AudioDriverMediaKit::lock() { if (!mutex) return; - mutex->lock(); + mutex.lock(); } void AudioDriverMediaKit::unlock() { if (!mutex) return; - mutex->unlock(); + mutex.unlock(); } void AudioDriverMediaKit::finish() { @@ -124,15 +123,9 @@ void AudioDriverMediaKit::finish() { if (samples_in) { memdelete_arr(samples_in); }; - - if (mutex) { - memdelete(mutex); - mutex = NULL; - } } AudioDriverMediaKit::AudioDriverMediaKit() { - mutex = NULL; player = NULL; } diff --git a/platform/haiku/audio_driver_media_kit.h b/platform/haiku/audio_driver_media_kit.h index 06a362a89e..8272780fa7 100644 --- a/platform/haiku/audio_driver_media_kit.h +++ b/platform/haiku/audio_driver_media_kit.h @@ -40,7 +40,7 @@ #include <SoundPlayer.h> class AudioDriverMediaKit : public AudioDriver { - Mutex *mutex; + Mutex mutex; BSoundPlayer *player; static int32_t *samples_in; diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index c44a0270ab..f0326d5027 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -200,7 +200,7 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform { private: Ref<EditorHTTPServer> server; bool server_quit; - Mutex *server_lock; + Mutex server_lock; Thread *server_thread; static void _server_thread_poll(void *data); @@ -531,9 +531,8 @@ bool EditorExportPlatformJavaScript::poll_export() { menu_options = preset.is_valid(); if (server->is_listening()) { if (menu_options == 0) { - server_lock->lock(); + MutexLock lock(server_lock); server->stop(); - server_lock->unlock(); } else { menu_options += 1; } @@ -553,9 +552,8 @@ int EditorExportPlatformJavaScript::get_options_count() const { Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) { if (p_option == 1) { - server_lock->lock(); + MutexLock lock(server_lock); server->stop(); - server_lock->unlock(); return OK; } @@ -584,10 +582,12 @@ Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_prese ERR_FAIL_COND_V_MSG(!bind_ip.is_valid(), ERR_INVALID_PARAMETER, "Invalid editor setting 'export/web/http_host': '" + bind_host + "'. Try using '127.0.0.1'."); // Restart server. - server_lock->lock(); - server->stop(); - err = server->listen(bind_port, bind_ip); - server_lock->unlock(); + { + MutexLock lock(server_lock); + + server->stop(); + err = server->listen(bind_port, bind_ip); + } ERR_FAIL_COND_V_MSG(err != OK, err, "Unable to start HTTP server."); OS::get_singleton()->shell_open(String("http://" + bind_host + ":" + itos(bind_port) + "/tmp_js_export.html")); @@ -605,9 +605,10 @@ void EditorExportPlatformJavaScript::_server_thread_poll(void *data) { EditorExportPlatformJavaScript *ej = (EditorExportPlatformJavaScript *)data; while (!ej->server_quit) { OS::get_singleton()->delay_usec(1000); - ej->server_lock->lock(); - ej->server->poll(); - ej->server_lock->unlock(); + { + MutexLock lock(ej->server_lock); + ej->server->poll(); + } } } @@ -615,7 +616,6 @@ EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() { server.instance(); server_quit = false; - server_lock = Mutex::create(); server_thread = Thread::create(_server_thread_poll, this); Ref<Image> img = memnew(Image(_javascript_logo)); @@ -639,7 +639,6 @@ EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() { server->stop(); server_quit = true; Thread::wait_to_finish(server_thread); - memdelete(server_lock); memdelete(server_thread); } diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 3cd7a02a94..1e63d50263 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -141,7 +141,6 @@ void OS_UWP::initialize_core() { ThreadUWP::make_default(); SemaphoreWindows::make_default(); - MutexWindows::make_default(); RWLockWindows::make_default(); FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 716a637993..2b414dd5bf 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -47,7 +47,6 @@ #include "drivers/windows/dir_access_windows.h" #include "drivers/windows/file_access_windows.h" -#include "drivers/windows/mutex_windows.h" #include "drivers/windows/rw_lock_windows.h" #include "drivers/windows/semaphore_windows.h" #include "drivers/windows/thread_windows.h" @@ -230,7 +229,6 @@ void OS_Windows::initialize_core() { ThreadWindows::make_default(); SemaphoreWindows::make_default(); - MutexWindows::make_default(); RWLockWindows::make_default(); FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES); diff --git a/platform/x11/joypad_linux.cpp b/platform/x11/joypad_linux.cpp index a64a25aeee..a9fe7275c2 100644 --- a/platform/x11/joypad_linux.cpp +++ b/platform/x11/joypad_linux.cpp @@ -83,7 +83,6 @@ void JoypadLinux::Joypad::reset() { JoypadLinux::JoypadLinux(InputDefault *in) { exit_udev = false; input = in; - joy_mutex = Mutex::create(); joy_thread = Thread::create(joy_thread_func, this); } @@ -91,7 +90,6 @@ JoypadLinux::~JoypadLinux() { exit_udev = true; Thread::wait_to_finish(joy_thread); memdelete(joy_thread); - memdelete(joy_mutex); close_joypad(); } @@ -137,9 +135,8 @@ void JoypadLinux::enumerate_joypads(udev *p_udev) { String devnode_str = devnode; if (devnode_str.find(ignore_str) == -1) { - joy_mutex->lock(); + MutexLock lock(joy_mutex); open_joypad(devnode); - joy_mutex->unlock(); } } udev_device_unref(dev); @@ -176,7 +173,7 @@ void JoypadLinux::monitor_joypads(udev *p_udev) { if (dev && udev_device_get_devnode(dev) != 0) { - joy_mutex->lock(); + MutexLock lock(joy_mutex); String action = udev_device_get_action(dev); const char *devnode = udev_device_get_devnode(dev); if (devnode) { @@ -192,7 +189,6 @@ void JoypadLinux::monitor_joypads(udev *p_udev) { } udev_device_unref(dev); - joy_mutex->unlock(); } } usleep(50000); @@ -204,15 +200,17 @@ void JoypadLinux::monitor_joypads(udev *p_udev) { void JoypadLinux::monitor_joypads() { while (!exit_udev) { - joy_mutex->lock(); - for (int i = 0; i < 32; i++) { - char fname[64]; - sprintf(fname, "/dev/input/event%d", i); - if (attached_devices.find(fname) == -1) { - open_joypad(fname); + { + MutexLock lock(joy_mutex); + + for (int i = 0; i < 32; i++) { + char fname[64]; + sprintf(fname, "/dev/input/event%d", i); + if (attached_devices.find(fname) == -1) { + open_joypad(fname); + } } } - joy_mutex->unlock(); usleep(1000000); // 1s } } @@ -457,7 +455,7 @@ InputDefault::JoyAxis JoypadLinux::axis_correct(const input_absinfo *p_abs, int void JoypadLinux::process_joypads() { - if (joy_mutex->try_lock() != OK) { + if (joy_mutex.try_lock() != OK) { return; } for (int i = 0; i < JOYPADS_MAX; i++) { @@ -548,6 +546,6 @@ void JoypadLinux::process_joypads() { } } } - joy_mutex->unlock(); + joy_mutex.unlock(); } #endif diff --git a/platform/x11/joypad_linux.h b/platform/x11/joypad_linux.h index e5638899bf..d5719b6dbe 100644 --- a/platform/x11/joypad_linux.h +++ b/platform/x11/joypad_linux.h @@ -72,7 +72,7 @@ private: }; bool exit_udev; - Mutex *joy_mutex; + Mutex joy_mutex; Thread *joy_thread; InputDefault *input; Joypad joypads[JOYPADS_MAX]; |