diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2020-03-03 09:26:42 +0100 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2020-03-03 13:20:42 +0100 |
commit | 9a3a2b03b8b718409eb26252d742d48091756ef7 (patch) | |
tree | 94cc5ae822288ec8b1e098773338498f865b5b77 /core/io/ip.cpp | |
parent | c9768f15f7bb194622b9020ab2614d47ac7e63dd (diff) | |
download | redot-engine-9a3a2b03b8b718409eb26252d742d48091756ef7.tar.gz |
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.
Diffstat (limited to 'core/io/ip.cpp')
-rw-r--r-- | core/io/ip.cpp | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/core/io/ip.cpp b/core/io/ip.cpp index af534e4bb7..2143b84d15 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -71,7 +71,7 @@ struct _IP_ResolverPrivate { } Mutex mutex; - SemaphoreOld *sem; + Semaphore sem; Thread *thread; //Semaphore* semaphore; @@ -98,7 +98,7 @@ struct _IP_ResolverPrivate { while (!ipr->thread_abort) { - ipr->sem->wait(); + ipr->sem.wait(); MutexLock lock(ipr->mutex); ipr->resolve_queues(); @@ -148,7 +148,7 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ resolver->queue[id].response = IP_Address(); resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING; if (resolver->thread) - resolver->sem->post(); + resolver->sem.post(); else resolver->resolve_queues(); } @@ -300,23 +300,13 @@ IP::IP() { singleton = this; resolver = memnew(_IP_ResolverPrivate); - resolver->sem = NULL; #ifndef NO_THREADS - resolver->sem = SemaphoreOld::create(); - if (resolver->sem) { - resolver->thread_abort = false; + resolver->thread_abort = false; - resolver->thread = Thread::create(_IP_ResolverPrivate::_thread_function, resolver); - - if (!resolver->thread) - memdelete(resolver->sem); //wtf - } else { - resolver->thread = NULL; - } + resolver->thread = Thread::create(_IP_ResolverPrivate::_thread_function, resolver); #else - resolver->sem = NULL; resolver->thread = NULL; #endif } @@ -326,10 +316,9 @@ IP::~IP() { #ifndef NO_THREADS if (resolver->thread) { resolver->thread_abort = true; - resolver->sem->post(); + resolver->sem.post(); Thread::wait_to_finish(resolver->thread); memdelete(resolver->thread); - memdelete(resolver->sem); } #endif |