Modernize Mutex

- Based on C++11's `mutex`
- No more need to allocate-deallocate or check for null
- No pointer anymore, just a member variable
- Platform-specific implementations no longer needed
- Simpler for `NO_THREADS`
- `BinaryMutex` added for special cases as the non-recursive version
- `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`.
- `ScopedMutexLock` is dropped and replaced by `MutexLock`, because they were pretty much the same.
This commit is contained in:
Pedro J. Estébanez 2021-01-27 10:43:02 +01:00
parent b450036120
commit 4ddcdc031b
99 changed files with 472 additions and 1391 deletions

View file

@ -267,20 +267,15 @@ int AudioDriverJavaScript::WorkletNode::create(int p_buffer_size, int p_channels
void AudioDriverJavaScript::WorkletNode::start(float *p_out_buf, int p_out_buf_size, float *p_in_buf, int p_in_buf_size) {
godot_audio_worklet_start(p_in_buf, p_in_buf_size, p_out_buf, p_out_buf_size, state);
mutex = Mutex::create();
thread = Thread::create(_audio_thread_func, this);
}
void AudioDriverJavaScript::WorkletNode::lock() {
if (mutex) {
mutex->lock();
}
mutex.lock();
}
void AudioDriverJavaScript::WorkletNode::unlock() {
if (mutex) {
mutex->unlock();
}
mutex.unlock();
}
void AudioDriverJavaScript::WorkletNode::finish() {
@ -288,7 +283,5 @@ void AudioDriverJavaScript::WorkletNode::finish() {
Thread::wait_to_finish(thread);
memdelete(thread);
thread = nullptr;
memdelete(mutex);
mutex = nullptr;
}
#endif