diff options
author | Andy Hung <hunga@google.com> | 2021-01-12 14:54:10 -0800 |
---|---|---|
committer | Andy Hung <hunga@google.com> | 2021-01-14 10:02:42 -0800 |
commit | 6ee09f04577dc07e3242c1214fcb6d5501b29a77 (patch) | |
tree | 6f13230071e1ab64c829e79c8b687e86a552ee3a /audio/core/all-versions/default/StreamOut.cpp | |
parent | 2cac3d31d55da0cb3c55f574313a1646bab68a6f (diff) |
StreamOut: use atomic_sp<> for callback thread safety
Test: see bug
Test: basic audio works
Bug: 177278988
Change-Id: Id1f5036e36b2a3b3e71e0b0ec548d4c65a972b50
Diffstat (limited to 'audio/core/all-versions/default/StreamOut.cpp')
-rw-r--r-- | audio/core/all-versions/default/StreamOut.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/audio/core/all-versions/default/StreamOut.cpp b/audio/core/all-versions/default/StreamOut.cpp index ffd3b6b856..1fb72671bb 100644 --- a/audio/core/all-versions/default/StreamOut.cpp +++ b/audio/core/all-versions/default/StreamOut.cpp @@ -163,7 +163,7 @@ StreamOut::~StreamOut() { status_t status = EventFlag::deleteEventFlag(&mEfGroup); ALOGE_IF(status, "write MQ event flag deletion error: %s", strerror(-status)); } - mCallback.clear(); + mCallback = nullptr; #if MAJOR_VERSION <= 5 mDevice->closeOutputStream(mStream); // Closing the output stream in the HAL waits for the callback to finish, @@ -462,7 +462,7 @@ Return<Result> StreamOut::setCallback(const sp<IStreamOutCallback>& callback) { Return<Result> StreamOut::clearCallback() { if (mStream->set_callback == NULL) return Result::NOT_SUPPORTED; - mCallback.clear(); + mCallback = nullptr; return Result::OK; } @@ -477,7 +477,7 @@ int StreamOut::asyncCallback(stream_callback_event_t event, void*, void* cookie) // It's correct to hold an sp<> to callback because the reference // in the StreamOut instance can be cleared in the meantime. There is // no difference on which thread to run IStreamOutCallback's destructor. - sp<IStreamOutCallback> callback = self->mCallback; + sp<IStreamOutCallback> callback = self->mCallback.load(); if (callback.get() == nullptr) return 0; ALOGV("asyncCallback() event %d", event); Return<void> result; |