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

Commit f86b18b1 authored by Glenn Kasten's avatar Glenn Kasten Committed by Android (Google) Code Review
Browse files

Merge "AudioRecord callback thread waits for priority boost"

parents 13c34e09 28f13513
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -474,6 +474,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
@@ -662,6 +662,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);