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:
@ -79,7 +79,6 @@ Error AudioDriverXAudio2::init() {
|
||||
hr = xaudio->CreateSourceVoice(&source_voice, &wave_format, 0, XAUDIO2_MAX_FREQ_RATIO, &voice_callback);
|
||||
ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_UNAVAILABLE, "Error creating XAudio2 source voice. Error code: " + itos(hr) + ".");
|
||||
|
||||
mutex = Mutex::create();
|
||||
thread = Thread::create(AudioDriverXAudio2::thread_func, this);
|
||||
|
||||
return OK;
|
||||
@ -158,15 +157,15 @@ float AudioDriverXAudio2::get_latency() {
|
||||
|
||||
void AudioDriverXAudio2::lock() {
|
||||
|
||||
if (!thread || !mutex)
|
||||
if (!thread)
|
||||
return;
|
||||
mutex->lock();
|
||||
mutex.lock();
|
||||
}
|
||||
void AudioDriverXAudio2::unlock() {
|
||||
|
||||
if (!thread || !mutex)
|
||||
if (!thread)
|
||||
return;
|
||||
mutex->unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void AudioDriverXAudio2::finish() {
|
||||
@ -194,14 +193,11 @@ void AudioDriverXAudio2::finish() {
|
||||
mastering_voice->DestroyVoice();
|
||||
|
||||
memdelete(thread);
|
||||
if (mutex)
|
||||
memdelete(mutex);
|
||||
thread = NULL;
|
||||
}
|
||||
|
||||
AudioDriverXAudio2::AudioDriverXAudio2() :
|
||||
thread(NULL),
|
||||
mutex(NULL),
|
||||
current_buffer(0) {
|
||||
wave_format = { 0 };
|
||||
for (int i = 0; i < AUDIO_BUFFERS; i++) {
|
||||
|
||||
@ -65,7 +65,7 @@ class AudioDriverXAudio2 : public AudioDriver {
|
||||
};
|
||||
|
||||
Thread *thread;
|
||||
Mutex *mutex;
|
||||
Mutex mutex;
|
||||
|
||||
int32_t *samples_in;
|
||||
int16_t *samples_out[AUDIO_BUFFERS];
|
||||
|
||||
Reference in New Issue
Block a user