Merge pull request #36752 from RandomShaper/rework_semaphore
Drop old semaphore implementation
This commit is contained in:
commit
42595085a5
33 changed files with 79 additions and 803 deletions
|
@ -2576,32 +2576,28 @@ 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::post() {
|
||||
|
||||
semaphore.post();
|
||||
}
|
||||
|
||||
void _Semaphore::_bind_methods() {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
_Semaphore::_Semaphore() {
|
||||
|
||||
semaphore = SemaphoreOld::create();
|
||||
}
|
||||
|
||||
_Semaphore::~_Semaphore() {
|
||||
|
||||
memdelete(semaphore);
|
||||
}
|
||||
|
||||
///////////////
|
||||
|
||||
void _Mutex::lock() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "core/error_list.h"
|
||||
#include "core/typedefs.h"
|
||||
|
||||
#if !(defined NO_THREADS)
|
||||
#if !defined(NO_THREADS)
|
||||
|
||||
#include <mutex>
|
||||
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue