From 8e3c1dbc2c179c03ca2cf092ed6ebc73331a1503 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Wed, 24 Jul 2024 06:23:25 -0700 Subject: [PATCH] audio: Use 'join' instead of 'stop' for stream workers Calling 'stop' can cause the worker thread to terminate before it handles the 'halReservedExit' command. This should be avoided because a proper exit sequence may do cleanups. Since all stream workers must handle the 'halReservedExit' command, use of 'stop' should not be needed (if the thread code gets stuck on a call to drivers, calling 'stop' will not interrupt this), thus it is being replaced by 'join'. Bug: 344482249 Test: atest CtsMediaAudioTestCases Test: atest VtsHalAudioCoreTargetTest Change-Id: If13f7239423657b80091239ff67e7fe350957e2e --- audio/aidl/default/Stream.cpp | 2 +- audio/aidl/default/include/core-impl/Stream.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/audio/aidl/default/Stream.cpp b/audio/aidl/default/Stream.cpp index 8f5e83914c..389860fa2e 100644 --- a/audio/aidl/default/Stream.cpp +++ b/audio/aidl/default/Stream.cpp @@ -772,7 +772,7 @@ ndk::ScopedAStatus StreamCommonImpl::close() { if (!isClosed()) { stopWorker(); LOG(DEBUG) << __func__ << ": joining the worker thread..."; - mWorker->stop(); + mWorker->join(); LOG(DEBUG) << __func__ << ": worker thread joined"; onClose(mWorker->setClosed()); return ndk::ScopedAStatus::ok(); diff --git a/audio/aidl/default/include/core-impl/Stream.h b/audio/aidl/default/include/core-impl/Stream.h index 6b45866a38..93ace96b5c 100644 --- a/audio/aidl/default/include/core-impl/Stream.h +++ b/audio/aidl/default/include/core-impl/Stream.h @@ -245,7 +245,7 @@ struct StreamWorkerInterface { virtual StreamDescriptor::State setClosed() = 0; virtual bool start() = 0; virtual pid_t getTid() = 0; - virtual void stop() = 0; + virtual void join() = 0; virtual std::string getError() = 0; }; @@ -265,7 +265,7 @@ class StreamWorkerImpl : public StreamWorkerInterface, return WorkerImpl::start(WorkerImpl::kThreadName, ANDROID_PRIORITY_URGENT_AUDIO); } pid_t getTid() override { return WorkerImpl::getTid(); } - void stop() override { return WorkerImpl::stop(); } + void join() override { return WorkerImpl::join(); } std::string getError() override { return WorkerImpl::getError(); } };