OSDN Git Service

libui: Add hasSignaled() method to Fence
authorDan Stoza <stoza@google.com>
Wed, 12 Oct 2016 17:35:17 +0000 (10:35 -0700)
committerMatthew Bouyack <mbouyack@google.com>
Wed, 12 Oct 2016 19:48:43 +0000 (12:48 -0700)
Adds a hasSignaled() method to android::Fence. This will make it easier
to write client code that only cares whether a fence has signaled, and
allows such code to gain the performance benefits of wait(0) (which is
significantly faster than getSignalTime()) while still being obvious
about what it is trying to do.

Test: m

Change-Id: Ia28ce6cff3860a171254ea20a24f3f1bfbc67eb8

include/ui/Fence.h

index 23a8658..fa4b9bc 100644 (file)
@@ -96,6 +96,17 @@ public:
     // occurs then -1 is returned.
     nsecs_t getSignalTime() const;
 
+    // hasSignaled returns whether the fence has signaled yet. Prefer this to
+    // getSignalTime() or wait() if all you care about is whether the fence has
+    // signaled.
+    inline bool hasSignaled() {
+        // The sync_wait call underlying wait() has been measured to be
+        // significantly faster than the sync_fence_info call underlying
+        // getSignalTime(), which might otherwise appear to be the more obvious
+        // way to check whether a fence has signaled.
+        return wait(0) == NO_ERROR;
+    }
+
     // Flattenable interface
     size_t getFlattenedSize() const;
     size_t getFdCount() const;