diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2021-01-19 13:29:41 +0100 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2021-01-29 12:02:13 +0100 |
commit | 99fe462452be44efa618e83ad9bbecd722ae6ecd (patch) | |
tree | 9bd84bc560b2c8049234d92d217396d21e68ba28 /editor/fileserver | |
parent | 6ddfc8e7187bd2b25b5caa61dee8fdca05af6298 (diff) |
Modernize Thread
- Based on C++11's `thread` and `thread_local`
- No more need to allocate-deallocate or check for null
- No pointer anymore, just a member variable
- Platform-specific implementations no longer needed (except for the few cases of non-portable functions)
- Simpler for `NO_THREADS`
- Thread ids are now the same across platforms (main is 1; others follow)
Diffstat (limited to 'editor/fileserver')
-rw-r--r-- | editor/fileserver/editor_file_server.cpp | 12 | ||||
-rw-r--r-- | editor/fileserver/editor_file_server.h | 4 |
2 files changed, 7 insertions, 9 deletions
diff --git a/editor/fileserver/editor_file_server.cpp b/editor/fileserver/editor_file_server.cpp index 02bbeb57c7..07edae833d 100644 --- a/editor/fileserver/editor_file_server.cpp +++ b/editor/fileserver/editor_file_server.cpp @@ -43,7 +43,7 @@ void EditorFileServer::_close_client(ClientData *cd) { cd->connection->disconnect_from_host(); { MutexLock lock(cd->efs->wait_mutex); - cd->efs->to_wait.insert(cd->thread); + cd->efs->to_wait.insert(&cd->thread); } while (cd->files.size()) { memdelete(cd->files.front()->get()); @@ -278,7 +278,7 @@ void EditorFileServer::_thread_start(void *s) { cd->connection = self->server->take_connection(); cd->efs = self; cd->quit = false; - cd->thread = Thread::create(_subthread_start, cd); + cd->thread.start(_subthread_start, cd); } } @@ -287,8 +287,7 @@ void EditorFileServer::_thread_start(void *s) { Thread *w = self->to_wait.front()->get(); self->to_wait.erase(w); self->wait_mutex.unlock(); - Thread::wait_to_finish(w); - memdelete(w); + w->wait_to_finish(); self->wait_mutex.lock(); } self->wait_mutex.unlock(); @@ -317,7 +316,7 @@ EditorFileServer::EditorFileServer() { quit = false; active = false; cmd = CMD_NONE; - thread = Thread::create(_thread_start, this); + thread.start(_thread_start, this); EDITOR_DEF("filesystem/file_server/port", 6010); EDITOR_DEF("filesystem/file_server/password", ""); @@ -325,6 +324,5 @@ EditorFileServer::EditorFileServer() { EditorFileServer::~EditorFileServer() { quit = true; - Thread::wait_to_finish(thread); - memdelete(thread); + thread.wait_to_finish(); } diff --git a/editor/fileserver/editor_file_server.h b/editor/fileserver/editor_file_server.h index 267b129bda..e4c8327d76 100644 --- a/editor/fileserver/editor_file_server.h +++ b/editor/fileserver/editor_file_server.h @@ -47,7 +47,7 @@ class EditorFileServer : public Object { }; struct ClientData { - Thread *thread = nullptr; + Thread thread; Ref<StreamPeerTCP> connection; Map<int, FileAccess *> files; EditorFileServer *efs = nullptr; @@ -61,7 +61,7 @@ class EditorFileServer : public Object { static void _subthread_start(void *s); Mutex wait_mutex; - Thread *thread; + Thread thread; static void _thread_start(void *); bool quit; Command cmd; |