Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 28f13513 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

AudioRecord callback thread waits for priority boost

Change-Id: Iae38fa4ac20a45751566169213a08a15deb0a2f6
parent f36dbfe3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -476,6 +476,7 @@ private:

    int                     mPreviousPriority;  // before start()
    SchedPolicy             mPreviousSchedulingGroup;
    bool                    mAwaitBoost;    // thread should wait for priority boost before running

    // The proxy should only be referenced while a lock is held because the proxy isn't
    // multi-thread safe.
+20 −0
Original line number Diff line number Diff line
@@ -665,6 +665,26 @@ ssize_t AudioRecord::read(void* buffer, size_t userSize)
nsecs_t AudioRecord::processAudioBuffer(const sp<AudioRecordThread>& thread)
{
    mLock.lock();
    if (mAwaitBoost) {
        mAwaitBoost = false;
        mLock.unlock();
        static const int32_t kMaxTries = 5;
        int32_t tryCounter = kMaxTries;
        uint32_t pollUs = 10000;
        do {
            int policy = sched_getscheduler(0);
            if (policy == SCHED_FIFO || policy == SCHED_RR) {
                break;
            }
            usleep(pollUs);
            pollUs <<= 1;
        } while (tryCounter-- > 0);
        if (tryCounter < 0) {
            ALOGE("did not receive expected priority boost on time");
        }
        // Run again immediately
        return 0;
    }

    // Can only reference mCblk while locked
    int32_t flags = android_atomic_and(~CBLK_OVERRUN, &mCblk->mFlags);