summaryrefslogtreecommitdiff
path: root/editor/fileserver
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2020-02-26 11:28:13 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2020-02-26 20:40:10 +0100
commit18fbdbb456c07a56b358bea2e392765fbcbb3283 (patch)
tree737363d20493afe45e75d932e0c1957dd9a79589 /editor/fileserver
parent1e57b558f215dd4920768e9567b6f55825877c89 (diff)
Reimplement Mutex with C++'s <mutex>
Main: - It's now implemented thanks to `<mutex>`. No more platform-specific implementations. - `BinaryMutex` (non-recursive) is added, as an alternative for special cases. - Doesn't need allocation/deallocation anymore. It can live in the stack and be part of other classes. - Because of that, it's methods are now `const` and the inner mutex is `mutable` so it can be easily used in `const` contexts. - A no-op implementation is provided if `NO_THREADS` is defined. No more need to add `#ifdef NO_THREADS` just for this. - `MutexLock` now takes a reference. At this point the cases of null `Mutex`es are rare. If you ever need that, just don't use `MutexLock`. - Thread-safe utilities are therefore simpler now. Misc.: - `ScopedMutexLock` is dropped and replaced by `MutexLock`, because they were pretty much the same. - Every case of lock, do-something, unlock is replaced by `MutexLock` (complex cases where it's not straightfoward are kept as as explicit lock and unlock). - `ShaderRD` contained an `std::mutex`, which has been replaced by `Mutex`.
Diffstat (limited to 'editor/fileserver')
-rw-r--r--editor/fileserver/editor_file_server.cpp17
-rw-r--r--editor/fileserver/editor_file_server.h2
2 files changed, 9 insertions, 10 deletions
diff --git a/editor/fileserver/editor_file_server.cpp b/editor/fileserver/editor_file_server.cpp
index af7eb0c4c7..fb44c145b2 100644
--- a/editor/fileserver/editor_file_server.cpp
+++ b/editor/fileserver/editor_file_server.cpp
@@ -42,9 +42,10 @@
void EditorFileServer::_close_client(ClientData *cd) {
cd->connection->disconnect_from_host();
- cd->efs->wait_mutex->lock();
- cd->efs->to_wait.insert(cd->thread);
- cd->efs->wait_mutex->unlock();
+ {
+ MutexLock lock(cd->efs->wait_mutex);
+ cd->efs->to_wait.insert(cd->thread);
+ }
while (cd->files.size()) {
memdelete(cd->files.front()->get());
cd->files.erase(cd->files.front());
@@ -295,16 +296,16 @@ void EditorFileServer::_thread_start(void *s) {
}
}
- self->wait_mutex->lock();
+ self->wait_mutex.lock();
while (self->to_wait.size()) {
Thread *w = self->to_wait.front()->get();
self->to_wait.erase(w);
- self->wait_mutex->unlock();
+ self->wait_mutex.unlock();
Thread::wait_to_finish(w);
memdelete(w);
- self->wait_mutex->lock();
+ self->wait_mutex.lock();
}
- self->wait_mutex->unlock();
+ self->wait_mutex.unlock();
OS::get_singleton()->delay_usec(100000);
}
@@ -331,7 +332,6 @@ void EditorFileServer::stop() {
EditorFileServer::EditorFileServer() {
server.instance();
- wait_mutex = Mutex::create();
quit = false;
active = false;
cmd = CMD_NONE;
@@ -346,5 +346,4 @@ EditorFileServer::~EditorFileServer() {
quit = true;
Thread::wait_to_finish(thread);
memdelete(thread);
- memdelete(wait_mutex);
}
diff --git a/editor/fileserver/editor_file_server.h b/editor/fileserver/editor_file_server.h
index 4ce4c0cda6..cc3cb44566 100644
--- a/editor/fileserver/editor_file_server.h
+++ b/editor/fileserver/editor_file_server.h
@@ -62,7 +62,7 @@ class EditorFileServer : public Object {
static void _close_client(ClientData *cd);
static void _subthread_start(void *s);
- Mutex *wait_mutex;
+ Mutex wait_mutex;
Thread *thread;
static void _thread_start(void *);
bool quit;