am ae66946b: Merge "fix a race in SF buffer management" into gingerbread

Merge commit 'ae66946bd9e9f1168241c75196d2379b43e3ca30' into gingerbread-plus-aosp

* commit 'ae66946bd9e9f1168241c75196d2379b43e3ca30':
  fix a race in SF buffer management
diff --git a/include/private/surfaceflinger/SharedBufferStack.h b/include/private/surfaceflinger/SharedBufferStack.h
index d016dfa..d689667 100644
--- a/include/private/surfaceflinger/SharedBufferStack.h
+++ b/include/private/surfaceflinger/SharedBufferStack.h
@@ -151,7 +151,6 @@
     ~SharedBufferBase();
     status_t getStatus() const;
     int32_t getIdentity() const;
-    size_t getFrontBuffer() const;
     String8 dump(char const* prefix) const;
 
 protected:
@@ -226,6 +225,11 @@
         inline ssize_t operator()();
     };
 
+    struct DequeueUpdate : public UpdateBase {
+        inline DequeueUpdate(SharedBufferBase* sbb);
+        inline ssize_t operator()();
+    };
+
     struct UndoDequeueUpdate : public UpdateBase {
         inline UndoDequeueUpdate(SharedBufferBase* sbb);
         inline ssize_t operator()();
diff --git a/libs/surfaceflinger_client/SharedBufferStack.cpp b/libs/surfaceflinger_client/SharedBufferStack.cpp
index 4ad9f86..38b2fae 100644
--- a/libs/surfaceflinger_client/SharedBufferStack.cpp
+++ b/libs/surfaceflinger_client/SharedBufferStack.cpp
@@ -191,12 +191,6 @@
     return stack.identity;
 }
 
-size_t SharedBufferBase::getFrontBuffer() const
-{
-    SharedBufferStack& stack( *mSharedStack );
-    return size_t( stack.head );
-}
-
 String8 SharedBufferBase::dump(char const* prefix) const
 {
     const size_t SIZE = 1024;
@@ -281,6 +275,16 @@
     return NO_ERROR;
 }
 
+SharedBufferClient::DequeueUpdate::DequeueUpdate(SharedBufferBase* sbb)
+    : UpdateBase(sbb) {
+}
+ssize_t SharedBufferClient::DequeueUpdate::operator()() {
+    if (android_atomic_dec(&stack.available) == 0) {
+        LOGW("dequeue probably called from multiple threads!");
+    }
+    return NO_ERROR;
+}
+
 SharedBufferClient::UndoDequeueUpdate::UndoDequeueUpdate(SharedBufferBase* sbb)
     : UpdateBase(sbb) {    
 }
@@ -388,12 +392,8 @@
     if (err != NO_ERROR)
         return ssize_t(err);
 
-    // NOTE: 'stack.available' is part of the conditions, however
-    // decrementing it, never changes any conditions, so we don't need
-    // to do this as part of an update.
-    if (android_atomic_dec(&stack.available) == 0) {
-        LOGW("dequeue probably called from multiple threads!");
-    }
+    DequeueUpdate update(this);
+    updateCondition( update );
 
     undoDequeueTail = tail;
     int dequeued = stack.index[tail];