From 5ea5ae85d27bad5571da1d82de3e4c1901bde562 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sun, 6 Aug 2023 01:35:24 -0500 Subject: [PATCH] LibAudio: Remove the strong reference to the PulseAudio control thread Now that `Thread` keeps itself alive when it is running detached, we do not need to hold onto it in the PulseAudio playback stream's internal state object. This was a hack that did not work correctly because the `Thread` object and its action `Function` would be deleted before the action had exited and cause a crash. --- .../Libraries/LibAudio/PlaybackStreamPulseAudio.cpp | 11 ----------- .../Libraries/LibAudio/PlaybackStreamPulseAudio.h | 4 ---- 2 files changed, 15 deletions(-) diff --git a/Userland/Libraries/LibAudio/PlaybackStreamPulseAudio.cpp b/Userland/Libraries/LibAudio/PlaybackStreamPulseAudio.cpp index 17e2d1eaa6d..89ae851338d 100644 --- a/Userland/Libraries/LibAudio/PlaybackStreamPulseAudio.cpp +++ b/Userland/Libraries/LibAudio/PlaybackStreamPulseAudio.cpp @@ -45,7 +45,6 @@ ErrorOr> PlaybackStreamPulseAudio::create(OutputSt }, "Audio::PlaybackStream"sv)); - internal_state->set_thread(thread); thread->start(); thread->detach(); return playback_stream; @@ -136,12 +135,6 @@ ErrorOr PlaybackStreamPulseAudio::InternalState::check_is_running() return {}; } -void PlaybackStreamPulseAudio::InternalState::set_thread(NonnullRefPtr const& thread) -{ - Threading::MutexLocker locker { m_mutex }; - m_thread = thread; -} - void PlaybackStreamPulseAudio::InternalState::set_stream(NonnullRefPtr const& stream) { m_stream = stream; @@ -177,10 +170,6 @@ void PlaybackStreamPulseAudio::InternalState::thread_loop() } task(); } - - // Stop holding onto our thread so it can be deleted. - Threading::MutexLocker locker { m_mutex }; - m_thread = nullptr; } void PlaybackStreamPulseAudio::InternalState::exit() diff --git a/Userland/Libraries/LibAudio/PlaybackStreamPulseAudio.h b/Userland/Libraries/LibAudio/PlaybackStreamPulseAudio.h index 001149987f1..d1671944557 100644 --- a/Userland/Libraries/LibAudio/PlaybackStreamPulseAudio.h +++ b/Userland/Libraries/LibAudio/PlaybackStreamPulseAudio.h @@ -31,8 +31,6 @@ private: // the UI thread. class InternalState : public AtomicRefCounted { public: - void set_thread(NonnullRefPtr const&); - void set_stream(NonnullRefPtr const&); RefPtr stream(); @@ -49,8 +47,6 @@ private: Threading::ConditionVariable m_wake_condition { m_mutex }; Atomic m_exit { false }; - - RefPtr m_thread { nullptr }; }; PlaybackStreamPulseAudio(NonnullRefPtr);