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:
@ -1137,27 +1137,28 @@ 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[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();
|
||||
{
|
||||
MutexLock lock(audio_data_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);
|
||||
}
|
||||
|
||||
return ad;
|
||||
}
|
||||
|
||||
void AudioServer::audio_data_free(void *p_data) {
|
||||
|
||||
audio_data_lock->lock();
|
||||
MutexLock lock(audio_data_lock);
|
||||
|
||||
if (!audio_data.has(p_data)) {
|
||||
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();
|
||||
}
|
||||
|
||||
size_t AudioServer::audio_data_get_total_memory_usage() const {
|
||||
@ -1399,7 +1400,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;
|
||||
@ -1413,7 +1413,6 @@ AudioServer::AudioServer() {
|
||||
|
||||
AudioServer::~AudioServer() {
|
||||
|
||||
memdelete(audio_data_lock);
|
||||
singleton = NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user