Modernize Semaphore
- Based on C++11's `mutex` and `condition_variable` - No more need to allocate-deallocate or check for null - No pointer anymore, just a member variable - Platform-specific implementations no longer needed - Simpler for `NO_THREADS`
This commit is contained in:
parent
4ddcdc031b
commit
8f6a636ae7
|
@ -2689,12 +2689,14 @@ void _Marshalls::_bind_methods() {
|
||||||
|
|
||||||
Error _Semaphore::wait() {
|
Error _Semaphore::wait() {
|
||||||
|
|
||||||
return semaphore->wait();
|
semaphore.wait();
|
||||||
|
return OK; // Can't fail anymore; keep compat
|
||||||
}
|
}
|
||||||
|
|
||||||
Error _Semaphore::post() {
|
Error _Semaphore::post() {
|
||||||
|
|
||||||
return semaphore->post();
|
semaphore.post();
|
||||||
|
return OK; // Can't fail anymore; keep compat
|
||||||
}
|
}
|
||||||
|
|
||||||
void _Semaphore::_bind_methods() {
|
void _Semaphore::_bind_methods() {
|
||||||
|
@ -2703,16 +2705,6 @@ void _Semaphore::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post);
|
ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post);
|
||||||
}
|
}
|
||||||
|
|
||||||
_Semaphore::_Semaphore() {
|
|
||||||
|
|
||||||
semaphore = Semaphore::create();
|
|
||||||
}
|
|
||||||
|
|
||||||
_Semaphore::~_Semaphore() {
|
|
||||||
|
|
||||||
memdelete(semaphore);
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
|
|
||||||
void _Mutex::lock() {
|
void _Mutex::lock() {
|
||||||
|
|
|
@ -665,16 +665,13 @@ public:
|
||||||
class _Semaphore : public Reference {
|
class _Semaphore : public Reference {
|
||||||
|
|
||||||
GDCLASS(_Semaphore, Reference);
|
GDCLASS(_Semaphore, Reference);
|
||||||
Semaphore *semaphore;
|
Semaphore semaphore;
|
||||||
|
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Error wait();
|
Error wait();
|
||||||
Error post();
|
Error post();
|
||||||
|
|
||||||
_Semaphore();
|
|
||||||
~_Semaphore();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class _Thread : public Reference {
|
class _Thread : public Reference {
|
||||||
|
|
|
@ -113,11 +113,10 @@ CommandQueueMT::CommandQueueMT(bool p_sync) {
|
||||||
|
|
||||||
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
|
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
|
||||||
|
|
||||||
sync_sems[i].sem = Semaphore::create();
|
|
||||||
sync_sems[i].in_use = false;
|
sync_sems[i].in_use = false;
|
||||||
}
|
}
|
||||||
if (p_sync) {
|
if (p_sync) {
|
||||||
sync = Semaphore::create();
|
sync = memnew(Semaphore);
|
||||||
} else {
|
} else {
|
||||||
sync = NULL;
|
sync = NULL;
|
||||||
}
|
}
|
||||||
|
@ -127,9 +126,5 @@ CommandQueueMT::~CommandQueueMT() {
|
||||||
|
|
||||||
if (sync)
|
if (sync)
|
||||||
memdelete(sync);
|
memdelete(sync);
|
||||||
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
|
|
||||||
|
|
||||||
memdelete(sync_sems[i].sem);
|
|
||||||
}
|
|
||||||
memfree(command_mem);
|
memfree(command_mem);
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,7 +250,7 @@
|
||||||
cmd->sync_sem = ss; \
|
cmd->sync_sem = ss; \
|
||||||
unlock(); \
|
unlock(); \
|
||||||
if (sync) sync->post(); \
|
if (sync) sync->post(); \
|
||||||
ss->sem->wait(); \
|
ss->sem.wait(); \
|
||||||
ss->in_use = false; \
|
ss->in_use = false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@
|
||||||
cmd->sync_sem = ss; \
|
cmd->sync_sem = ss; \
|
||||||
unlock(); \
|
unlock(); \
|
||||||
if (sync) sync->post(); \
|
if (sync) sync->post(); \
|
||||||
ss->sem->wait(); \
|
ss->sem.wait(); \
|
||||||
ss->in_use = false; \
|
ss->in_use = false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ class CommandQueueMT {
|
||||||
|
|
||||||
struct SyncSemaphore {
|
struct SyncSemaphore {
|
||||||
|
|
||||||
Semaphore *sem;
|
Semaphore sem;
|
||||||
bool in_use;
|
bool in_use;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ class CommandQueueMT {
|
||||||
SyncSemaphore *sync_sem;
|
SyncSemaphore *sync_sem;
|
||||||
|
|
||||||
virtual void post() {
|
virtual void post() {
|
||||||
sync_sem->sem->post();
|
sync_sem->sem.post();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -88,9 +88,7 @@ void FileAccessNetworkClient::_thread_func() {
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
|
|
||||||
DEBUG_PRINT("SEM WAIT - " + itos(sem->get()));
|
DEBUG_PRINT("SEM WAIT - " + itos(sem->get()));
|
||||||
Error err = sem->wait();
|
sem.wait();
|
||||||
if (err != OK)
|
|
||||||
ERR_PRINT("sem->wait() failed");
|
|
||||||
DEBUG_TIME("sem_unlock");
|
DEBUG_TIME("sem_unlock");
|
||||||
//DEBUG_PRINT("semwait returned "+itos(werr));
|
//DEBUG_PRINT("semwait returned "+itos(werr));
|
||||||
DEBUG_PRINT("MUTEX LOCK " + itos(lockcount));
|
DEBUG_PRINT("MUTEX LOCK " + itos(lockcount));
|
||||||
|
@ -140,7 +138,7 @@ void FileAccessNetworkClient::_thread_func() {
|
||||||
fa->_respond(len, Error(status));
|
fa->_respond(len, Error(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
fa->sem->post();
|
fa->sem.post();
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case FileAccessNetwork::RESPONSE_DATA: {
|
case FileAccessNetwork::RESPONSE_DATA: {
|
||||||
|
@ -160,14 +158,14 @@ void FileAccessNetworkClient::_thread_func() {
|
||||||
|
|
||||||
int status = get_32();
|
int status = get_32();
|
||||||
fa->exists_modtime = status != 0;
|
fa->exists_modtime = status != 0;
|
||||||
fa->sem->post();
|
fa->sem.post();
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case FileAccessNetwork::RESPONSE_GET_MODTIME: {
|
case FileAccessNetwork::RESPONSE_GET_MODTIME: {
|
||||||
|
|
||||||
uint64_t status = get_64();
|
uint64_t status = get_64();
|
||||||
fa->exists_modtime = status;
|
fa->exists_modtime = status;
|
||||||
fa->sem->post();
|
fa->sem.post();
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +227,6 @@ FileAccessNetworkClient::FileAccessNetworkClient() {
|
||||||
singleton = this;
|
singleton = this;
|
||||||
last_id = 0;
|
last_id = 0;
|
||||||
client.instance();
|
client.instance();
|
||||||
sem = Semaphore::create();
|
|
||||||
lockcount = 0;
|
lockcount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,12 +234,10 @@ FileAccessNetworkClient::~FileAccessNetworkClient() {
|
||||||
|
|
||||||
if (thread) {
|
if (thread) {
|
||||||
quit = true;
|
quit = true;
|
||||||
sem->post();
|
sem.post();
|
||||||
Thread::wait_to_finish(thread);
|
Thread::wait_to_finish(thread);
|
||||||
memdelete(thread);
|
memdelete(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
memdelete(sem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) {
|
void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) {
|
||||||
|
@ -262,7 +257,7 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block)
|
||||||
|
|
||||||
if (waiting_on_page == page) {
|
if (waiting_on_page == page) {
|
||||||
waiting_on_page = -1;
|
waiting_on_page = -1;
|
||||||
page_sem->post();
|
page_sem.post();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,9 +299,9 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
|
||||||
nc->unlock_mutex();
|
nc->unlock_mutex();
|
||||||
DEBUG_PRINT("OPEN POST");
|
DEBUG_PRINT("OPEN POST");
|
||||||
DEBUG_TIME("open_post");
|
DEBUG_TIME("open_post");
|
||||||
nc->sem->post(); //awaiting answer
|
nc->sem.post(); //awaiting answer
|
||||||
DEBUG_PRINT("WAIT...");
|
DEBUG_PRINT("WAIT...");
|
||||||
sem->wait();
|
sem.wait();
|
||||||
DEBUG_TIME("open_end");
|
DEBUG_TIME("open_end");
|
||||||
DEBUG_PRINT("WAIT ENDED...");
|
DEBUG_PRINT("WAIT ENDED...");
|
||||||
|
|
||||||
|
@ -390,7 +385,7 @@ void FileAccessNetwork::_queue_page(int p_page) const {
|
||||||
pages.write[p_page].queued = true;
|
pages.write[p_page].queued = true;
|
||||||
nc->blockrequest_mutex.unlock();
|
nc->blockrequest_mutex.unlock();
|
||||||
DEBUG_PRINT("QUEUE PAGE POST");
|
DEBUG_PRINT("QUEUE PAGE POST");
|
||||||
nc->sem->post();
|
nc->sem.post();
|
||||||
DEBUG_PRINT("queued " + itos(p_page));
|
DEBUG_PRINT("queued " + itos(p_page));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,7 +418,7 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
}
|
}
|
||||||
buffer_mutex.unlock();
|
buffer_mutex.unlock();
|
||||||
DEBUG_PRINT("wait");
|
DEBUG_PRINT("wait");
|
||||||
page_sem->wait();
|
page_sem.wait();
|
||||||
DEBUG_PRINT("done");
|
DEBUG_PRINT("done");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -472,8 +467,8 @@ bool FileAccessNetwork::file_exists(const String &p_path) {
|
||||||
nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
|
nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
|
||||||
nc->unlock_mutex();
|
nc->unlock_mutex();
|
||||||
DEBUG_PRINT("FILE EXISTS POST");
|
DEBUG_PRINT("FILE EXISTS POST");
|
||||||
nc->sem->post();
|
nc->sem.post();
|
||||||
sem->wait();
|
sem.wait();
|
||||||
|
|
||||||
return exists_modtime != 0;
|
return exists_modtime != 0;
|
||||||
}
|
}
|
||||||
|
@ -489,8 +484,8 @@ uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) {
|
||||||
nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
|
nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
|
||||||
nc->unlock_mutex();
|
nc->unlock_mutex();
|
||||||
DEBUG_PRINT("MODTIME POST");
|
DEBUG_PRINT("MODTIME POST");
|
||||||
nc->sem->post();
|
nc->sem.post();
|
||||||
sem->wait();
|
sem.wait();
|
||||||
|
|
||||||
return exists_modtime;
|
return exists_modtime;
|
||||||
}
|
}
|
||||||
|
@ -518,8 +513,6 @@ FileAccessNetwork::FileAccessNetwork() {
|
||||||
eof_flag = false;
|
eof_flag = false;
|
||||||
opened = false;
|
opened = false;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
sem = Semaphore::create();
|
|
||||||
page_sem = Semaphore::create();
|
|
||||||
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
|
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
|
||||||
nc->lock_mutex();
|
nc->lock_mutex();
|
||||||
id = nc->last_id++;
|
id = nc->last_id++;
|
||||||
|
@ -535,8 +528,6 @@ FileAccessNetwork::FileAccessNetwork() {
|
||||||
FileAccessNetwork::~FileAccessNetwork() {
|
FileAccessNetwork::~FileAccessNetwork() {
|
||||||
|
|
||||||
close();
|
close();
|
||||||
memdelete(sem);
|
|
||||||
memdelete(page_sem);
|
|
||||||
|
|
||||||
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
|
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
|
||||||
nc->lock_mutex();
|
nc->lock_mutex();
|
||||||
|
|
|
@ -49,7 +49,7 @@ class FileAccessNetworkClient {
|
||||||
|
|
||||||
List<BlockRequest> block_requests;
|
List<BlockRequest> block_requests;
|
||||||
|
|
||||||
Semaphore *sem;
|
Semaphore sem;
|
||||||
Thread *thread;
|
Thread *thread;
|
||||||
bool quit;
|
bool quit;
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
|
@ -85,8 +85,8 @@ public:
|
||||||
|
|
||||||
class FileAccessNetwork : public FileAccess {
|
class FileAccessNetwork : public FileAccess {
|
||||||
|
|
||||||
Semaphore *sem;
|
Semaphore sem;
|
||||||
Semaphore *page_sem;
|
Semaphore page_sem;
|
||||||
Mutex buffer_mutex;
|
Mutex buffer_mutex;
|
||||||
bool opened;
|
bool opened;
|
||||||
size_t total_size;
|
size_t total_size;
|
||||||
|
|
|
@ -71,7 +71,7 @@ struct _IP_ResolverPrivate {
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
Semaphore *sem;
|
Semaphore sem;
|
||||||
|
|
||||||
Thread *thread;
|
Thread *thread;
|
||||||
//Semaphore* semaphore;
|
//Semaphore* semaphore;
|
||||||
|
@ -98,7 +98,7 @@ struct _IP_ResolverPrivate {
|
||||||
|
|
||||||
while (!ipr->thread_abort) {
|
while (!ipr->thread_abort) {
|
||||||
|
|
||||||
ipr->sem->wait();
|
ipr->sem.wait();
|
||||||
|
|
||||||
ipr->mutex.lock();
|
ipr->mutex.lock();
|
||||||
ipr->resolve_queues();
|
ipr->resolve_queues();
|
||||||
|
@ -152,7 +152,7 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ
|
||||||
resolver->queue[id].response = IP_Address();
|
resolver->queue[id].response = IP_Address();
|
||||||
resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING;
|
resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING;
|
||||||
if (resolver->thread)
|
if (resolver->thread)
|
||||||
resolver->sem->post();
|
resolver->sem.post();
|
||||||
else
|
else
|
||||||
resolver->resolve_queues();
|
resolver->resolve_queues();
|
||||||
}
|
}
|
||||||
|
@ -314,23 +314,11 @@ IP::IP() {
|
||||||
|
|
||||||
singleton = this;
|
singleton = this;
|
||||||
resolver = memnew(_IP_ResolverPrivate);
|
resolver = memnew(_IP_ResolverPrivate);
|
||||||
resolver->sem = NULL;
|
|
||||||
|
|
||||||
#ifndef NO_THREADS
|
#ifndef NO_THREADS
|
||||||
|
resolver->thread_abort = false;
|
||||||
resolver->sem = Semaphore::create();
|
resolver->thread = Thread::create(_IP_ResolverPrivate::_thread_function, resolver);
|
||||||
if (resolver->sem) {
|
|
||||||
resolver->thread_abort = false;
|
|
||||||
|
|
||||||
resolver->thread = Thread::create(_IP_ResolverPrivate::_thread_function, resolver);
|
|
||||||
|
|
||||||
if (!resolver->thread)
|
|
||||||
memdelete(resolver->sem); //wtf
|
|
||||||
} else {
|
|
||||||
resolver->thread = NULL;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
resolver->sem = NULL;
|
|
||||||
resolver->thread = NULL;
|
resolver->thread = NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -340,10 +328,9 @@ IP::~IP() {
|
||||||
#ifndef NO_THREADS
|
#ifndef NO_THREADS
|
||||||
if (resolver->thread) {
|
if (resolver->thread) {
|
||||||
resolver->thread_abort = true;
|
resolver->thread_abort = true;
|
||||||
resolver->sem->post();
|
resolver->sem.post();
|
||||||
Thread::wait_to_finish(resolver->thread);
|
Thread::wait_to_finish(resolver->thread);
|
||||||
memdelete(resolver->thread);
|
memdelete(resolver->thread);
|
||||||
memdelete(resolver->sem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
/*************************************************************************/
|
|
||||||
/* semaphore.cpp */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* This file is part of: */
|
|
||||||
/* GODOT ENGINE */
|
|
||||||
/* https://godotengine.org */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
|
|
||||||
#include "semaphore.h"
|
|
||||||
|
|
||||||
#include "core/error_macros.h"
|
|
||||||
|
|
||||||
Semaphore *(*Semaphore::create_func)() = 0;
|
|
||||||
|
|
||||||
Semaphore *Semaphore::create() {
|
|
||||||
|
|
||||||
ERR_FAIL_COND_V(!create_func, 0);
|
|
||||||
|
|
||||||
return create_func();
|
|
||||||
}
|
|
||||||
|
|
||||||
Semaphore::~Semaphore() {
|
|
||||||
}
|
|
|
@ -32,19 +32,59 @@
|
||||||
#define SEMAPHORE_H
|
#define SEMAPHORE_H
|
||||||
|
|
||||||
#include "core/error_list.h"
|
#include "core/error_list.h"
|
||||||
|
#include "core/typedefs.h"
|
||||||
|
|
||||||
|
#if !defined(NO_THREADS)
|
||||||
|
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
class Semaphore {
|
class Semaphore {
|
||||||
protected:
|
private:
|
||||||
static Semaphore *(*create_func)();
|
mutable std::mutex mutex_;
|
||||||
|
mutable std::condition_variable condition_;
|
||||||
|
mutable unsigned long count_ = 0; // Initialized as locked.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual Error wait() = 0; ///< wait until semaphore has positive value, then decrement and pass
|
_ALWAYS_INLINE_ void post() const {
|
||||||
virtual Error post() = 0; ///< unlock the semaphore, incrementing the value
|
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||||
virtual int get() const = 0; ///< get semaphore value
|
++count_;
|
||||||
|
condition_.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
static Semaphore *create(); ///< Create a mutex
|
_ALWAYS_INLINE_ void wait() const {
|
||||||
|
std::unique_lock<decltype(mutex_)> lock(mutex_);
|
||||||
|
while (!count_) { // Handle spurious wake-ups.
|
||||||
|
condition_.wait(lock);
|
||||||
|
}
|
||||||
|
--count_;
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~Semaphore();
|
_ALWAYS_INLINE_ bool try_wait() const {
|
||||||
|
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||||
|
if (count_) {
|
||||||
|
--count_;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ALWAYS_INLINE_ int get() const {
|
||||||
|
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||||
|
return count_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
class Semaphore {
|
||||||
|
public:
|
||||||
|
_ALWAYS_INLINE_ void post() const {}
|
||||||
|
_ALWAYS_INLINE_ void wait() const {}
|
||||||
|
_ALWAYS_INLINE_ bool try_wait() const { return true; }
|
||||||
|
_ALWAYS_INLINE_ int get() const { return 1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif // SEMAPHORE_H
|
||||||
|
|
|
@ -39,11 +39,3 @@ Thread *ThreadDummy::create(ThreadCreateCallback p_callback, void *p_user, const
|
||||||
void ThreadDummy::make_default() {
|
void ThreadDummy::make_default() {
|
||||||
Thread::create_func = &ThreadDummy::create;
|
Thread::create_func = &ThreadDummy::create;
|
||||||
};
|
};
|
||||||
|
|
||||||
Semaphore *SemaphoreDummy::create() {
|
|
||||||
return memnew(SemaphoreDummy);
|
|
||||||
};
|
|
||||||
|
|
||||||
void SemaphoreDummy::make_default() {
|
|
||||||
Semaphore::create_func = &SemaphoreDummy::create;
|
|
||||||
};
|
|
||||||
|
|
|
@ -45,16 +45,4 @@ public:
|
||||||
static void make_default();
|
static void make_default();
|
||||||
};
|
};
|
||||||
|
|
||||||
class SemaphoreDummy : public Semaphore {
|
|
||||||
|
|
||||||
static Semaphore *create();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual Error wait() { return OK; };
|
|
||||||
virtual Error post() { return OK; };
|
|
||||||
virtual int get() const { return 0; }; ///< get semaphore value
|
|
||||||
|
|
||||||
static void make_default();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
#include "drivers/unix/dir_access_unix.h"
|
#include "drivers/unix/dir_access_unix.h"
|
||||||
#include "drivers/unix/file_access_unix.h"
|
#include "drivers/unix/file_access_unix.h"
|
||||||
#include "drivers/unix/net_socket_posix.h"
|
#include "drivers/unix/net_socket_posix.h"
|
||||||
#include "drivers/unix/semaphore_posix.h"
|
|
||||||
#include "drivers/unix/thread_posix.h"
|
#include "drivers/unix/thread_posix.h"
|
||||||
#include "servers/visual_server.h"
|
#include "servers/visual_server.h"
|
||||||
|
|
||||||
|
@ -121,12 +120,8 @@ void OS_Unix::initialize_core() {
|
||||||
|
|
||||||
#ifdef NO_THREADS
|
#ifdef NO_THREADS
|
||||||
ThreadDummy::make_default();
|
ThreadDummy::make_default();
|
||||||
SemaphoreDummy::make_default();
|
|
||||||
#else
|
#else
|
||||||
ThreadPosix::make_default();
|
ThreadPosix::make_default();
|
||||||
#if !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED)
|
|
||||||
SemaphorePosix::make_default();
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
|
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
|
||||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
|
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
/*************************************************************************/
|
|
||||||
/* semaphore_posix.cpp */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* This file is part of: */
|
|
||||||
/* GODOT ENGINE */
|
|
||||||
/* https://godotengine.org */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
|
|
||||||
#include "semaphore_posix.h"
|
|
||||||
|
|
||||||
#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED)
|
|
||||||
|
|
||||||
#include "core/os/memory.h"
|
|
||||||
#include <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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Semaphore *SemaphorePosix::create_semaphore_posix() {
|
|
||||||
|
|
||||||
return memnew(SemaphorePosix);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SemaphorePosix::make_default() {
|
|
||||||
|
|
||||||
create_func = create_semaphore_posix;
|
|
||||||
}
|
|
||||||
|
|
||||||
SemaphorePosix::SemaphorePosix() {
|
|
||||||
|
|
||||||
int r = sem_init(&sem, 0, 0);
|
|
||||||
if (r != 0)
|
|
||||||
perror("sem creating");
|
|
||||||
}
|
|
||||||
|
|
||||||
SemaphorePosix::~SemaphorePosix() {
|
|
||||||
|
|
||||||
sem_destroy(&sem);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,58 +0,0 @@
|
||||||
/*************************************************************************/
|
|
||||||
/* semaphore_posix.h */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* This file is part of: */
|
|
||||||
/* GODOT ENGINE */
|
|
||||||
/* https://godotengine.org */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
|
|
||||||
#ifndef SEMAPHORE_POSIX_H
|
|
||||||
#define SEMAPHORE_POSIX_H
|
|
||||||
|
|
||||||
#include "core/os/semaphore.h"
|
|
||||||
|
|
||||||
#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED)
|
|
||||||
|
|
||||||
#include <semaphore.h>
|
|
||||||
|
|
||||||
class SemaphorePosix : public Semaphore {
|
|
||||||
|
|
||||||
mutable sem_t sem;
|
|
||||||
|
|
||||||
static Semaphore *create_semaphore_posix();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual Error wait();
|
|
||||||
virtual Error post();
|
|
||||||
virtual int get() const;
|
|
||||||
|
|
||||||
static void make_default();
|
|
||||||
SemaphorePosix();
|
|
||||||
|
|
||||||
~SemaphorePosix();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
|
@ -1,98 +0,0 @@
|
||||||
/*************************************************************************/
|
|
||||||
/* semaphore_windows.cpp */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* This file is part of: */
|
|
||||||
/* GODOT ENGINE */
|
|
||||||
/* https://godotengine.org */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
|
|
||||||
#include "semaphore_windows.h"
|
|
||||||
|
|
||||||
#if defined(WINDOWS_ENABLED)
|
|
||||||
|
|
||||||
#include "core/os/memory.h"
|
|
||||||
|
|
||||||
Error SemaphoreWindows::wait() {
|
|
||||||
|
|
||||||
WaitForSingleObjectEx(semaphore, INFINITE, false);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
Error SemaphoreWindows::post() {
|
|
||||||
|
|
||||||
ReleaseSemaphore(semaphore, 1, NULL);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
int SemaphoreWindows::get() const {
|
|
||||||
long previous;
|
|
||||||
switch (WaitForSingleObjectEx(semaphore, 0, false)) {
|
|
||||||
case WAIT_OBJECT_0: {
|
|
||||||
ERR_FAIL_COND_V(!ReleaseSemaphore(semaphore, 1, &previous), -1);
|
|
||||||
return previous + 1;
|
|
||||||
} break;
|
|
||||||
case WAIT_TIMEOUT: {
|
|
||||||
return 0;
|
|
||||||
} break;
|
|
||||||
default: {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ERR_FAIL_V(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Semaphore *SemaphoreWindows::create_semaphore_windows() {
|
|
||||||
|
|
||||||
return memnew(SemaphoreWindows);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SemaphoreWindows::make_default() {
|
|
||||||
|
|
||||||
create_func = create_semaphore_windows;
|
|
||||||
}
|
|
||||||
|
|
||||||
SemaphoreWindows::SemaphoreWindows() {
|
|
||||||
|
|
||||||
#ifdef UWP_ENABLED
|
|
||||||
semaphore = CreateSemaphoreEx(
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
0xFFFFFFF, //wathever
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
SEMAPHORE_ALL_ACCESS);
|
|
||||||
#else
|
|
||||||
semaphore = CreateSemaphore(
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
0xFFFFFFF, //wathever
|
|
||||||
NULL);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
SemaphoreWindows::~SemaphoreWindows() {
|
|
||||||
|
|
||||||
CloseHandle(semaphore);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,58 +0,0 @@
|
||||||
/*************************************************************************/
|
|
||||||
/* semaphore_windows.h */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* This file is part of: */
|
|
||||||
/* GODOT ENGINE */
|
|
||||||
/* https://godotengine.org */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
|
|
||||||
#ifndef SEMAPHORE_WINDOWS_H
|
|
||||||
#define SEMAPHORE_WINDOWS_H
|
|
||||||
|
|
||||||
#include "core/os/semaphore.h"
|
|
||||||
|
|
||||||
#ifdef WINDOWS_ENABLED
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
class SemaphoreWindows : public Semaphore {
|
|
||||||
|
|
||||||
mutable HANDLE semaphore;
|
|
||||||
|
|
||||||
static Semaphore *create_semaphore_windows();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual Error wait();
|
|
||||||
virtual Error post();
|
|
||||||
virtual int get() const;
|
|
||||||
|
|
||||||
static void make_default();
|
|
||||||
SemaphoreWindows();
|
|
||||||
|
|
||||||
~SemaphoreWindows();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
|
@ -220,7 +220,7 @@ void EditorResourcePreview::_thread() {
|
||||||
exited = false;
|
exited = false;
|
||||||
while (!exit) {
|
while (!exit) {
|
||||||
|
|
||||||
preview_sem->wait();
|
preview_sem.wait();
|
||||||
preview_mutex.lock();
|
preview_mutex.lock();
|
||||||
|
|
||||||
if (queue.size()) {
|
if (queue.size()) {
|
||||||
|
@ -381,7 +381,7 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p
|
||||||
|
|
||||||
queue.push_back(item);
|
queue.push_back(item);
|
||||||
preview_mutex.unlock();
|
preview_mutex.unlock();
|
||||||
preview_sem->post();
|
preview_sem.post();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorResourcePreview::queue_resource_preview(const String &p_path, Object *p_receiver, const StringName &p_receiver_func, const Variant &p_userdata) {
|
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);
|
queue.push_back(item);
|
||||||
preview_mutex.unlock();
|
preview_mutex.unlock();
|
||||||
preview_sem->post();
|
preview_sem.post();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorResourcePreview::add_preview_generator(const Ref<EditorResourcePreviewGenerator> &p_generator) {
|
void EditorResourcePreview::add_preview_generator(const Ref<EditorResourcePreviewGenerator> &p_generator) {
|
||||||
|
@ -463,7 +463,7 @@ void EditorResourcePreview::start() {
|
||||||
void EditorResourcePreview::stop() {
|
void EditorResourcePreview::stop() {
|
||||||
if (thread) {
|
if (thread) {
|
||||||
exit = true;
|
exit = true;
|
||||||
preview_sem->post();
|
preview_sem.post();
|
||||||
while (!exited) {
|
while (!exited) {
|
||||||
OS::get_singleton()->delay_usec(10000);
|
OS::get_singleton()->delay_usec(10000);
|
||||||
VisualServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on visual server
|
VisualServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on visual server
|
||||||
|
@ -477,7 +477,6 @@ void EditorResourcePreview::stop() {
|
||||||
EditorResourcePreview::EditorResourcePreview() {
|
EditorResourcePreview::EditorResourcePreview() {
|
||||||
thread = NULL;
|
thread = NULL;
|
||||||
singleton = this;
|
singleton = this;
|
||||||
preview_sem = Semaphore::create();
|
|
||||||
order = 0;
|
order = 0;
|
||||||
exit = false;
|
exit = false;
|
||||||
exited = false;
|
exited = false;
|
||||||
|
@ -486,5 +485,4 @@ EditorResourcePreview::EditorResourcePreview() {
|
||||||
EditorResourcePreview::~EditorResourcePreview() {
|
EditorResourcePreview::~EditorResourcePreview() {
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
memdelete(preview_sem);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ class EditorResourcePreview : public Node {
|
||||||
List<QueueItem> queue;
|
List<QueueItem> queue;
|
||||||
|
|
||||||
Mutex preview_mutex;
|
Mutex preview_mutex;
|
||||||
Semaphore *preview_sem;
|
Semaphore preview_sem;
|
||||||
Thread *thread;
|
Thread *thread;
|
||||||
volatile bool exit;
|
volatile bool exit;
|
||||||
volatile bool exited;
|
volatile bool exited;
|
||||||
|
|
|
@ -44,7 +44,7 @@ int VideoStreamPlaybackTheora::buffer_data() {
|
||||||
int read;
|
int read;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
thread_sem->post();
|
thread_sem.post();
|
||||||
read = MIN(ring_buffer.data_left(), 4096);
|
read = MIN(ring_buffer.data_left(), 4096);
|
||||||
if (read) {
|
if (read) {
|
||||||
ring_buffer.read((uint8_t *)buffer, read);
|
ring_buffer.read((uint8_t *)buffer, read);
|
||||||
|
@ -141,7 +141,7 @@ void VideoStreamPlaybackTheora::clear() {
|
||||||
|
|
||||||
#ifdef THEORA_USE_THREAD_STREAMING
|
#ifdef THEORA_USE_THREAD_STREAMING
|
||||||
thread_exit = true;
|
thread_exit = true;
|
||||||
thread_sem->post(); //just in case
|
thread_sem.post(); //just in case
|
||||||
Thread::wait_to_finish(thread);
|
Thread::wait_to_finish(thread);
|
||||||
memdelete(thread);
|
memdelete(thread);
|
||||||
thread = NULL;
|
thread = NULL;
|
||||||
|
@ -385,7 +385,7 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef THEORA_USE_THREAD_STREAMING
|
#ifdef THEORA_USE_THREAD_STREAMING
|
||||||
thread_sem->post();
|
thread_sem.post();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
time += p_delta;
|
time += p_delta;
|
||||||
|
@ -664,7 +664,7 @@ void VideoStreamPlaybackTheora::_streaming_thread(void *ud) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vs->thread_sem->wait();
|
vs->thread_sem.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,7 +693,6 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() {
|
||||||
int rb_power = nearest_shift(RB_SIZE_KB * 1024);
|
int rb_power = nearest_shift(RB_SIZE_KB * 1024);
|
||||||
ring_buffer.resize(rb_power);
|
ring_buffer.resize(rb_power);
|
||||||
read_buffer.resize(RB_SIZE_KB * 1024);
|
read_buffer.resize(RB_SIZE_KB * 1024);
|
||||||
thread_sem = Semaphore::create();
|
|
||||||
thread = NULL;
|
thread = NULL;
|
||||||
thread_exit = false;
|
thread_exit = false;
|
||||||
thread_eof = false;
|
thread_eof = false;
|
||||||
|
@ -703,10 +702,6 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() {
|
||||||
|
|
||||||
VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() {
|
VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() {
|
||||||
|
|
||||||
#ifdef THEORA_USE_THREAD_STREAMING
|
|
||||||
|
|
||||||
memdelete(thread_sem);
|
|
||||||
#endif
|
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
if (file)
|
if (file)
|
||||||
|
|
|
@ -112,7 +112,7 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback {
|
||||||
RingBuffer<uint8_t> ring_buffer;
|
RingBuffer<uint8_t> ring_buffer;
|
||||||
Vector<uint8_t> read_buffer;
|
Vector<uint8_t> read_buffer;
|
||||||
bool thread_eof;
|
bool thread_eof;
|
||||||
Semaphore *thread_sem;
|
Semaphore thread_sem;
|
||||||
Thread *thread;
|
Thread *thread;
|
||||||
volatile bool thread_exit;
|
volatile bool thread_exit;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
Import("env")
|
Import("env")
|
||||||
|
|
||||||
iphone_lib = [
|
iphone_lib = [
|
||||||
"semaphore_iphone.cpp",
|
|
||||||
"godot_iphone.mm",
|
"godot_iphone.mm",
|
||||||
"os_iphone.mm",
|
"os_iphone.mm",
|
||||||
"main.m",
|
"main.m",
|
||||||
|
|
|
@ -45,8 +45,6 @@
|
||||||
#include "core/project_settings.h"
|
#include "core/project_settings.h"
|
||||||
#include "drivers/unix/syslog_logger.h"
|
#include "drivers/unix/syslog_logger.h"
|
||||||
|
|
||||||
#include "semaphore_iphone.h"
|
|
||||||
|
|
||||||
#import "app_delegate.h"
|
#import "app_delegate.h"
|
||||||
#import "device_metrics.h"
|
#import "device_metrics.h"
|
||||||
#import "godot_view.h"
|
#import "godot_view.h"
|
||||||
|
@ -104,7 +102,6 @@ String OSIPhone::get_unique_id() const {
|
||||||
void OSIPhone::initialize_core() {
|
void OSIPhone::initialize_core() {
|
||||||
|
|
||||||
OS_Unix::initialize_core();
|
OS_Unix::initialize_core();
|
||||||
SemaphoreIphone::make_default();
|
|
||||||
|
|
||||||
set_data_dir(data_dir);
|
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-2021 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
|
|
||||||
#include "semaphore_iphone.h"
|
|
||||||
|
|
||||||
#include <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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Semaphore *SemaphoreIphone::create_semaphore_iphone() {
|
|
||||||
|
|
||||||
return memnew(SemaphoreIphone);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SemaphoreIphone::make_default() {
|
|
||||||
|
|
||||||
create_func = create_semaphore_iphone;
|
|
||||||
}
|
|
||||||
|
|
||||||
SemaphoreIphone::SemaphoreIphone() {
|
|
||||||
|
|
||||||
cgsem_init(&sem);
|
|
||||||
}
|
|
||||||
|
|
||||||
SemaphoreIphone::~SemaphoreIphone() {
|
|
||||||
|
|
||||||
cgsem_destroy(&sem);
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*************************************************************************/
|
|
||||||
/* semaphore_iphone.h */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* This file is part of: */
|
|
||||||
/* GODOT ENGINE */
|
|
||||||
/* https://godotengine.org */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
|
|
||||||
#ifndef SEMAPHORE_IPHONE_H
|
|
||||||
#define SEMAPHORE_IPHONE_H
|
|
||||||
|
|
||||||
struct cgsem {
|
|
||||||
int pipefd[2];
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct cgsem cgsem_t;
|
|
||||||
|
|
||||||
#include "core/os/semaphore.h"
|
|
||||||
|
|
||||||
class SemaphoreIphone : public Semaphore {
|
|
||||||
|
|
||||||
mutable cgsem_t sem;
|
|
||||||
|
|
||||||
static Semaphore *create_semaphore_iphone();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual Error wait();
|
|
||||||
virtual Error post();
|
|
||||||
virtual int get() const;
|
|
||||||
|
|
||||||
static void make_default();
|
|
||||||
SemaphoreIphone();
|
|
||||||
|
|
||||||
~SemaphoreIphone();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SEMAPHORE_IPHONE_H
|
|
|
@ -9,7 +9,6 @@ files = [
|
||||||
"crash_handler_osx.mm",
|
"crash_handler_osx.mm",
|
||||||
"os_osx.mm",
|
"os_osx.mm",
|
||||||
"godot_main_osx.mm",
|
"godot_main_osx.mm",
|
||||||
"semaphore_osx.cpp",
|
|
||||||
"dir_access_osx.mm",
|
"dir_access_osx.mm",
|
||||||
"joypad_osx.cpp",
|
"joypad_osx.cpp",
|
||||||
"power_osx.cpp",
|
"power_osx.cpp",
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
#include "drivers/gles2/rasterizer_gles2.h"
|
#include "drivers/gles2/rasterizer_gles2.h"
|
||||||
#include "drivers/gles3/rasterizer_gles3.h"
|
#include "drivers/gles3/rasterizer_gles3.h"
|
||||||
#include "main/main.h"
|
#include "main/main.h"
|
||||||
#include "semaphore_osx.h"
|
|
||||||
#include "servers/visual/visual_server_raster.h"
|
#include "servers/visual/visual_server_raster.h"
|
||||||
|
|
||||||
#include <mach-o/dyld.h>
|
#include <mach-o/dyld.h>
|
||||||
|
@ -1527,8 +1526,6 @@ void OS_OSX::initialize_core() {
|
||||||
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_RESOURCES);
|
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_RESOURCES);
|
||||||
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_USERDATA);
|
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_USERDATA);
|
||||||
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_FILESYSTEM);
|
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_FILESYSTEM);
|
||||||
|
|
||||||
SemaphoreOSX::make_default();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LayoutInfo {
|
struct LayoutInfo {
|
||||||
|
|
|
@ -1,107 +0,0 @@
|
||||||
/*************************************************************************/
|
|
||||||
/* semaphore_osx.cpp */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* This file is part of: */
|
|
||||||
/* GODOT ENGINE */
|
|
||||||
/* https://godotengine.org */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
|
|
||||||
#include "semaphore_osx.h"
|
|
||||||
|
|
||||||
#include <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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Semaphore *SemaphoreOSX::create_semaphore_osx() {
|
|
||||||
|
|
||||||
return memnew(SemaphoreOSX);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SemaphoreOSX::make_default() {
|
|
||||||
|
|
||||||
create_func = create_semaphore_osx;
|
|
||||||
}
|
|
||||||
|
|
||||||
SemaphoreOSX::SemaphoreOSX() {
|
|
||||||
|
|
||||||
cgsem_init(&sem);
|
|
||||||
}
|
|
||||||
|
|
||||||
SemaphoreOSX::~SemaphoreOSX() {
|
|
||||||
|
|
||||||
cgsem_destroy(&sem);
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*************************************************************************/
|
|
||||||
/* semaphore_osx.h */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* This file is part of: */
|
|
||||||
/* GODOT ENGINE */
|
|
||||||
/* https://godotengine.org */
|
|
||||||
/*************************************************************************/
|
|
||||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
||||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
||||||
/* */
|
|
||||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
||||||
/* a copy of this software and associated documentation files (the */
|
|
||||||
/* "Software"), to deal in the Software without restriction, including */
|
|
||||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
||||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
||||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
||||||
/* the following conditions: */
|
|
||||||
/* */
|
|
||||||
/* The above copyright notice and this permission notice shall be */
|
|
||||||
/* included in all copies or substantial portions of the Software. */
|
|
||||||
/* */
|
|
||||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
||||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
||||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
||||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
||||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
||||||
/*************************************************************************/
|
|
||||||
|
|
||||||
#ifndef SEMAPHORE_OSX_H
|
|
||||||
#define SEMAPHORE_OSX_H
|
|
||||||
|
|
||||||
struct cgsem {
|
|
||||||
int pipefd[2];
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct cgsem cgsem_t;
|
|
||||||
|
|
||||||
#include "core/os/semaphore.h"
|
|
||||||
|
|
||||||
class SemaphoreOSX : public Semaphore {
|
|
||||||
|
|
||||||
mutable cgsem_t sem;
|
|
||||||
|
|
||||||
static Semaphore *create_semaphore_osx();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual Error wait();
|
|
||||||
virtual Error post();
|
|
||||||
virtual int get() const;
|
|
||||||
|
|
||||||
static void make_default();
|
|
||||||
SemaphoreOSX();
|
|
||||||
|
|
||||||
~SemaphoreOSX();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SEMAPHORE_OSX_H
|
|
|
@ -11,7 +11,6 @@ common_server = [
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
common_server.append("#platform/osx/crash_handler_osx.mm")
|
common_server.append("#platform/osx/crash_handler_osx.mm")
|
||||||
common_server.append("#platform/osx/power_osx.cpp")
|
common_server.append("#platform/osx/power_osx.cpp")
|
||||||
common_server.append("#platform/osx/semaphore_osx.cpp")
|
|
||||||
else:
|
else:
|
||||||
common_server.append("#platform/x11/crash_handler_x11.cpp")
|
common_server.append("#platform/x11/crash_handler_x11.cpp")
|
||||||
common_server.append("#platform/x11/power_x11.cpp")
|
common_server.append("#platform/x11/power_x11.cpp")
|
||||||
|
|
|
@ -68,10 +68,6 @@ void OS_Server::initialize_core() {
|
||||||
crash_handler.initialize();
|
crash_handler.initialize();
|
||||||
|
|
||||||
OS_Unix::initialize_core();
|
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) {
|
Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "platform/osx/crash_handler_osx.h"
|
#include "platform/osx/crash_handler_osx.h"
|
||||||
#include "platform/osx/power_osx.h"
|
#include "platform/osx/power_osx.h"
|
||||||
#include "platform/osx/semaphore_osx.h"
|
|
||||||
#else
|
#else
|
||||||
#include "platform/x11/crash_handler_x11.h"
|
#include "platform/x11/crash_handler_x11.h"
|
||||||
#include "platform/x11/power_x11.h"
|
#include "platform/x11/power_x11.h"
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include "drivers/unix/ip_unix.h"
|
#include "drivers/unix/ip_unix.h"
|
||||||
#include "drivers/windows/dir_access_windows.h"
|
#include "drivers/windows/dir_access_windows.h"
|
||||||
#include "drivers/windows/file_access_windows.h"
|
#include "drivers/windows/file_access_windows.h"
|
||||||
#include "drivers/windows/semaphore_windows.h"
|
|
||||||
#include "main/main.h"
|
#include "main/main.h"
|
||||||
#include "platform/windows/windows_terminal_logger.h"
|
#include "platform/windows/windows_terminal_logger.h"
|
||||||
#include "servers/audio_server.h"
|
#include "servers/audio_server.h"
|
||||||
|
@ -139,7 +138,6 @@ void OS_UWP::initialize_core() {
|
||||||
//RedirectIOToConsole();
|
//RedirectIOToConsole();
|
||||||
|
|
||||||
ThreadUWP::make_default();
|
ThreadUWP::make_default();
|
||||||
SemaphoreWindows::make_default();
|
|
||||||
|
|
||||||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
|
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
|
||||||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
|
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include "drivers/gles3/rasterizer_gles3.h"
|
#include "drivers/gles3/rasterizer_gles3.h"
|
||||||
#include "drivers/windows/dir_access_windows.h"
|
#include "drivers/windows/dir_access_windows.h"
|
||||||
#include "drivers/windows/file_access_windows.h"
|
#include "drivers/windows/file_access_windows.h"
|
||||||
#include "drivers/windows/semaphore_windows.h"
|
|
||||||
#include "drivers/windows/thread_windows.h"
|
#include "drivers/windows/thread_windows.h"
|
||||||
#include "joypad_windows.h"
|
#include "joypad_windows.h"
|
||||||
#include "lang_table.h"
|
#include "lang_table.h"
|
||||||
|
@ -226,7 +225,6 @@ void OS_Windows::initialize_core() {
|
||||||
borderless = false;
|
borderless = false;
|
||||||
|
|
||||||
ThreadWindows::make_default();
|
ThreadWindows::make_default();
|
||||||
SemaphoreWindows::make_default();
|
|
||||||
|
|
||||||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
|
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
|
||||||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
|
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
|
||||||
|
|
|
@ -40,7 +40,7 @@ void Physics2DServerWrapMT::thread_exit() {
|
||||||
void Physics2DServerWrapMT::thread_step(real_t p_delta) {
|
void Physics2DServerWrapMT::thread_step(real_t p_delta) {
|
||||||
|
|
||||||
physics_2d_server->step(p_delta);
|
physics_2d_server->step(p_delta);
|
||||||
step_sem->post();
|
step_sem.post();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics2DServerWrapMT::_thread_callback(void *_instance) {
|
void Physics2DServerWrapMT::_thread_callback(void *_instance) {
|
||||||
|
@ -84,12 +84,13 @@ void Physics2DServerWrapMT::step(real_t p_step) {
|
||||||
|
|
||||||
void Physics2DServerWrapMT::sync() {
|
void Physics2DServerWrapMT::sync() {
|
||||||
|
|
||||||
if (step_sem) {
|
if (create_thread) {
|
||||||
if (first_frame)
|
if (first_frame)
|
||||||
first_frame = false;
|
first_frame = false;
|
||||||
else
|
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();
|
physics_2d_server->sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +108,6 @@ void Physics2DServerWrapMT::init() {
|
||||||
|
|
||||||
if (create_thread) {
|
if (create_thread) {
|
||||||
|
|
||||||
step_sem = Semaphore::create();
|
|
||||||
//OS::get_singleton()->release_rendering_thread();
|
//OS::get_singleton()->release_rendering_thread();
|
||||||
if (create_thread) {
|
if (create_thread) {
|
||||||
thread = Thread::create(_thread_callback, this);
|
thread = Thread::create(_thread_callback, this);
|
||||||
|
@ -146,9 +146,6 @@ void Physics2DServerWrapMT::finish() {
|
||||||
space_free_cached_ids();
|
space_free_cached_ids();
|
||||||
area_free_cached_ids();
|
area_free_cached_ids();
|
||||||
body_free_cached_ids();
|
body_free_cached_ids();
|
||||||
|
|
||||||
if (step_sem)
|
|
||||||
memdelete(step_sem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Physics2DServerWrapMT::Physics2DServerWrapMT(Physics2DServer *p_contained, bool p_create_thread) :
|
Physics2DServerWrapMT::Physics2DServerWrapMT(Physics2DServer *p_contained, bool p_create_thread) :
|
||||||
|
@ -157,7 +154,6 @@ Physics2DServerWrapMT::Physics2DServerWrapMT(Physics2DServer *p_contained, bool
|
||||||
physics_2d_server = p_contained;
|
physics_2d_server = p_contained;
|
||||||
create_thread = p_create_thread;
|
create_thread = p_create_thread;
|
||||||
thread = NULL;
|
thread = NULL;
|
||||||
step_sem = NULL;
|
|
||||||
step_pending = 0;
|
step_pending = 0;
|
||||||
step_thread_up = false;
|
step_thread_up = false;
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Physics2DServerWrapMT : public Physics2DServer {
|
||||||
volatile bool step_thread_up;
|
volatile bool step_thread_up;
|
||||||
bool create_thread;
|
bool create_thread;
|
||||||
|
|
||||||
Semaphore *step_sem;
|
Semaphore step_sem;
|
||||||
int step_pending;
|
int step_pending;
|
||||||
void thread_step(real_t p_delta);
|
void thread_step(real_t p_delta);
|
||||||
void thread_flush();
|
void thread_flush();
|
||||||
|
|
|
@ -2711,7 +2711,7 @@ void VisualServerScene::_gi_probe_bake_thread() {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
probe_bake_sem->wait();
|
probe_bake_sem.wait();
|
||||||
if (probe_bake_thread_exit) {
|
if (probe_bake_thread_exit) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3410,7 +3410,7 @@ void VisualServerScene::render_probes() {
|
||||||
probe->dynamic.updating_stage = GI_UPDATE_STAGE_LIGHTING;
|
probe->dynamic.updating_stage = GI_UPDATE_STAGE_LIGHTING;
|
||||||
probe_bake_list.push_back(instance_probe);
|
probe_bake_list.push_back(instance_probe);
|
||||||
probe_bake_mutex.unlock();
|
probe_bake_mutex.unlock();
|
||||||
probe_bake_sem->post();
|
probe_bake_sem.post();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -3683,7 +3683,6 @@ VisualServerScene *VisualServerScene::singleton = NULL;
|
||||||
VisualServerScene::VisualServerScene() {
|
VisualServerScene::VisualServerScene() {
|
||||||
|
|
||||||
#ifndef NO_THREADS
|
#ifndef NO_THREADS
|
||||||
probe_bake_sem = Semaphore::create();
|
|
||||||
probe_bake_thread = Thread::create(_gi_probe_bake_threads, this);
|
probe_bake_thread = Thread::create(_gi_probe_bake_threads, this);
|
||||||
probe_bake_thread_exit = false;
|
probe_bake_thread_exit = false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -3697,9 +3696,8 @@ VisualServerScene::~VisualServerScene() {
|
||||||
|
|
||||||
#ifndef NO_THREADS
|
#ifndef NO_THREADS
|
||||||
probe_bake_thread_exit = true;
|
probe_bake_thread_exit = true;
|
||||||
probe_bake_sem->post();
|
probe_bake_sem.post();
|
||||||
Thread::wait_to_finish(probe_bake_thread);
|
Thread::wait_to_finish(probe_bake_thread);
|
||||||
memdelete(probe_bake_thread);
|
memdelete(probe_bake_thread);
|
||||||
memdelete(probe_bake_sem);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -593,7 +593,7 @@ public:
|
||||||
|
|
||||||
volatile bool probe_bake_thread_exit;
|
volatile bool probe_bake_thread_exit;
|
||||||
Thread *probe_bake_thread;
|
Thread *probe_bake_thread;
|
||||||
Semaphore *probe_bake_sem;
|
Semaphore probe_bake_sem;
|
||||||
Mutex probe_bake_mutex;
|
Mutex probe_bake_mutex;
|
||||||
List<Instance *> probe_bake_list;
|
List<Instance *> probe_bake_list;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue