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`.
This commit is contained in:
parent
1e57b558f2
commit
18fbdbb456
98 changed files with 739 additions and 1754 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue