diff options
| author | 2021-10-06 22:53:36 +0000 | |
|---|---|---|
| committer | 2021-10-06 22:53:36 +0000 | |
| commit | 097d2a50873100486d65a69cb1cbabf37fb3b188 (patch) | |
| tree | c2f19f92e4503b2de0afeebdd9bf7aeb1bb2e9c1 /libs/ui/FenceTime.cpp | |
| parent | cbfb18e134845deeace954bbba818acda48cb80f (diff) | |
| parent | adcb6a2733c1baf66e5ad72365965ab504f5f959 (diff) | |
Merge Android 12
Bug: 202323961
Merged-In: Ifb27b3eb12454fa96f07e6797745c697b4f831c4
Change-Id: I2a7f5931477fddb51564c2eabcdc96ce58888ce8
Diffstat (limited to 'libs/ui/FenceTime.cpp')
| -rw-r--r-- | libs/ui/FenceTime.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libs/ui/FenceTime.cpp b/libs/ui/FenceTime.cpp index bdfe04b0dd..538c1d2a42 100644 --- a/libs/ui/FenceTime.cpp +++ b/libs/ui/FenceTime.cpp @@ -97,6 +97,34 @@ bool FenceTime::isValid() const { return mState != State::INVALID; } +status_t FenceTime::wait(int timeout) { + // See if we already have a cached value we can return. + nsecs_t signalTime = mSignalTime.load(std::memory_order_relaxed); + if (signalTime != Fence::SIGNAL_TIME_PENDING) { + return NO_ERROR; + } + + // Hold a reference to the fence on the stack in case the class' + // reference is removed by another thread. This prevents the + // fence from being destroyed until the end of this method, where + // we conveniently do not have the lock held. + sp<Fence> fence; + { + // With the lock acquired this time, see if we have the cached + // value or if we need to poll the fence. + std::lock_guard<std::mutex> lock(mMutex); + if (!mFence.get()) { + // Another thread set the signal time just before we added the + // reference to mFence. + return NO_ERROR; + } + fence = mFence; + } + + // Make the system call without the lock held. + return fence->wait(timeout); +} + nsecs_t FenceTime::getSignalTime() { // See if we already have a cached value we can return. nsecs_t signalTime = mSignalTime.load(std::memory_order_relaxed); |