diff options
Diffstat (limited to 'audio/core/all-versions/default/StreamOut.cpp')
-rw-r--r-- | audio/core/all-versions/default/StreamOut.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/audio/core/all-versions/default/StreamOut.cpp b/audio/core/all-versions/default/StreamOut.cpp index 82cc408e99..396d354179 100644 --- a/audio/core/all-versions/default/StreamOut.cpp +++ b/audio/core/all-versions/default/StreamOut.cpp @@ -138,8 +138,7 @@ bool WriteThread::threadLoop() { } // namespace StreamOut::StreamOut(const sp<Device>& device, audio_stream_out_t* stream) - : mIsClosed(false), - mDevice(device), + : mDevice(device), mStream(stream), mStreamCommon(new Stream(&stream->common)), mStreamMmap(new StreamMmap<audio_stream_out_t>(stream)), @@ -148,7 +147,7 @@ StreamOut::StreamOut(const sp<Device>& device, audio_stream_out_t* stream) StreamOut::~StreamOut() { ATRACE_CALL(); - close(); + (void)close(); if (mWriteThread.get()) { ATRACE_NAME("mWriteThread->join"); status_t status = mWriteThread->join(); @@ -159,10 +158,12 @@ StreamOut::~StreamOut() { ALOGE_IF(status, "write MQ event flag deletion error: %s", strerror(-status)); } mCallback.clear(); +#if MAJOR_VERSION <= 5 mDevice->closeOutputStream(mStream); // Closing the output stream in the HAL waits for the callback to finish, // and joins the callback thread. Thus is it guaranteed that the callback // thread will not be accessing our object anymore. +#endif mStream = nullptr; } @@ -291,14 +292,16 @@ Return<Result> StreamOut::setParameters(const hidl_vec<ParameterValue>& context, #endif Return<Result> StreamOut::close() { - if (mIsClosed) return Result::INVALID_STATE; - mIsClosed = true; - if (mWriteThread.get()) { - mStopWriteThread.store(true, std::memory_order_release); + if (mStopWriteThread.load(std::memory_order_relaxed)) { // only this thread writes + return Result::INVALID_STATE; } + mStopWriteThread.store(true, std::memory_order_release); if (mEfGroup) { mEfGroup->wake(static_cast<uint32_t>(MessageQueueFlagBits::NOT_EMPTY)); } +#if MAJOR_VERSION >= 6 + mDevice->closeOutputStream(mStream); +#endif return Result::OK; } |