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

@ -1148,27 +1148,27 @@ void *AudioServer::audio_data_alloc(uint32_t p_data_len, const uint8_t *p_from_d
copymem(ad, p_from_data, p_data_len);
}
audio_data_lock->lock();
audio_data_lock.lock();
audio_data[ad] = p_data_len;
audio_data_total_mem += p_data_len;
audio_data_max_mem = MAX(audio_data_total_mem, audio_data_max_mem);
audio_data_lock->unlock();
audio_data_lock.unlock();
return ad;
}
void AudioServer::audio_data_free(void *p_data) {
audio_data_lock->lock();
audio_data_lock.lock();
if (!audio_data.has(p_data)) {
audio_data_lock->unlock();
audio_data_lock.unlock();
ERR_FAIL();
}
audio_data_total_mem -= audio_data[p_data];
audio_data.erase(p_data);
memfree(p_data);
audio_data_lock->unlock();
audio_data_lock.unlock();
}
size_t AudioServer::audio_data_get_total_memory_usage() const {
@ -1410,7 +1410,6 @@ AudioServer::AudioServer() {
singleton = this;
audio_data_total_mem = 0;
audio_data_max_mem = 0;
audio_data_lock = Mutex::create();
mix_frames = 0;
channel_count = 0;
to_mix = 0;
@ -1424,7 +1423,6 @@ AudioServer::AudioServer() {
AudioServer::~AudioServer() {
memdelete(audio_data_lock);
singleton = NULL;
}