diff options
author | Mikhail Naganov <mnaganov@google.com> | 2017-01-31 17:24:48 -0800 |
---|---|---|
committer | Mikhail Naganov <mnaganov@google.com> | 2017-02-02 17:00:42 -0800 |
commit | b0abafbf0a6174e8c8933cc5fb19501a2d22c53b (patch) | |
tree | d119b77826ef8b5b1190886dab505360c86f4f2e /audio/2.0/default/StreamIn.cpp | |
parent | bbd6adda5af693692c889b47ef1394a578c5baea (diff) |
audiohal: Make closing of effects and streams fast
There were two problems:
1. Joining of reader / writer / process threads (the threads that
interact with HAL) was taking up to 1 second because the thread
was usually waiting for an event flag to be toggled, or a 1s
timeout.
2. Calling IStream.close or IEffect.close shouldn't tax the caller.
Changed the code so a call to close only signals the thread that
it's time to exit, and then the thread is only joined in the
effect or stream destructor.
Bug: 34800063
Bug: 34499806
Test: see repro steps in the bugs
Change-Id: Ife20524a1eba4ec9a78152e89862526e8cd5c960
Diffstat (limited to 'audio/2.0/default/StreamIn.cpp')
-rw-r--r-- | audio/2.0/default/StreamIn.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/audio/2.0/default/StreamIn.cpp b/audio/2.0/default/StreamIn.cpp index ad18986401..b444423738 100644 --- a/audio/2.0/default/StreamIn.cpp +++ b/audio/2.0/default/StreamIn.cpp @@ -16,10 +16,12 @@ #define LOG_TAG "StreamInHAL" //#define LOG_NDEBUG 0 +#define ATRACE_TAG ATRACE_TAG_AUDIO #include <android/log.h> #include <hardware/audio.h> #include <mediautils/SchedulingPolicyService.h> +#include <utils/Trace.h> #include "StreamIn.h" @@ -120,7 +122,18 @@ StreamIn::StreamIn(audio_hw_device_t* device, audio_stream_in_t* stream) } StreamIn::~StreamIn() { + ATRACE_CALL(); close(); + if (mReadThread.get()) { + ATRACE_NAME("mReadThread->join"); + status_t status = mReadThread->join(); + ALOGE_IF(status, "read thread exit error: %s", strerror(-status)); + } + if (mEfGroup) { + status_t status = EventFlag::deleteEventFlag(&mEfGroup); + ALOGE_IF(status, "read MQ event flag deletion error: %s", strerror(-status)); + } + mDevice->close_input_stream(mDevice, mStream); mStream = nullptr; mDevice = nullptr; } @@ -240,14 +253,10 @@ Return<Result> StreamIn::close() { mIsClosed = true; if (mReadThread.get()) { mStopReadThread.store(true, std::memory_order_release); - status_t status = mReadThread->requestExitAndWait(); - ALOGE_IF(status, "read thread exit error: %s", strerror(-status)); } if (mEfGroup) { - status_t status = EventFlag::deleteEventFlag(&mEfGroup); - ALOGE_IF(status, "read MQ event flag deletion error: %s", strerror(-status)); + mEfGroup->wake(static_cast<uint32_t>(MessageQueueFlagBits::NOT_FULL)); } - mDevice->close_input_stream(mDevice, mStream); return Result::OK; } |