Loading media/libaaudio/src/core/AudioStream.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -452,8 +452,8 @@ aaudio_result_t AudioStream::createThread_l(int64_t periodNanoseconds, void* threadArg) { if (mHasThread) { ALOGE("%s() - mHasThread already true", __func__); return AAUDIO_ERROR_INVALID_STATE; ALOGD("%s() - previous thread was not joined, join now to be safe", __func__); joinThread_l(nullptr); } if (threadProc == nullptr) { return AAUDIO_ERROR_NULL; Loading @@ -462,6 +462,7 @@ aaudio_result_t AudioStream::createThread_l(int64_t periodNanoseconds, mThreadProc = threadProc; mThreadArg = threadArg; setPeriodNanoseconds(periodNanoseconds); mHasThread = true; // Prevent this object from getting deleted before the thread has a chance to create // its strong pointer. Assume the thread will call decStrong(). this->incStrong(nullptr); Loading @@ -470,6 +471,7 @@ aaudio_result_t AudioStream::createThread_l(int64_t periodNanoseconds, android::status_t status = -errno; ALOGE("%s() - pthread_create() failed, %d", __func__, status); this->decStrong(nullptr); // Because the thread won't do it. mHasThread = false; return AAudioConvert_androidToAAudioResult(status); } else { // TODO Use AAudioThread or maybe AndroidThread Loading @@ -484,7 +486,6 @@ aaudio_result_t AudioStream::createThread_l(int64_t periodNanoseconds, err = pthread_setname_np(mThread, name); ALOGW_IF((err != 0), "Could not set name of AAudio thread. err = %d", err); mHasThread = true; return AAUDIO_OK; } } Loading @@ -498,7 +499,7 @@ aaudio_result_t AudioStream::joinThread(void** returnArg) { // This must be called under mStreamLock. aaudio_result_t AudioStream::joinThread_l(void** returnArg) { if (!mHasThread) { ALOGD("joinThread() - but has no thread"); ALOGD("joinThread() - but has no thread or already join()ed"); return AAUDIO_ERROR_INVALID_STATE; } aaudio_result_t result = AAUDIO_OK; Loading @@ -515,8 +516,7 @@ aaudio_result_t AudioStream::joinThread_l(void** returnArg) { result = AAudioConvert_androidToAAudioResult(-err); } else { ALOGD("%s() pthread_join succeeded", __func__); // This must be set false so that the callback thread can be created // when the stream is restarted. // Prevent joining a second time, which has undefined behavior. mHasThread = false; } } else { Loading media/libaaudio/src/core/AudioStream.h +13 −3 Original line number Diff line number Diff line Loading @@ -157,9 +157,13 @@ public: virtual aaudio_result_t setBufferSize(int32_t requestedFrames) = 0; virtual aaudio_result_t createThread_l(int64_t periodNanoseconds, aaudio_result_t createThread(int64_t periodNanoseconds, aaudio_audio_thread_proc_t threadProc, void *threadArg); void *threadArg) EXCLUDES(mStreamLock) { std::lock_guard<std::mutex> lock(mStreamLock); return createThread_l(periodNanoseconds, threadProc, threadArg); } aaudio_result_t joinThread(void **returnArg); Loading Loading @@ -535,6 +539,11 @@ protected: mSessionId = sessionId; } aaudio_result_t createThread_l(int64_t periodNanoseconds, aaudio_audio_thread_proc_t threadProc, void *threadArg) REQUIRES(mStreamLock); aaudio_result_t joinThread_l(void **returnArg) REQUIRES(mStreamLock); std::atomic<bool> mCallbackEnabled{false}; Loading Loading @@ -658,6 +667,7 @@ private: std::atomic<pid_t> mErrorCallbackThread{CALLBACK_THREAD_NONE}; // background thread ---------------------------------- // Use mHasThread to prevent joining twice, which has undefined behavior. bool mHasThread GUARDED_BY(mStreamLock) = false; pthread_t mThread GUARDED_BY(mStreamLock) = {}; Loading services/oboeservice/AAudioServiceEndpointShared.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ aaudio_result_t aaudio::AAudioServiceEndpointShared::startSharingThread_l() { // Prevent this object from getting deleted before the thread has a chance to create // its strong pointer. Assume the thread will call decStrong(). this->incStrong(nullptr); aaudio_result_t result = getStreamInternal()->createThread_l(periodNanos, aaudio_result_t result = getStreamInternal()->createThread(periodNanos, aaudio_endpoint_thread_proc, this); if (result != AAUDIO_OK) { Loading Loading
media/libaaudio/src/core/AudioStream.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -452,8 +452,8 @@ aaudio_result_t AudioStream::createThread_l(int64_t periodNanoseconds, void* threadArg) { if (mHasThread) { ALOGE("%s() - mHasThread already true", __func__); return AAUDIO_ERROR_INVALID_STATE; ALOGD("%s() - previous thread was not joined, join now to be safe", __func__); joinThread_l(nullptr); } if (threadProc == nullptr) { return AAUDIO_ERROR_NULL; Loading @@ -462,6 +462,7 @@ aaudio_result_t AudioStream::createThread_l(int64_t periodNanoseconds, mThreadProc = threadProc; mThreadArg = threadArg; setPeriodNanoseconds(periodNanoseconds); mHasThread = true; // Prevent this object from getting deleted before the thread has a chance to create // its strong pointer. Assume the thread will call decStrong(). this->incStrong(nullptr); Loading @@ -470,6 +471,7 @@ aaudio_result_t AudioStream::createThread_l(int64_t periodNanoseconds, android::status_t status = -errno; ALOGE("%s() - pthread_create() failed, %d", __func__, status); this->decStrong(nullptr); // Because the thread won't do it. mHasThread = false; return AAudioConvert_androidToAAudioResult(status); } else { // TODO Use AAudioThread or maybe AndroidThread Loading @@ -484,7 +486,6 @@ aaudio_result_t AudioStream::createThread_l(int64_t periodNanoseconds, err = pthread_setname_np(mThread, name); ALOGW_IF((err != 0), "Could not set name of AAudio thread. err = %d", err); mHasThread = true; return AAUDIO_OK; } } Loading @@ -498,7 +499,7 @@ aaudio_result_t AudioStream::joinThread(void** returnArg) { // This must be called under mStreamLock. aaudio_result_t AudioStream::joinThread_l(void** returnArg) { if (!mHasThread) { ALOGD("joinThread() - but has no thread"); ALOGD("joinThread() - but has no thread or already join()ed"); return AAUDIO_ERROR_INVALID_STATE; } aaudio_result_t result = AAUDIO_OK; Loading @@ -515,8 +516,7 @@ aaudio_result_t AudioStream::joinThread_l(void** returnArg) { result = AAudioConvert_androidToAAudioResult(-err); } else { ALOGD("%s() pthread_join succeeded", __func__); // This must be set false so that the callback thread can be created // when the stream is restarted. // Prevent joining a second time, which has undefined behavior. mHasThread = false; } } else { Loading
media/libaaudio/src/core/AudioStream.h +13 −3 Original line number Diff line number Diff line Loading @@ -157,9 +157,13 @@ public: virtual aaudio_result_t setBufferSize(int32_t requestedFrames) = 0; virtual aaudio_result_t createThread_l(int64_t periodNanoseconds, aaudio_result_t createThread(int64_t periodNanoseconds, aaudio_audio_thread_proc_t threadProc, void *threadArg); void *threadArg) EXCLUDES(mStreamLock) { std::lock_guard<std::mutex> lock(mStreamLock); return createThread_l(periodNanoseconds, threadProc, threadArg); } aaudio_result_t joinThread(void **returnArg); Loading Loading @@ -535,6 +539,11 @@ protected: mSessionId = sessionId; } aaudio_result_t createThread_l(int64_t periodNanoseconds, aaudio_audio_thread_proc_t threadProc, void *threadArg) REQUIRES(mStreamLock); aaudio_result_t joinThread_l(void **returnArg) REQUIRES(mStreamLock); std::atomic<bool> mCallbackEnabled{false}; Loading Loading @@ -658,6 +667,7 @@ private: std::atomic<pid_t> mErrorCallbackThread{CALLBACK_THREAD_NONE}; // background thread ---------------------------------- // Use mHasThread to prevent joining twice, which has undefined behavior. bool mHasThread GUARDED_BY(mStreamLock) = false; pthread_t mThread GUARDED_BY(mStreamLock) = {}; Loading
services/oboeservice/AAudioServiceEndpointShared.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ aaudio_result_t aaudio::AAudioServiceEndpointShared::startSharingThread_l() { // Prevent this object from getting deleted before the thread has a chance to create // its strong pointer. Assume the thread will call decStrong(). this->incStrong(nullptr); aaudio_result_t result = getStreamInternal()->createThread_l(periodNanos, aaudio_result_t result = getStreamInternal()->createThread(periodNanos, aaudio_endpoint_thread_proc, this); if (result != AAUDIO_OK) { Loading