Drop old semaphore implementation

- Removed platform-specific implementations.
- Now all semaphores are in-object, unless they need to be conditionally created.
- Similarly to `Mutex`, provided a dummy implementation for when `NO_THREADS` is defined.
- Similarly to `Mutex`, methods are made `const` for easy use in such contexts.
- Language bindings updated: `wait()` and `post()` are now `void`.
- Language bindings updated: `try_wait()` added.

Bonus:
- Rewritten the `#ifdef` in `mutex.h` to meet the code style.
This commit is contained in:
Pedro J. Estébanez
2020-03-03 09:26:42 +01:00
parent c9768f15f7
commit 9a3a2b03b8
33 changed files with 79 additions and 803 deletions

View File

@ -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