diff options
author | Glenn Kasten <gkasten@google.com> | 2013-06-24 12:06:46 -0700 |
---|---|---|
committer | Glenn Kasten <gkasten@google.com> | 2013-06-24 13:34:08 -0700 |
commit | 0d09a9bec07b3bec78bd473ff0bfcf0a261f3f25 (patch) | |
tree | 410d8c22e5d15f9143d04212cd96939c217cacc5 /media/libmedia/AudioTrackShared.cpp | |
parent | a2cf13c77260f98fc674f103dcbd2bb2488a80ce (diff) | |
download | frameworks_av-0d09a9bec07b3bec78bd473ff0bfcf0a261f3f25.zip frameworks_av-0d09a9bec07b3bec78bd473ff0bfcf0a261f3f25.tar.gz frameworks_av-0d09a9bec07b3bec78bd473ff0bfcf0a261f3f25.tar.bz2 |
Use mFutex as an event flag rather than semaphore
An event flag can be more fault-tolerant in case of loss of synchronization,
as it cannot overflow. It also allows more bits to be used in the future.
See http://en.wikipedia.org/wiki/Event_flag
Change-Id: I01ca25d951eb263124da54bb4738f0d94ec4a48b
Diffstat (limited to 'media/libmedia/AudioTrackShared.cpp')
-rw-r--r-- | media/libmedia/AudioTrackShared.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/media/libmedia/AudioTrackShared.cpp b/media/libmedia/AudioTrackShared.cpp index f034164..4b7f368 100644 --- a/media/libmedia/AudioTrackShared.cpp +++ b/media/libmedia/AudioTrackShared.cpp @@ -207,15 +207,15 @@ status_t ClientProxy::obtainBuffer(Buffer* buffer, const struct timespec *reques ts = NULL; break; } - int32_t old = android_atomic_dec(&cblk->mFutex); - if (old <= 0) { + int32_t old = android_atomic_and(~CBLK_FUTEX_WAKE, &cblk->mFutex); + if (!(old & CBLK_FUTEX_WAKE)) { int rc; if (measure && !beforeIsValid) { clock_gettime(CLOCK_MONOTONIC, &before); beforeIsValid = true; } int ret = __futex_syscall4(&cblk->mFutex, - mClientInServer ? FUTEX_WAIT_PRIVATE : FUTEX_WAIT, old - 1, ts); + mClientInServer ? FUTEX_WAIT_PRIVATE : FUTEX_WAIT, old & ~CBLK_FUTEX_WAKE, ts); // update total elapsed time spent waiting if (measure) { struct timespec after; @@ -484,9 +484,8 @@ void ServerProxy::releaseBuffer(Buffer* buffer) } if (!mDeferWake && mAvailToClient + stepCount >= minimum) { ALOGV("mAvailToClient=%u stepCount=%u minimum=%u", mAvailToClient, stepCount, minimum); - // could client be sleeping, or not need this increment and counter overflows? - int32_t old = android_atomic_inc(&cblk->mFutex); - if (old == -1) { + int32_t old = android_atomic_or(CBLK_FUTEX_WAKE, &cblk->mFutex); + if (!(old & CBLK_FUTEX_WAKE)) { (void) __futex_syscall3(&cblk->mFutex, mClientInServer ? FUTEX_WAKE_PRIVATE : FUTEX_WAKE, 1); } |