diff options
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/file_access_network.cpp | 11 | ||||
-rw-r--r-- | core/io/file_access_network.h | 2 | ||||
-rw-r--r-- | core/io/ip.cpp | 24 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 5 |
4 files changed, 14 insertions, 28 deletions
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 1d9aa846eb..97838fd14c 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -201,7 +201,7 @@ Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const S return ERR_INVALID_PARAMETER; } - thread = Thread::create(_thread_func, this); + thread.start(_thread_func, this); return OK; } @@ -214,12 +214,9 @@ FileAccessNetworkClient::FileAccessNetworkClient() { } FileAccessNetworkClient::~FileAccessNetworkClient() { - if (thread) { - quit = true; - sem.post(); - Thread::wait_to_finish(thread); - memdelete(thread); - } + quit = true; + sem.post(); + thread.wait_to_finish(); } void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) { diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h index 6aec2869fc..1f5de3e5dd 100644 --- a/core/io/file_access_network.h +++ b/core/io/file_access_network.h @@ -48,7 +48,7 @@ class FileAccessNetworkClient { List<BlockRequest> block_requests; Semaphore sem; - Thread *thread = nullptr; + Thread thread; bool quit = false; Mutex mutex; Mutex blockrequest_mutex; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 6fb812e78d..df95785000 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -71,7 +71,7 @@ struct _IP_ResolverPrivate { Mutex mutex; Semaphore sem; - Thread *thread; + Thread thread; //Semaphore* semaphore; bool thread_abort; @@ -141,7 +141,7 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ } else { resolver->queue[id].response = IP_Address(); resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING; - if (resolver->thread) { + if (resolver->thread.is_started()) { resolver->sem.post(); } else { resolver->resolve_queues(); @@ -285,26 +285,14 @@ IP::IP() { singleton = this; resolver = memnew(_IP_ResolverPrivate); -#ifndef NO_THREADS - resolver->thread_abort = false; - - resolver->thread = Thread::create(_IP_ResolverPrivate::_thread_function, resolver); -#else - resolver->thread = nullptr; -#endif + resolver->thread.start(_IP_ResolverPrivate::_thread_function, resolver); } IP::~IP() { -#ifndef NO_THREADS - if (resolver->thread) { - resolver->thread_abort = true; - resolver->sem.post(); - Thread::wait_to_finish(resolver->thread); - memdelete(resolver->thread); - } - -#endif + resolver->thread_abort = true; + resolver->sem.post(); + resolver->thread.wait_to_finish(); memdelete(resolver); } diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 1a2b1ed033..d66511a39f 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -362,7 +362,8 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String & print_lt("REQUEST: load count: " + itos(thread_loading_count) + " / wait count: " + itos(thread_waiting_count) + " / suspended count: " + itos(thread_suspended_count) + " / active: " + itos(thread_loading_count - thread_suspended_count)); - load_task.thread = Thread::create(_thread_load_function, &thread_load_tasks[local_path]); + load_task.thread = memnew(Thread); + load_task.thread->start(_thread_load_function, &thread_load_tasks[local_path]); load_task.loader_id = load_task.thread->get_id(); } @@ -489,7 +490,7 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { if (load_task.requests == 0) { if (load_task.thread) { //thread may not have been used - Thread::wait_to_finish(load_task.thread); + load_task.thread->wait_to_finish(); memdelete(load_task.thread); } thread_load_tasks.erase(local_path); |