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

Commit 2ae13a9c authored by Andreas Huber's avatar Andreas Huber
Browse files

Don't hold the prefetcher mutex while prefetching a single source, the lock...

Don't hold the prefetcher mutex while prefetching a single source, the lock protects the list of sources and does not guard access to the individual sources.

related-to- bug: 2413024
parent 24137908
Loading
Loading
Loading
Loading
+36 −30
Original line number Diff line number Diff line
@@ -128,6 +128,9 @@ static int64_t kMaxCacheDurationUs = 10000000ll;

void Prefetcher::threadFunc() {
    for (;;) {
        sp<PrefetchedSource> minSource;

        {
            Mutex::Autolock autoLock(mLock);
            if (mDone) {
                break;
@@ -155,19 +158,22 @@ void Prefetcher::threadFunc() {
                if (minIndex < 0 || cacheDurationUs < minCacheDurationUs) {
                    minCacheDurationUs = cacheDurationUs;
                    minIndex = i;
                    minSource = source;
                }
            }

            if (minIndex < 0) {
                continue;
            }

        sp<PrefetchedSource> source = mSources[minIndex].promote();
        if (source != NULL) {
            source->cacheMore();
        }

        // Make sure not to hold the lock while calling into the source.
        // The lock guards the list of sources, not the individual sources
        // themselves.
        minSource->cacheMore();
    }

    Mutex::Autolock autoLock(mLock);
    for (size_t i = 0; i < mSources.size(); ++i) {
        sp<PrefetchedSource> source = mSources[i].promote();