summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-03-05 16:33:45 +0100
committerGitHub <noreply@github.com>2020-03-05 16:33:45 +0100
commit42595085a5a22f3b5399844d06e89631c42e8981 (patch)
treeda1c7092d1b0960891b4634358b1150f679fa805
parentbd553d072b65fe5359ab76e64566ff316d35c62e (diff)
parent9a3a2b03b8b718409eb26252d742d48091756ef7 (diff)
Merge pull request #36752 from RandomShaper/rework_semaphore
Drop old semaphore implementation
-rw-r--r--core/bind/core_bind.cpp24
-rw-r--r--core/bind/core_bind.h10
-rw-r--r--core/command_queue_mt.cpp7
-rw-r--r--core/command_queue_mt.h10
-rw-r--r--core/io/file_access_network.cpp37
-rw-r--r--core/io/file_access_network.h6
-rw-r--r--core/io/ip.cpp23
-rw-r--r--core/os/mutex.h2
-rw-r--r--core/os/semaphore.cpp14
-rw-r--r--core/os/semaphore.h31
-rw-r--r--core/os/thread_dummy.cpp8
-rw-r--r--core/os/thread_dummy.h12
-rw-r--r--doc/classes/Semaphore.xml13
-rw-r--r--drivers/unix/os_unix.cpp5
-rw-r--r--drivers/unix/semaphore_posix.cpp87
-rw-r--r--drivers/unix/semaphore_posix.h58
-rw-r--r--drivers/windows/semaphore_windows.cpp98
-rw-r--r--drivers/windows/semaphore_windows.h58
-rw-r--r--editor/editor_resource_preview.cpp10
-rw-r--r--editor/editor_resource_preview.h2
-rw-r--r--platform/iphone/os_iphone.cpp1
-rw-r--r--platform/iphone/semaphore_iphone.cpp112
-rw-r--r--platform/iphone/semaphore_iphone.h59
-rw-r--r--platform/osx/SCsub1
-rw-r--r--platform/osx/os_osx.mm3
-rw-r--r--platform/osx/semaphore_osx.cpp107
-rw-r--r--platform/osx/semaphore_osx.h59
-rw-r--r--platform/server/SCsub1
-rw-r--r--platform/server/os_server.cpp4
-rw-r--r--platform/uwp/os_uwp.cpp1
-rw-r--r--platform/windows/os_windows.cpp2
-rw-r--r--servers/physics_2d/physics_2d_server_wrap_mt.cpp15
-rw-r--r--servers/physics_2d/physics_2d_server_wrap_mt.h2
33 files changed, 79 insertions, 803 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 264d8d415c..bfe07d61c5 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -2576,30 +2576,26 @@ void _Marshalls::_bind_methods() {
////////////////
-Error _Semaphore::wait() {
+void _Semaphore::wait() {
- return semaphore->wait();
+ semaphore.wait();
}
-Error _Semaphore::post() {
+Error _Semaphore::try_wait() {
- return semaphore->post();
+ return semaphore.try_wait() ? OK : ERR_BUSY;
}
-void _Semaphore::_bind_methods() {
+void _Semaphore::post() {
- ClassDB::bind_method(D_METHOD("wait"), &_Semaphore::wait);
- ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post);
+ semaphore.post();
}
-_Semaphore::_Semaphore() {
-
- semaphore = SemaphoreOld::create();
-}
-
-_Semaphore::~_Semaphore() {
+void _Semaphore::_bind_methods() {
- memdelete(semaphore);
+ ClassDB::bind_method(D_METHOD("wait"), &_Semaphore::wait);
+ ClassDB::bind_method(D_METHOD("try_wait"), &_Semaphore::try_wait);
+ ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post);
}
///////////////
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index e7850de744..fc6419b7d8 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -635,16 +635,14 @@ public:
class _Semaphore : public Reference {
GDCLASS(_Semaphore, Reference);
- SemaphoreOld *semaphore;
+ Semaphore semaphore;
static void _bind_methods();
public:
- Error wait();
- Error post();
-
- _Semaphore();
- ~_Semaphore();
+ void wait();
+ Error try_wait();
+ void post();
};
class _Thread : public Reference {
diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp
index b88f773ed8..85e8a847a0 100644
--- a/core/command_queue_mt.cpp
+++ b/core/command_queue_mt.cpp
@@ -108,11 +108,10 @@ CommandQueueMT::CommandQueueMT(bool p_sync) {
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
- sync_sems[i].sem = SemaphoreOld::create();
sync_sems[i].in_use = false;
}
if (p_sync)
- sync = SemaphoreOld::create();
+ sync = memnew(Semaphore);
else
sync = NULL;
}
@@ -121,9 +120,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 7407557e7e..90231546ef 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -270,7 +270,7 @@
cmd->sync_sem = ss; \
unlock(); \
if (sync) sync->post(); \
- ss->sem->wait(); \
+ ss->sem.wait(); \
ss->in_use = false; \
}
@@ -287,7 +287,7 @@
cmd->sync_sem = ss; \
unlock(); \
if (sync) sync->post(); \
- ss->sem->wait(); \
+ ss->sem.wait(); \
ss->in_use = false; \
}
@@ -297,7 +297,7 @@ class CommandQueueMT {
struct SyncSemaphore {
- SemaphoreOld *sem;
+ Semaphore sem;
bool in_use;
};
@@ -313,7 +313,7 @@ class CommandQueueMT {
SyncSemaphore *sync_sem;
virtual void post() {
- sync_sem->sem->post();
+ sync_sem->sem.post();
}
};
@@ -342,7 +342,7 @@ class CommandQueueMT {
uint32_t dealloc_ptr;
SyncSemaphore sync_sems[SYNC_SEMAPHORES];
Mutex mutex;
- SemaphoreOld *sync;
+ Semaphore *sync;
template <class T>
T *allocate() {
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index 7f1eb6fd90..370dd8f982 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));
@@ -141,7 +139,7 @@ void FileAccessNetworkClient::_thread_func() {
fa->_respond(len, Error(status));
}
- fa->sem->post();
+ fa->sem.post();
} break;
case FileAccessNetwork::RESPONSE_DATA: {
@@ -161,14 +159,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;
}
@@ -230,7 +228,6 @@ FileAccessNetworkClient::FileAccessNetworkClient() {
singleton = this;
last_id = 0;
client.instance();
- sem = SemaphoreOld::create();
lockcount = 0;
}
@@ -238,12 +235,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<uint8_t> &p_block) {
@@ -264,7 +259,7 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block)
if (waiting_on_page == page) {
waiting_on_page = -1;
- page_sem->post();
+ page_sem.post();
}
}
@@ -306,9 +301,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...");
@@ -393,7 +388,7 @@ void FileAccessNetwork::_queue_page(int p_page) const {
pages.write[p_page].queued = true;
}
DEBUG_PRINT("QUEUE PAGE POST");
- nc->sem->post();
+ nc->sem.post();
DEBUG_PRINT("queued " + itos(p_page));
}
}
@@ -426,7 +421,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 {
@@ -475,8 +470,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;
}
@@ -492,8 +487,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;
}
@@ -521,8 +516,6 @@ FileAccessNetwork::FileAccessNetwork() {
eof_flag = false;
opened = false;
pos = 0;
- sem = SemaphoreOld::create();
- page_sem = SemaphoreOld::create();
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();
id = nc->last_id++;
@@ -538,8 +531,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 38d9b8e8a6..7f664b46f7 100644
--- a/core/io/file_access_network.h
+++ b/core/io/file_access_network.h
@@ -49,7 +49,7 @@ class FileAccessNetworkClient {
List<BlockRequest> block_requests;
- SemaphoreOld *sem;
+ Semaphore sem;
Thread *thread;
bool quit;
Mutex mutex;
@@ -85,8 +85,8 @@ public:
class FileAccessNetwork : public FileAccess {
- SemaphoreOld *sem;
- SemaphoreOld *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 af534e4bb7..2143b84d15 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -71,7 +71,7 @@ struct _IP_ResolverPrivate {
}
Mutex mutex;
- SemaphoreOld *sem;
+ Semaphore sem;
Thread *thread;
//Semaphore* semaphore;
@@ -98,7 +98,7 @@ struct _IP_ResolverPrivate {
while (!ipr->thread_abort) {
- ipr->sem->wait();
+ ipr->sem.wait();
MutexLock lock(ipr->mutex);
ipr->resolve_queues();
@@ -148,7 +148,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();
}
@@ -300,23 +300,13 @@ IP::IP() {
singleton = this;
resolver = memnew(_IP_ResolverPrivate);
- resolver->sem = NULL;
#ifndef NO_THREADS
- resolver->sem = SemaphoreOld::create();
- if (resolver->sem) {
- resolver->thread_abort = false;
+ 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 = Thread::create(_IP_ResolverPrivate::_thread_function, resolver);
#else
- resolver->sem = NULL;
resolver->thread = NULL;
#endif
}
@@ -326,10 +316,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/mutex.h b/core/os/mutex.h
index 6cf8ee7c40..8d7b378d60 100644
--- a/core/os/mutex.h
+++ b/core/os/mutex.h
@@ -34,7 +34,7 @@
#include "core/error_list.h"
#include "core/typedefs.h"
-#if !(defined NO_THREADS)
+#if !defined(NO_THREADS)
#include <mutex>
diff --git a/core/os/semaphore.cpp b/core/os/semaphore.cpp
index 2c20f234d0..93f1e2dff4 100644
--- a/core/os/semaphore.cpp
+++ b/core/os/semaphore.cpp
@@ -29,17 +29,3 @@
/*************************************************************************/
#include "semaphore.h"
-
-#include "core/error_macros.h"
-
-SemaphoreOld *(*SemaphoreOld::create_func)() = 0;
-
-SemaphoreOld *SemaphoreOld::create() {
-
- ERR_FAIL_COND_V(!create_func, 0);
-
- return create_func();
-}
-
-SemaphoreOld::~SemaphoreOld() {
-}
diff --git a/core/os/semaphore.h b/core/os/semaphore.h
index f16a15a6db..6f194d4887 100644
--- a/core/os/semaphore.h
+++ b/core/os/semaphore.h
@@ -34,30 +34,32 @@
#include "core/error_list.h"
#include "core/typedefs.h"
+#if !defined(NO_THREADS)
+
#include <condition_variable>
#include <mutex>
class Semaphore {
private:
- std::mutex mutex_;
- std::condition_variable condition_;
- unsigned long count_ = 0; // Initialized as locked.
+ mutable std::mutex mutex_;
+ mutable std::condition_variable condition_;
+ mutable unsigned long count_ = 0; // Initialized as locked.
public:
- _ALWAYS_INLINE_ void post() {
+ _ALWAYS_INLINE_ void post() const {
std::lock_guard<decltype(mutex_)> lock(mutex_);
++count_;
condition_.notify_one();
}
- _ALWAYS_INLINE_ void wait() {
+ _ALWAYS_INLINE_ void wait() const {
std::unique_lock<decltype(mutex_)> lock(mutex_);
while (!count_) // Handle spurious wake-ups.
condition_.wait(lock);
--count_;
}
- _ALWAYS_INLINE_ bool try_wait() {
+ _ALWAYS_INLINE_ bool try_wait() const {
std::lock_guard<decltype(mutex_)> lock(mutex_);
if (count_) {
--count_;
@@ -67,18 +69,15 @@ public:
}
};
-class SemaphoreOld {
-protected:
- static SemaphoreOld *(*create_func)();
+#else
+class Semaphore {
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
-
- static SemaphoreOld *create(); ///< Create a mutex
-
- virtual ~SemaphoreOld();
+ _ALWAYS_INLINE_ void post() const {}
+ _ALWAYS_INLINE_ void wait() const {}
+ _ALWAYS_INLINE_ bool try_wait() const { return true; }
};
#endif
+
+#endif
diff --git a/core/os/thread_dummy.cpp b/core/os/thread_dummy.cpp
index 097c90c1fb..9dcddcae11 100644
--- a/core/os/thread_dummy.cpp
+++ b/core/os/thread_dummy.cpp
@@ -40,14 +40,6 @@ void ThreadDummy::make_default() {
Thread::create_func = &ThreadDummy::create;
};
-SemaphoreOld *SemaphoreDummy::create() {
- return memnew(SemaphoreDummy);
-};
-
-void SemaphoreDummy::make_default() {
- SemaphoreOld::create_func = &SemaphoreDummy::create;
-};
-
RWLock *RWLockDummy::create() {
return memnew(RWLockDummy);
};
diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h
index c0976ec299..da8188f983 100644
--- a/core/os/thread_dummy.h
+++ b/core/os/thread_dummy.h
@@ -45,18 +45,6 @@ public:
static void make_default();
};
-class SemaphoreDummy : public SemaphoreOld {
-
- static SemaphoreOld *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();
-};
-
class RWLockDummy : public RWLock {
static RWLock *create();
diff --git a/doc/classes/Semaphore.xml b/doc/classes/Semaphore.xml
index eca98fb10e..19719eea93 100644
--- a/doc/classes/Semaphore.xml
+++ b/doc/classes/Semaphore.xml
@@ -11,17 +11,24 @@
</tutorials>
<methods>
<method name="post">
- <return type="int" enum="Error">
+ <return type="void">
</return>
<description>
- Lowers the [Semaphore], allowing one more thread in. Returns [constant OK] on success, [constant ERR_BUSY] otherwise.
+ Lowers the [Semaphore], allowing one more thread in.
</description>
</method>
<method name="wait">
+ <return type="void">
+ </return>
+ <description>
+ Waits for the [Semaphore], if its value is zero, blocks until non-zero.
+ </description>
+ </method>
+ <method name="try_wait">
<return type="int" enum="Error">
</return>
<description>
- Tries to wait for the [Semaphore], if its value is zero, blocks until non-zero. Returns [constant OK] on success, [constant ERR_BUSY] otherwise.
+ Like [method wait], but won't block, so if the value is zero, fails immediately and returns [constant ERR_BUSY]. If non-zero, it returns [constant OK] to report success.
</description>
</method>
</methods>
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 27203b3eed..d21b095037 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -38,7 +38,6 @@
#include "drivers/unix/file_access_unix.h"
#include "drivers/unix/net_socket_posix.h"
#include "drivers/unix/rw_lock_posix.h"
-#include "drivers/unix/semaphore_posix.h"
#include "drivers/unix/thread_posix.h"
#include "servers/visual_server.h"
@@ -121,13 +120,9 @@ void OS_Unix::initialize_core() {
#ifdef NO_THREADS
ThreadDummy::make_default();
- SemaphoreDummy::make_default();
RWLockDummy::make_default();
#else
ThreadPosix::make_default();
-#if !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED)
- SemaphorePosix::make_default();
-#endif
RWLockPosix::make_default();
#endif
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
diff --git a/drivers/unix/semaphore_posix.cpp b/drivers/unix/semaphore_posix.cpp
deleted file mode 100644
index b532b09cd6..0000000000
--- 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-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 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 <errno.h>
-#include <stdio.h>
-
-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;
-}
-
-SemaphoreOld *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 2bffe6933d..0000000000
--- 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-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 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 <semaphore.h>
-
-class SemaphorePosix : public SemaphoreOld {
-
- mutable sem_t sem;
-
- static SemaphoreOld *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 1b53e311ff..0000000000
--- 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-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 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);
-}
-
-SemaphoreOld *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 159e8b3b96..0000000000
--- 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-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 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 <windows.h>
-
-class SemaphoreWindows : public SemaphoreOld {
-
- mutable HANDLE semaphore;
-
- static SemaphoreOld *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 40482dc367..3c401a6fc7 100644
--- a/editor/editor_resource_preview.cpp
+++ b/editor/editor_resource_preview.cpp
@@ -217,7 +217,7 @@ void EditorResourcePreview::_thread() {
exited = false;
while (!exit) {
- preview_sem->wait();
+ preview_sem.wait();
preview_mutex.lock();
if (queue.size()) {
@@ -379,7 +379,7 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p
queue.push_back(item);
}
- 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_sem->post();
+ preview_sem.post();
}
void EditorResourcePreview::add_preview_generator(const Ref<EditorResourcePreviewGenerator> &p_generator) {
@@ -462,7 +462,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
@@ -476,7 +476,6 @@ void EditorResourcePreview::stop() {
EditorResourcePreview::EditorResourcePreview() {
thread = NULL;
singleton = this;
- preview_sem = SemaphoreOld::create();
order = 0;
exit = false;
exited = false;
@@ -485,5 +484,4 @@ EditorResourcePreview::EditorResourcePreview() {
EditorResourcePreview::~EditorResourcePreview() {
stop();
- memdelete(preview_sem);
}
diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h
index ae347c0469..0e1684963c 100644
--- a/editor/editor_resource_preview.h
+++ b/editor/editor_resource_preview.h
@@ -71,7 +71,7 @@ class EditorResourcePreview : public Node {
List<QueueItem> queue;
Mutex preview_mutex;
- SemaphoreOld *preview_sem;
+ Semaphore preview_sem;
Thread *thread;
volatile bool exit;
volatile bool exited;
diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp
index 8a50f5a28b..497f2f747d 100644
--- a/platform/iphone/os_iphone.cpp
+++ b/platform/iphone/os_iphone.cpp
@@ -100,7 +100,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 0461f58c40..0000000000
--- 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-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 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 <fcntl.h>
-#include <unistd.h>
-
-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 <errno.h>
-
-Error SemaphoreIphone::wait() {
-
- cgsem_wait(&sem);
- return OK;
-}
-
-Error SemaphoreIphone::post() {
-
- cgsem_post(&sem);
-
- return OK;
-}
-int SemaphoreIphone::get() const {
-
- return 0;
-}
-
-SemaphoreOld *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 54ff3c17f9..0000000000
--- 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-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 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 SemaphoreOld {
-
- mutable cgsem_t sem;
-
- static SemaphoreOld *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 d764ac4b50..0a4e0a45e1 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',
'vulkan_context_osx.mm',
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 952360c6aa..4c70beee00 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -44,7 +44,6 @@
#endif
#include "main/main.h"
-#include "semaphore_osx.h"
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
@@ -1464,8 +1463,6 @@ void OS_OSX::initialize_core() {
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_RESOURCES);
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_USERDATA);
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_FILESYSTEM);
-
- SemaphoreOSX::make_default();
}
static bool keyboard_layout_dirty = true;
diff --git a/platform/osx/semaphore_osx.cpp b/platform/osx/semaphore_osx.cpp
deleted file mode 100644
index e4e5991637..0000000000
--- 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-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 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 <fcntl.h>
-#include <unistd.h>
-
-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 <errno.h>
-
-Error SemaphoreOSX::wait() {
-
- cgsem_wait(&sem);
- return OK;
-}
-
-Error SemaphoreOSX::post() {
-
- cgsem_post(&sem);
-
- return OK;
-}
-int SemaphoreOSX::get() const {
-
- return 0;
-}
-
-SemaphoreOld *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 9aa2b47bc8..0000000000
--- 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-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 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 SemaphoreOld {
-
- mutable cgsem_t sem;
-
- static SemaphoreOld *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 e8538f03a6..8364164114 100644
--- a/platform/server/SCsub
+++ b/platform/server/SCsub
@@ -10,7 +10,6 @@ common_server = [\
if sys.platform == "darwin":
common_server.append("#platform/osx/crash_handler_osx.mm")
- common_server.append("#platform/osx/semaphore_osx.cpp")
else:
common_server.append("#platform/x11/crash_handler_x11.cpp")
diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp
index 8a66332ff1..3257ec261c 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/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp
index 97c8dafe65..4ddb5463d0 100644
--- a/platform/uwp/os_uwp.cpp
+++ b/platform/uwp/os_uwp.cpp
@@ -140,7 +140,6 @@ void OS_UWP::initialize_core() {
//RedirectIOToConsole();
ThreadUWP::make_default();
- SemaphoreWindows::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 6757f60a06..63f0cd53a4 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -48,7 +48,6 @@
#include "drivers/windows/dir_access_windows.h"
#include "drivers/windows/file_access_windows.h"
#include "drivers/windows/rw_lock_windows.h"
-#include "drivers/windows/semaphore_windows.h"
#include "drivers/windows/thread_windows.h"
#include "joypad_windows.h"
#include "lang_table.h"
@@ -228,7 +227,6 @@ void OS_Windows::initialize_core() {
borderless = false;
ThreadWindows::make_default();
- SemaphoreWindows::make_default();
RWLockWindows::make_default();
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.cpp b/servers/physics_2d/physics_2d_server_wrap_mt.cpp
index 7070902f77..76036930c6 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,11 +84,11 @@ void Physics2DServerWrapMT::step(real_t p_step) {
void Physics2DServerWrapMT::sync() {
- if (step_sem) {
+ if (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,11 +107,8 @@ void Physics2DServerWrapMT::init() {
if (create_thread) {
- step_sem = SemaphoreOld::create();
//OS::get_singleton()->release_rendering_thread();
- if (create_thread) {
- thread = Thread::create(_thread_callback, this);
- }
+ thread = Thread::create(_thread_callback, this);
while (!step_thread_up) {
OS::get_singleton()->delay_usec(1000);
}
@@ -146,9 +143,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 +151,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 0648b8651f..4d5e317c8c 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;
- SemaphoreOld *step_sem;
+ Semaphore step_sem;
int step_pending;
void thread_step(real_t p_delta);
void thread_flush();