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)
This commit is contained in:
Pedro J. Estébanez
2021-01-27 20:10:10 +01:00
parent 8f6a636ae7
commit 6d89f675b1
84 changed files with 370 additions and 1080 deletions

View File

@@ -294,7 +294,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;
@@ -599,15 +599,11 @@ void AudioDriverPulseAudio::set_device(String device) {
void AudioDriverPulseAudio::lock() {
if (!thread)
return;
mutex.lock();
}
void AudioDriverPulseAudio::unlock() {
if (!thread)
return;
mutex.unlock();
}
@@ -622,11 +618,11 @@ 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();
@@ -640,10 +636,6 @@ void AudioDriverPulseAudio::finish() {
pa_mainloop_free(pa_ml);
pa_ml = NULL;
}
memdelete(thread);
thread = NULL;
}
Error AudioDriverPulseAudio::capture_init_device() {
@@ -797,7 +789,6 @@ String AudioDriverPulseAudio::capture_get_device() {
}
AudioDriverPulseAudio::AudioDriverPulseAudio() :
thread(NULL),
pa_ml(NULL),
pa_ctx(NULL),
pa_str(NULL),

View File

@@ -41,7 +41,7 @@
class AudioDriverPulseAudio : public AudioDriver {
Thread *thread;
Thread thread;
Mutex mutex;
pa_mainloop *pa_ml;