From 99fe462452be44efa618e83ad9bbecd722ae6ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Tue, 19 Jan 2021 13:29:41 +0100 Subject: Modernize Thread - Based on C++11's `thread` and `thread_local` - No more need to allocate-deallocate or check for null - No pointer anymore, just a member variable - Platform-specific implementations no longer needed (except for the few cases of non-portable functions) - Simpler for `NO_THREADS` - Thread ids are now the same across platforms (main is 1; others follow) --- drivers/pulseaudio/audio_driver_pulseaudio.cpp | 16 +++------------- drivers/pulseaudio/audio_driver_pulseaudio.h | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) (limited to 'drivers/pulseaudio') diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index 440b7d7f53..a5092c8c5c 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -287,7 +287,7 @@ Error AudioDriverPulseAudio::init() { Error err = init_device(); if (err == OK) { - thread = Thread::create(AudioDriverPulseAudio::thread_func, this); + thread.start(AudioDriverPulseAudio::thread_func, this); } return OK; @@ -581,16 +581,10 @@ void AudioDriverPulseAudio::set_device(String device) { } void AudioDriverPulseAudio::lock() { - if (!thread) { - return; - } mutex.lock(); } void AudioDriverPulseAudio::unlock() { - if (!thread) { - return; - } mutex.unlock(); } @@ -603,12 +597,12 @@ void AudioDriverPulseAudio::finish_device() { } void AudioDriverPulseAudio::finish() { - if (!thread) { + if (!thread.is_started()) { return; } exit_thread = true; - Thread::wait_to_finish(thread); + thread.wait_to_finish(); finish_device(); @@ -622,10 +616,6 @@ void AudioDriverPulseAudio::finish() { pa_mainloop_free(pa_ml); pa_ml = nullptr; } - - memdelete(thread); - - thread = nullptr; } Error AudioDriverPulseAudio::capture_init_device() { diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.h b/drivers/pulseaudio/audio_driver_pulseaudio.h index 71ab2ef1c8..2ddf8d2592 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.h +++ b/drivers/pulseaudio/audio_driver_pulseaudio.h @@ -40,7 +40,7 @@ #include class AudioDriverPulseAudio : public AudioDriver { - Thread *thread = nullptr; + Thread thread; Mutex mutex; pa_mainloop *pa_ml = nullptr; -- cgit v1.2.3