summaryrefslogtreecommitdiffstats
path: root/libs/gui/include
diff options
context:
space:
mode:
authorJorim Jaggi <jjaggi@google.com>2019-04-02 22:51:02 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-04-02 22:51:02 +0000
commit7c1316e263ef4001e330294d87dad21e1909df53 (patch)
tree55a65ed026ed86611180c1c4e8bb05226a218834 /libs/gui/include
parent3068624325d1ea50b7bd9546d2da6f01187ff758 (diff)
parent35b4e3839a2eb405bd172351042f81d842183715 (diff)
downloadandroid_frameworks_native-7c1316e263ef4001e330294d87dad21e1909df53.tar.gz
android_frameworks_native-7c1316e263ef4001e330294d87dad21e1909df53.tar.bz2
android_frameworks_native-7c1316e263ef4001e330294d87dad21e1909df53.zip
Merge changes I735d68e8,I1226ed73
* changes: Wait for buffer allocation Convert Mutex to std::mutex in BufferQueueCore/Producer/Consumer
Diffstat (limited to 'libs/gui/include')
-rw-r--r--libs/gui/include/gui/BufferQueueCore.h12
-rw-r--r--libs/gui/include/gui/BufferQueueProducer.h14
2 files changed, 17 insertions, 9 deletions
diff --git a/libs/gui/include/gui/BufferQueueCore.h b/libs/gui/include/gui/BufferQueueCore.h
index b377a412b..0e8028380 100644
--- a/libs/gui/include/gui/BufferQueueCore.h
+++ b/libs/gui/include/gui/BufferQueueCore.h
@@ -22,8 +22,6 @@
#include <gui/BufferSlot.h>
#include <gui/OccupancyTracker.h>
-#include <utils/Condition.h>
-#include <utils/Mutex.h>
#include <utils/NativeHandle.h>
#include <utils/RefBase.h>
#include <utils/String8.h>
@@ -33,6 +31,8 @@
#include <list>
#include <set>
+#include <mutex>
+#include <condition_variable>
#define BQ_LOGV(x, ...) ALOGV("[%s] " x, mConsumerName.string(), ##__VA_ARGS__)
#define BQ_LOGD(x, ...) ALOGD("[%s] " x, mConsumerName.string(), ##__VA_ARGS__)
@@ -134,7 +134,7 @@ private:
bool adjustAvailableSlotsLocked(int delta);
// waitWhileAllocatingLocked blocks until mIsAllocating is false.
- void waitWhileAllocatingLocked() const;
+ void waitWhileAllocatingLocked(std::unique_lock<std::mutex>& lock) const;
#if DEBUG_ONLY_CODE
// validateConsistencyLocked ensures that the free lists are in sync with
@@ -145,7 +145,7 @@ private:
// mMutex is the mutex used to prevent concurrent access to the member
// variables of BufferQueueCore objects. It must be locked whenever any
// member variable is accessed.
- mutable Mutex mMutex;
+ mutable std::mutex mMutex;
// mIsAbandoned indicates that the BufferQueue will no longer be used to
// consume image buffers pushed to it using the IGraphicBufferProducer
@@ -219,7 +219,7 @@ private:
// mDequeueCondition is a condition variable used for dequeueBuffer in
// synchronous mode.
- mutable Condition mDequeueCondition;
+ mutable std::condition_variable mDequeueCondition;
// mDequeueBufferCannotBlock indicates whether dequeueBuffer is allowed to
// block. This flag is set during connect when both the producer and
@@ -282,7 +282,7 @@ private:
// mIsAllocatingCondition is a condition variable used by producers to wait until mIsAllocating
// becomes false.
- mutable Condition mIsAllocatingCondition;
+ mutable std::condition_variable mIsAllocatingCondition;
// mAllowAllocation determines whether dequeueBuffer is allowed to allocate
// new buffers
diff --git a/libs/gui/include/gui/BufferQueueProducer.h b/libs/gui/include/gui/BufferQueueProducer.h
index 73bc5dd31..415e2a616 100644
--- a/libs/gui/include/gui/BufferQueueProducer.h
+++ b/libs/gui/include/gui/BufferQueueProducer.h
@@ -211,7 +211,8 @@ private:
Dequeue,
Attach,
};
- status_t waitForFreeSlotThenRelock(FreeSlotCaller caller, int* found) const;
+ status_t waitForFreeSlotThenRelock(FreeSlotCaller caller, std::unique_lock<std::mutex>& lock,
+ int* found) const;
sp<BufferQueueCore> mCore;
@@ -243,15 +244,22 @@ private:
// (mCore->mMutex) is held, a ticket is retained by the producer. After
// dropping the BufferQueue lock, the producer must wait on the condition
// variable until the current callback ticket matches its retained ticket.
- Mutex mCallbackMutex;
+ std::mutex mCallbackMutex;
int mNextCallbackTicket; // Protected by mCore->mMutex
int mCurrentCallbackTicket; // Protected by mCallbackMutex
- Condition mCallbackCondition;
+ std::condition_variable mCallbackCondition;
// Sets how long dequeueBuffer or attachBuffer will block if a buffer or
// slot is not yet available.
nsecs_t mDequeueTimeout;
+ // If set to true, dequeueBuffer() is currently waiting for buffer allocation to complete.
+ bool mDequeueWaitingForAllocation;
+
+ // Condition variable to signal allocateBuffers() that dequeueBuffer() is no longer waiting for
+ // allocation to complete.
+ std::condition_variable mDequeueWaitingForAllocationCondition;
+
}; // class BufferQueueProducer
} // namespace android