diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 6e19bda90d0..94d42a28527 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -2689,12 +2689,14 @@ void _Marshalls::_bind_methods() { Error _Semaphore::wait() { - return semaphore->wait(); + semaphore.wait(); + return OK; // Can't fail anymore; keep compat } Error _Semaphore::post() { - return semaphore->post(); + semaphore.post(); + return OK; // Can't fail anymore; keep compat } void _Semaphore::_bind_methods() { @@ -2703,16 +2705,6 @@ void _Semaphore::_bind_methods() { ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post); } -_Semaphore::_Semaphore() { - - semaphore = Semaphore::create(); -} - -_Semaphore::~_Semaphore() { - - memdelete(semaphore); -} - /////////////// void _Mutex::lock() { diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 3995c9f01d8..5bb2da076ae 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -665,16 +665,13 @@ public: class _Semaphore : public Reference { GDCLASS(_Semaphore, Reference); - Semaphore *semaphore; + Semaphore semaphore; static void _bind_methods(); public: Error wait(); Error post(); - - _Semaphore(); - ~_Semaphore(); }; class _Thread : public Reference { diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index 5f0a257cbda..316c6ce1c4f 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -113,11 +113,10 @@ CommandQueueMT::CommandQueueMT(bool p_sync) { for (int i = 0; i < SYNC_SEMAPHORES; i++) { - sync_sems[i].sem = Semaphore::create(); sync_sems[i].in_use = false; } if (p_sync) { - sync = Semaphore::create(); + sync = memnew(Semaphore); } else { sync = NULL; } @@ -127,9 +126,5 @@ CommandQueueMT::~CommandQueueMT() { if (sync) memdelete(sync); - for (int i = 0; i < SYNC_SEMAPHORES; i++) { - - memdelete(sync_sems[i].sem); - } memfree(command_mem); } diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index ae0ca1d3150..d71ef61cce6 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -250,7 +250,7 @@ cmd->sync_sem = ss; \ unlock(); \ if (sync) sync->post(); \ - ss->sem->wait(); \ + ss->sem.wait(); \ ss->in_use = false; \ } @@ -267,7 +267,7 @@ cmd->sync_sem = ss; \ unlock(); \ if (sync) sync->post(); \ - ss->sem->wait(); \ + ss->sem.wait(); \ ss->in_use = false; \ } @@ -277,7 +277,7 @@ class CommandQueueMT { struct SyncSemaphore { - Semaphore *sem; + Semaphore sem; bool in_use; }; @@ -293,7 +293,7 @@ class CommandQueueMT { SyncSemaphore *sync_sem; virtual void post() { - sync_sem->sem->post(); + sync_sem->sem.post(); } }; diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index dc36c4159a3..d11ba68c72e 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -88,9 +88,7 @@ void FileAccessNetworkClient::_thread_func() { while (!quit) { DEBUG_PRINT("SEM WAIT - " + itos(sem->get())); - Error err = sem->wait(); - if (err != OK) - ERR_PRINT("sem->wait() failed"); + sem.wait(); DEBUG_TIME("sem_unlock"); //DEBUG_PRINT("semwait returned "+itos(werr)); DEBUG_PRINT("MUTEX LOCK " + itos(lockcount)); @@ -140,7 +138,7 @@ void FileAccessNetworkClient::_thread_func() { fa->_respond(len, Error(status)); } - fa->sem->post(); + fa->sem.post(); } break; case FileAccessNetwork::RESPONSE_DATA: { @@ -160,14 +158,14 @@ void FileAccessNetworkClient::_thread_func() { int status = get_32(); fa->exists_modtime = status != 0; - fa->sem->post(); + fa->sem.post(); } break; case FileAccessNetwork::RESPONSE_GET_MODTIME: { uint64_t status = get_64(); fa->exists_modtime = status; - fa->sem->post(); + fa->sem.post(); } break; } @@ -229,7 +227,6 @@ FileAccessNetworkClient::FileAccessNetworkClient() { singleton = this; last_id = 0; client.instance(); - sem = Semaphore::create(); lockcount = 0; } @@ -237,12 +234,10 @@ FileAccessNetworkClient::~FileAccessNetworkClient() { if (thread) { quit = true; - sem->post(); + sem.post(); Thread::wait_to_finish(thread); memdelete(thread); } - - memdelete(sem); } void FileAccessNetwork::_set_block(int p_offset, const Vector &p_block) { @@ -262,7 +257,7 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector &p_block) if (waiting_on_page == page) { waiting_on_page = -1; - page_sem->post(); + page_sem.post(); } } @@ -304,9 +299,9 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { nc->unlock_mutex(); DEBUG_PRINT("OPEN POST"); DEBUG_TIME("open_post"); - nc->sem->post(); //awaiting answer + nc->sem.post(); //awaiting answer DEBUG_PRINT("WAIT..."); - sem->wait(); + sem.wait(); DEBUG_TIME("open_end"); DEBUG_PRINT("WAIT ENDED..."); @@ -390,7 +385,7 @@ void FileAccessNetwork::_queue_page(int p_page) const { pages.write[p_page].queued = true; nc->blockrequest_mutex.unlock(); DEBUG_PRINT("QUEUE PAGE POST"); - nc->sem->post(); + nc->sem.post(); DEBUG_PRINT("queued " + itos(p_page)); } } @@ -423,7 +418,7 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { } buffer_mutex.unlock(); DEBUG_PRINT("wait"); - page_sem->wait(); + page_sem.wait(); DEBUG_PRINT("done"); } else { @@ -472,8 +467,8 @@ bool FileAccessNetwork::file_exists(const String &p_path) { nc->client->put_data((const uint8_t *)cs.ptr(), cs.length()); nc->unlock_mutex(); DEBUG_PRINT("FILE EXISTS POST"); - nc->sem->post(); - sem->wait(); + nc->sem.post(); + sem.wait(); return exists_modtime != 0; } @@ -489,8 +484,8 @@ uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) { nc->client->put_data((const uint8_t *)cs.ptr(), cs.length()); nc->unlock_mutex(); DEBUG_PRINT("MODTIME POST"); - nc->sem->post(); - sem->wait(); + nc->sem.post(); + sem.wait(); return exists_modtime; } @@ -518,8 +513,6 @@ FileAccessNetwork::FileAccessNetwork() { eof_flag = false; opened = false; pos = 0; - sem = Semaphore::create(); - page_sem = Semaphore::create(); FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; nc->lock_mutex(); id = nc->last_id++; @@ -535,8 +528,6 @@ FileAccessNetwork::FileAccessNetwork() { FileAccessNetwork::~FileAccessNetwork() { close(); - memdelete(sem); - memdelete(page_sem); FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; nc->lock_mutex(); diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h index ab234cdbc45..05ae24c5642 100644 --- a/core/io/file_access_network.h +++ b/core/io/file_access_network.h @@ -49,7 +49,7 @@ class FileAccessNetworkClient { List block_requests; - Semaphore *sem; + Semaphore sem; Thread *thread; bool quit; Mutex mutex; @@ -85,8 +85,8 @@ public: class FileAccessNetwork : public FileAccess { - Semaphore *sem; - Semaphore *page_sem; + Semaphore sem; + Semaphore page_sem; Mutex buffer_mutex; bool opened; size_t total_size; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 7e7dc252c1a..a059067a4cb 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -71,7 +71,7 @@ struct _IP_ResolverPrivate { } Mutex mutex; - Semaphore *sem; + Semaphore sem; Thread *thread; //Semaphore* semaphore; @@ -98,7 +98,7 @@ struct _IP_ResolverPrivate { while (!ipr->thread_abort) { - ipr->sem->wait(); + ipr->sem.wait(); ipr->mutex.lock(); ipr->resolve_queues(); @@ -152,7 +152,7 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ resolver->queue[id].response = IP_Address(); resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING; if (resolver->thread) - resolver->sem->post(); + resolver->sem.post(); else resolver->resolve_queues(); } @@ -314,23 +314,11 @@ IP::IP() { singleton = this; resolver = memnew(_IP_ResolverPrivate); - resolver->sem = NULL; #ifndef NO_THREADS - - resolver->sem = Semaphore::create(); - if (resolver->sem) { - resolver->thread_abort = false; - - resolver->thread = Thread::create(_IP_ResolverPrivate::_thread_function, resolver); - - if (!resolver->thread) - memdelete(resolver->sem); //wtf - } else { - resolver->thread = NULL; - } + resolver->thread_abort = false; + resolver->thread = Thread::create(_IP_ResolverPrivate::_thread_function, resolver); #else - resolver->sem = NULL; resolver->thread = NULL; #endif } @@ -340,10 +328,9 @@ IP::~IP() { #ifndef NO_THREADS if (resolver->thread) { resolver->thread_abort = true; - resolver->sem->post(); + resolver->sem.post(); Thread::wait_to_finish(resolver->thread); memdelete(resolver->thread); - memdelete(resolver->sem); } #endif diff --git a/core/os/semaphore.cpp b/core/os/semaphore.cpp deleted file mode 100644 index 32bbeceb34d..00000000000 --- a/core/os/semaphore.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************/ -/* semaphore.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "semaphore.h" - -#include "core/error_macros.h" - -Semaphore *(*Semaphore::create_func)() = 0; - -Semaphore *Semaphore::create() { - - ERR_FAIL_COND_V(!create_func, 0); - - return create_func(); -} - -Semaphore::~Semaphore() { -} diff --git a/core/os/semaphore.h b/core/os/semaphore.h index 6ddb36879e9..8efd6425ad5 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -32,19 +32,59 @@ #define SEMAPHORE_H #include "core/error_list.h" +#include "core/typedefs.h" + +#if !defined(NO_THREADS) + +#include +#include class Semaphore { -protected: - static Semaphore *(*create_func)(); +private: + mutable std::mutex mutex_; + mutable std::condition_variable condition_; + mutable unsigned long count_ = 0; // Initialized as locked. public: - virtual Error wait() = 0; ///< wait until semaphore has positive value, then decrement and pass - virtual Error post() = 0; ///< unlock the semaphore, incrementing the value - virtual int get() const = 0; ///< get semaphore value + _ALWAYS_INLINE_ void post() const { + std::lock_guard lock(mutex_); + ++count_; + condition_.notify_one(); + } - static Semaphore *create(); ///< Create a mutex + _ALWAYS_INLINE_ void wait() const { + std::unique_lock lock(mutex_); + while (!count_) { // Handle spurious wake-ups. + condition_.wait(lock); + } + --count_; + } - virtual ~Semaphore(); + _ALWAYS_INLINE_ bool try_wait() const { + std::lock_guard lock(mutex_); + if (count_) { + --count_; + return true; + } + return false; + } + + _ALWAYS_INLINE_ int get() const { + std::lock_guard lock(mutex_); + return count_; + } +}; + +#else + +class Semaphore { +public: + _ALWAYS_INLINE_ void post() const {} + _ALWAYS_INLINE_ void wait() const {} + _ALWAYS_INLINE_ bool try_wait() const { return true; } + _ALWAYS_INLINE_ int get() const { return 1; } }; #endif + +#endif // SEMAPHORE_H diff --git a/core/os/thread_dummy.cpp b/core/os/thread_dummy.cpp index 6f133370bee..3b2f6438c49 100644 --- a/core/os/thread_dummy.cpp +++ b/core/os/thread_dummy.cpp @@ -39,11 +39,3 @@ Thread *ThreadDummy::create(ThreadCreateCallback p_callback, void *p_user, const void ThreadDummy::make_default() { Thread::create_func = &ThreadDummy::create; }; - -Semaphore *SemaphoreDummy::create() { - return memnew(SemaphoreDummy); -}; - -void SemaphoreDummy::make_default() { - Semaphore::create_func = &SemaphoreDummy::create; -}; diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h index 2e36140760c..f86aaaecd12 100644 --- a/core/os/thread_dummy.h +++ b/core/os/thread_dummy.h @@ -45,16 +45,4 @@ public: static void make_default(); }; -class SemaphoreDummy : public Semaphore { - - static Semaphore *create(); - -public: - virtual Error wait() { return OK; }; - virtual Error post() { return OK; }; - virtual int get() const { return 0; }; ///< get semaphore value - - static void make_default(); -}; - #endif diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index b3102dc9681..32a4e0425f6 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -37,7 +37,6 @@ #include "drivers/unix/dir_access_unix.h" #include "drivers/unix/file_access_unix.h" #include "drivers/unix/net_socket_posix.h" -#include "drivers/unix/semaphore_posix.h" #include "drivers/unix/thread_posix.h" #include "servers/visual_server.h" @@ -121,12 +120,8 @@ void OS_Unix::initialize_core() { #ifdef NO_THREADS ThreadDummy::make_default(); - SemaphoreDummy::make_default(); #else ThreadPosix::make_default(); -#if !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED) - SemaphorePosix::make_default(); -#endif #endif FileAccess::make_default(FileAccess::ACCESS_RESOURCES); FileAccess::make_default(FileAccess::ACCESS_USERDATA); diff --git a/drivers/unix/semaphore_posix.cpp b/drivers/unix/semaphore_posix.cpp deleted file mode 100644 index 32055401a51..00000000000 --- a/drivers/unix/semaphore_posix.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************/ -/* semaphore_posix.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "semaphore_posix.h" - -#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED) - -#include "core/os/memory.h" -#include -#include - -Error SemaphorePosix::wait() { - - while (sem_wait(&sem)) { - if (errno == EINTR) { - errno = 0; - continue; - } else { - perror("sem waiting"); - return ERR_BUSY; - } - } - return OK; -} - -Error SemaphorePosix::post() { - - return (sem_post(&sem) == 0) ? OK : ERR_BUSY; -} -int SemaphorePosix::get() const { - - int val; - sem_getvalue(&sem, &val); - - return val; -} - -Semaphore *SemaphorePosix::create_semaphore_posix() { - - return memnew(SemaphorePosix); -} - -void SemaphorePosix::make_default() { - - create_func = create_semaphore_posix; -} - -SemaphorePosix::SemaphorePosix() { - - int r = sem_init(&sem, 0, 0); - if (r != 0) - perror("sem creating"); -} - -SemaphorePosix::~SemaphorePosix() { - - sem_destroy(&sem); -} - -#endif diff --git a/drivers/unix/semaphore_posix.h b/drivers/unix/semaphore_posix.h deleted file mode 100644 index 53c27dc9fe3..00000000000 --- a/drivers/unix/semaphore_posix.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************/ -/* semaphore_posix.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef SEMAPHORE_POSIX_H -#define SEMAPHORE_POSIX_H - -#include "core/os/semaphore.h" - -#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED) - -#include - -class SemaphorePosix : public Semaphore { - - mutable sem_t sem; - - static Semaphore *create_semaphore_posix(); - -public: - virtual Error wait(); - virtual Error post(); - virtual int get() const; - - static void make_default(); - SemaphorePosix(); - - ~SemaphorePosix(); -}; - -#endif -#endif diff --git a/drivers/windows/semaphore_windows.cpp b/drivers/windows/semaphore_windows.cpp deleted file mode 100644 index 9f39bda3e69..00000000000 --- a/drivers/windows/semaphore_windows.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/*************************************************************************/ -/* semaphore_windows.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "semaphore_windows.h" - -#if defined(WINDOWS_ENABLED) - -#include "core/os/memory.h" - -Error SemaphoreWindows::wait() { - - WaitForSingleObjectEx(semaphore, INFINITE, false); - return OK; -} -Error SemaphoreWindows::post() { - - ReleaseSemaphore(semaphore, 1, NULL); - return OK; -} -int SemaphoreWindows::get() const { - long previous; - switch (WaitForSingleObjectEx(semaphore, 0, false)) { - case WAIT_OBJECT_0: { - ERR_FAIL_COND_V(!ReleaseSemaphore(semaphore, 1, &previous), -1); - return previous + 1; - } break; - case WAIT_TIMEOUT: { - return 0; - } break; - default: { - } - } - - ERR_FAIL_V(-1); -} - -Semaphore *SemaphoreWindows::create_semaphore_windows() { - - return memnew(SemaphoreWindows); -} - -void SemaphoreWindows::make_default() { - - create_func = create_semaphore_windows; -} - -SemaphoreWindows::SemaphoreWindows() { - -#ifdef UWP_ENABLED - semaphore = CreateSemaphoreEx( - NULL, - 0, - 0xFFFFFFF, //wathever - NULL, - 0, - SEMAPHORE_ALL_ACCESS); -#else - semaphore = CreateSemaphore( - NULL, - 0, - 0xFFFFFFF, //wathever - NULL); -#endif -} - -SemaphoreWindows::~SemaphoreWindows() { - - CloseHandle(semaphore); -} - -#endif diff --git a/drivers/windows/semaphore_windows.h b/drivers/windows/semaphore_windows.h deleted file mode 100644 index 56499689f52..00000000000 --- a/drivers/windows/semaphore_windows.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************/ -/* semaphore_windows.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef SEMAPHORE_WINDOWS_H -#define SEMAPHORE_WINDOWS_H - -#include "core/os/semaphore.h" - -#ifdef WINDOWS_ENABLED - -#include - -class SemaphoreWindows : public Semaphore { - - mutable HANDLE semaphore; - - static Semaphore *create_semaphore_windows(); - -public: - virtual Error wait(); - virtual Error post(); - virtual int get() const; - - static void make_default(); - SemaphoreWindows(); - - ~SemaphoreWindows(); -}; - -#endif -#endif diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 2e6508146e8..acc96a57a40 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -220,7 +220,7 @@ void EditorResourcePreview::_thread() { exited = false; while (!exit) { - preview_sem->wait(); + preview_sem.wait(); preview_mutex.lock(); if (queue.size()) { @@ -381,7 +381,7 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref &p queue.push_back(item); preview_mutex.unlock(); - preview_sem->post(); + preview_sem.post(); } void EditorResourcePreview::queue_resource_preview(const String &p_path, Object *p_receiver, const StringName &p_receiver_func, const Variant &p_userdata) { @@ -403,7 +403,7 @@ void EditorResourcePreview::queue_resource_preview(const String &p_path, Object queue.push_back(item); preview_mutex.unlock(); - preview_sem->post(); + preview_sem.post(); } void EditorResourcePreview::add_preview_generator(const Ref &p_generator) { @@ -463,7 +463,7 @@ void EditorResourcePreview::start() { void EditorResourcePreview::stop() { if (thread) { exit = true; - preview_sem->post(); + preview_sem.post(); while (!exited) { OS::get_singleton()->delay_usec(10000); VisualServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on visual server @@ -477,7 +477,6 @@ void EditorResourcePreview::stop() { EditorResourcePreview::EditorResourcePreview() { thread = NULL; singleton = this; - preview_sem = Semaphore::create(); order = 0; exit = false; exited = false; @@ -486,5 +485,4 @@ EditorResourcePreview::EditorResourcePreview() { EditorResourcePreview::~EditorResourcePreview() { stop(); - memdelete(preview_sem); } diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h index dae8ce30944..4fd796e1be9 100644 --- a/editor/editor_resource_preview.h +++ b/editor/editor_resource_preview.h @@ -71,7 +71,7 @@ class EditorResourcePreview : public Node { List queue; Mutex preview_mutex; - Semaphore *preview_sem; + Semaphore preview_sem; Thread *thread; volatile bool exit; volatile bool exited; diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index a457147c3c8..9899c6efcce 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -44,7 +44,7 @@ int VideoStreamPlaybackTheora::buffer_data() { int read; do { - thread_sem->post(); + thread_sem.post(); read = MIN(ring_buffer.data_left(), 4096); if (read) { ring_buffer.read((uint8_t *)buffer, read); @@ -141,7 +141,7 @@ void VideoStreamPlaybackTheora::clear() { #ifdef THEORA_USE_THREAD_STREAMING thread_exit = true; - thread_sem->post(); //just in case + thread_sem.post(); //just in case Thread::wait_to_finish(thread); memdelete(thread); thread = NULL; @@ -385,7 +385,7 @@ void VideoStreamPlaybackTheora::update(float p_delta) { }; #ifdef THEORA_USE_THREAD_STREAMING - thread_sem->post(); + thread_sem.post(); #endif time += p_delta; @@ -664,7 +664,7 @@ void VideoStreamPlaybackTheora::_streaming_thread(void *ud) { } } - vs->thread_sem->wait(); + vs->thread_sem.wait(); } } @@ -693,7 +693,6 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { int rb_power = nearest_shift(RB_SIZE_KB * 1024); ring_buffer.resize(rb_power); read_buffer.resize(RB_SIZE_KB * 1024); - thread_sem = Semaphore::create(); thread = NULL; thread_exit = false; thread_eof = false; @@ -703,10 +702,6 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() { -#ifdef THEORA_USE_THREAD_STREAMING - - memdelete(thread_sem); -#endif clear(); if (file) diff --git a/modules/theora/video_stream_theora.h b/modules/theora/video_stream_theora.h index 694cc408017..b86e8547aab 100644 --- a/modules/theora/video_stream_theora.h +++ b/modules/theora/video_stream_theora.h @@ -112,7 +112,7 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback { RingBuffer ring_buffer; Vector read_buffer; bool thread_eof; - Semaphore *thread_sem; + Semaphore thread_sem; Thread *thread; volatile bool thread_exit; diff --git a/platform/iphone/SCsub b/platform/iphone/SCsub index df4aae021e6..983bfad6305 100644 --- a/platform/iphone/SCsub +++ b/platform/iphone/SCsub @@ -3,7 +3,6 @@ Import("env") iphone_lib = [ - "semaphore_iphone.cpp", "godot_iphone.mm", "os_iphone.mm", "main.m", diff --git a/platform/iphone/os_iphone.mm b/platform/iphone/os_iphone.mm index ae9e3675fcb..9874dbe61ed 100644 --- a/platform/iphone/os_iphone.mm +++ b/platform/iphone/os_iphone.mm @@ -45,8 +45,6 @@ #include "core/project_settings.h" #include "drivers/unix/syslog_logger.h" -#include "semaphore_iphone.h" - #import "app_delegate.h" #import "device_metrics.h" #import "godot_view.h" @@ -104,7 +102,6 @@ String OSIPhone::get_unique_id() const { void OSIPhone::initialize_core() { OS_Unix::initialize_core(); - SemaphoreIphone::make_default(); set_data_dir(data_dir); }; diff --git a/platform/iphone/semaphore_iphone.cpp b/platform/iphone/semaphore_iphone.cpp deleted file mode 100644 index 71d4a0f4454..00000000000 --- a/platform/iphone/semaphore_iphone.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/*************************************************************************/ -/* semaphore_iphone.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "semaphore_iphone.h" - -#include -#include - -void cgsem_init(cgsem_t *); -void cgsem_post(cgsem_t *); -void cgsem_wait(cgsem_t *); -void cgsem_destroy(cgsem_t *); - -void cgsem_init(cgsem_t *cgsem) { - int flags, fd, i; - - pipe(cgsem->pipefd); - - /* Make the pipes FD_CLOEXEC to allow them to close should we call - * execv on restart. */ - for (i = 0; i < 2; i++) { - fd = cgsem->pipefd[i]; - flags = fcntl(fd, F_GETFD, 0); - flags |= FD_CLOEXEC; - fcntl(fd, F_SETFD, flags); - } -} - -void cgsem_post(cgsem_t *cgsem) { - const char buf = 1; - - write(cgsem->pipefd[1], &buf, 1); -} - -void cgsem_wait(cgsem_t *cgsem) { - char buf; - - read(cgsem->pipefd[0], &buf, 1); -} - -void cgsem_destroy(cgsem_t *cgsem) { - close(cgsem->pipefd[1]); - close(cgsem->pipefd[0]); -} - -#include "core/os/memory.h" - -#include - -Error SemaphoreIphone::wait() { - - cgsem_wait(&sem); - return OK; -} - -Error SemaphoreIphone::post() { - - cgsem_post(&sem); - - return OK; -} -int SemaphoreIphone::get() const { - - return 0; -} - -Semaphore *SemaphoreIphone::create_semaphore_iphone() { - - return memnew(SemaphoreIphone); -} - -void SemaphoreIphone::make_default() { - - create_func = create_semaphore_iphone; -} - -SemaphoreIphone::SemaphoreIphone() { - - cgsem_init(&sem); -} - -SemaphoreIphone::~SemaphoreIphone() { - - cgsem_destroy(&sem); -} diff --git a/platform/iphone/semaphore_iphone.h b/platform/iphone/semaphore_iphone.h deleted file mode 100644 index 10d94245ba6..00000000000 --- a/platform/iphone/semaphore_iphone.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************/ -/* semaphore_iphone.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef SEMAPHORE_IPHONE_H -#define SEMAPHORE_IPHONE_H - -struct cgsem { - int pipefd[2]; -}; - -typedef struct cgsem cgsem_t; - -#include "core/os/semaphore.h" - -class SemaphoreIphone : public Semaphore { - - mutable cgsem_t sem; - - static Semaphore *create_semaphore_iphone(); - -public: - virtual Error wait(); - virtual Error post(); - virtual int get() const; - - static void make_default(); - SemaphoreIphone(); - - ~SemaphoreIphone(); -}; - -#endif // SEMAPHORE_IPHONE_H diff --git a/platform/osx/SCsub b/platform/osx/SCsub index cd9b5d59b90..e3f61d9e063 100644 --- a/platform/osx/SCsub +++ b/platform/osx/SCsub @@ -9,7 +9,6 @@ files = [ "crash_handler_osx.mm", "os_osx.mm", "godot_main_osx.mm", - "semaphore_osx.cpp", "dir_access_osx.mm", "joypad_osx.cpp", "power_osx.cpp", diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 6dbf145e0f4..5e1e62107bd 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -38,7 +38,6 @@ #include "drivers/gles2/rasterizer_gles2.h" #include "drivers/gles3/rasterizer_gles3.h" #include "main/main.h" -#include "semaphore_osx.h" #include "servers/visual/visual_server_raster.h" #include @@ -1527,8 +1526,6 @@ void OS_OSX::initialize_core() { DirAccess::make_default(DirAccess::ACCESS_RESOURCES); DirAccess::make_default(DirAccess::ACCESS_USERDATA); DirAccess::make_default(DirAccess::ACCESS_FILESYSTEM); - - SemaphoreOSX::make_default(); } struct LayoutInfo { diff --git a/platform/osx/semaphore_osx.cpp b/platform/osx/semaphore_osx.cpp deleted file mode 100644 index e95edaaca88..00000000000 --- a/platform/osx/semaphore_osx.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/*************************************************************************/ -/* semaphore_osx.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "semaphore_osx.h" - -#include -#include - -void cgsem_init(cgsem_t *cgsem) { - int flags, fd, i; - - pipe(cgsem->pipefd); - - /* Make the pipes FD_CLOEXEC to allow them to close should we call - * execv on restart. */ - for (i = 0; i < 2; i++) { - fd = cgsem->pipefd[i]; - flags = fcntl(fd, F_GETFD, 0); - flags |= FD_CLOEXEC; - fcntl(fd, F_SETFD, flags); - } -} - -void cgsem_post(cgsem_t *cgsem) { - const char buf = 1; - - write(cgsem->pipefd[1], &buf, 1); -} - -void cgsem_wait(cgsem_t *cgsem) { - char buf; - - read(cgsem->pipefd[0], &buf, 1); -} - -void cgsem_destroy(cgsem_t *cgsem) { - close(cgsem->pipefd[1]); - close(cgsem->pipefd[0]); -} - -#include "core/os/memory.h" - -#include - -Error SemaphoreOSX::wait() { - - cgsem_wait(&sem); - return OK; -} - -Error SemaphoreOSX::post() { - - cgsem_post(&sem); - - return OK; -} -int SemaphoreOSX::get() const { - - return 0; -} - -Semaphore *SemaphoreOSX::create_semaphore_osx() { - - return memnew(SemaphoreOSX); -} - -void SemaphoreOSX::make_default() { - - create_func = create_semaphore_osx; -} - -SemaphoreOSX::SemaphoreOSX() { - - cgsem_init(&sem); -} - -SemaphoreOSX::~SemaphoreOSX() { - - cgsem_destroy(&sem); -} diff --git a/platform/osx/semaphore_osx.h b/platform/osx/semaphore_osx.h deleted file mode 100644 index 262087f7583..00000000000 --- a/platform/osx/semaphore_osx.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************/ -/* semaphore_osx.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef SEMAPHORE_OSX_H -#define SEMAPHORE_OSX_H - -struct cgsem { - int pipefd[2]; -}; - -typedef struct cgsem cgsem_t; - -#include "core/os/semaphore.h" - -class SemaphoreOSX : public Semaphore { - - mutable cgsem_t sem; - - static Semaphore *create_semaphore_osx(); - -public: - virtual Error wait(); - virtual Error post(); - virtual int get() const; - - static void make_default(); - SemaphoreOSX(); - - ~SemaphoreOSX(); -}; - -#endif // SEMAPHORE_OSX_H diff --git a/platform/server/SCsub b/platform/server/SCsub index 00402d09298..38981ad162e 100644 --- a/platform/server/SCsub +++ b/platform/server/SCsub @@ -11,7 +11,6 @@ common_server = [ if sys.platform == "darwin": common_server.append("#platform/osx/crash_handler_osx.mm") common_server.append("#platform/osx/power_osx.cpp") - common_server.append("#platform/osx/semaphore_osx.cpp") else: common_server.append("#platform/x11/crash_handler_x11.cpp") common_server.append("#platform/x11/power_x11.cpp") diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp index 94bd8156655..2b283899fd8 100644 --- a/platform/server/os_server.cpp +++ b/platform/server/os_server.cpp @@ -68,10 +68,6 @@ void OS_Server::initialize_core() { crash_handler.initialize(); OS_Unix::initialize_core(); - -#ifdef __APPLE__ - SemaphoreOSX::make_default(); -#endif } Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) { diff --git a/platform/server/os_server.h b/platform/server/os_server.h index e1f874a09ad..77938ea088f 100644 --- a/platform/server/os_server.h +++ b/platform/server/os_server.h @@ -37,7 +37,6 @@ #ifdef __APPLE__ #include "platform/osx/crash_handler_osx.h" #include "platform/osx/power_osx.h" -#include "platform/osx/semaphore_osx.h" #else #include "platform/x11/crash_handler_x11.h" #include "platform/x11/power_x11.h" diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 0ea07431210..fa739593259 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -40,7 +40,6 @@ #include "drivers/unix/ip_unix.h" #include "drivers/windows/dir_access_windows.h" #include "drivers/windows/file_access_windows.h" -#include "drivers/windows/semaphore_windows.h" #include "main/main.h" #include "platform/windows/windows_terminal_logger.h" #include "servers/audio_server.h" @@ -139,7 +138,6 @@ void OS_UWP::initialize_core() { //RedirectIOToConsole(); ThreadUWP::make_default(); - SemaphoreWindows::make_default(); FileAccess::make_default(FileAccess::ACCESS_RESOURCES); FileAccess::make_default(FileAccess::ACCESS_USERDATA); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 3952d17a613..6c41190c04b 100755 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -40,7 +40,6 @@ #include "drivers/gles3/rasterizer_gles3.h" #include "drivers/windows/dir_access_windows.h" #include "drivers/windows/file_access_windows.h" -#include "drivers/windows/semaphore_windows.h" #include "drivers/windows/thread_windows.h" #include "joypad_windows.h" #include "lang_table.h" @@ -226,7 +225,6 @@ void OS_Windows::initialize_core() { borderless = false; ThreadWindows::make_default(); - SemaphoreWindows::make_default(); FileAccess::make_default(FileAccess::ACCESS_RESOURCES); FileAccess::make_default(FileAccess::ACCESS_USERDATA); diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.cpp b/servers/physics_2d/physics_2d_server_wrap_mt.cpp index 54cd45d67b3..9710d383887 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.cpp +++ b/servers/physics_2d/physics_2d_server_wrap_mt.cpp @@ -40,7 +40,7 @@ void Physics2DServerWrapMT::thread_exit() { void Physics2DServerWrapMT::thread_step(real_t p_delta) { physics_2d_server->step(p_delta); - step_sem->post(); + step_sem.post(); } void Physics2DServerWrapMT::_thread_callback(void *_instance) { @@ -84,12 +84,13 @@ void Physics2DServerWrapMT::step(real_t p_step) { void Physics2DServerWrapMT::sync() { - if (step_sem) { + if (create_thread) { if (first_frame) first_frame = false; else - step_sem->wait(); //must not wait if a step was not issued + step_sem.wait(); //must not wait if a step was not issued } + physics_2d_server->sync(); } @@ -107,7 +108,6 @@ void Physics2DServerWrapMT::init() { if (create_thread) { - step_sem = Semaphore::create(); //OS::get_singleton()->release_rendering_thread(); if (create_thread) { thread = Thread::create(_thread_callback, this); @@ -146,9 +146,6 @@ void Physics2DServerWrapMT::finish() { space_free_cached_ids(); area_free_cached_ids(); body_free_cached_ids(); - - if (step_sem) - memdelete(step_sem); } Physics2DServerWrapMT::Physics2DServerWrapMT(Physics2DServer *p_contained, bool p_create_thread) : @@ -157,7 +154,6 @@ Physics2DServerWrapMT::Physics2DServerWrapMT(Physics2DServer *p_contained, bool physics_2d_server = p_contained; create_thread = p_create_thread; thread = NULL; - step_sem = NULL; step_pending = 0; step_thread_up = false; diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h index 73b3f2db5e9..ed47756e4fc 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.h +++ b/servers/physics_2d/physics_2d_server_wrap_mt.h @@ -58,7 +58,7 @@ class Physics2DServerWrapMT : public Physics2DServer { volatile bool step_thread_up; bool create_thread; - Semaphore *step_sem; + Semaphore step_sem; int step_pending; void thread_step(real_t p_delta); void thread_flush(); diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index 8e7e93f1fee..8b7264c74eb 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -2711,7 +2711,7 @@ void VisualServerScene::_gi_probe_bake_thread() { while (true) { - probe_bake_sem->wait(); + probe_bake_sem.wait(); if (probe_bake_thread_exit) { break; } @@ -3410,7 +3410,7 @@ void VisualServerScene::render_probes() { probe->dynamic.updating_stage = GI_UPDATE_STAGE_LIGHTING; probe_bake_list.push_back(instance_probe); probe_bake_mutex.unlock(); - probe_bake_sem->post(); + probe_bake_sem.post(); #else @@ -3683,7 +3683,6 @@ VisualServerScene *VisualServerScene::singleton = NULL; VisualServerScene::VisualServerScene() { #ifndef NO_THREADS - probe_bake_sem = Semaphore::create(); probe_bake_thread = Thread::create(_gi_probe_bake_threads, this); probe_bake_thread_exit = false; #endif @@ -3697,9 +3696,8 @@ VisualServerScene::~VisualServerScene() { #ifndef NO_THREADS probe_bake_thread_exit = true; - probe_bake_sem->post(); + probe_bake_sem.post(); Thread::wait_to_finish(probe_bake_thread); memdelete(probe_bake_thread); - memdelete(probe_bake_sem); #endif } diff --git a/servers/visual/visual_server_scene.h b/servers/visual/visual_server_scene.h index d9199c69875..7c2d6916de0 100644 --- a/servers/visual/visual_server_scene.h +++ b/servers/visual/visual_server_scene.h @@ -593,7 +593,7 @@ public: volatile bool probe_bake_thread_exit; Thread *probe_bake_thread; - Semaphore *probe_bake_sem; + Semaphore probe_bake_sem; Mutex probe_bake_mutex; List probe_bake_list;