summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dan Stoza <stoza@google.com> 2016-10-13 09:45:00 -0700
committer Dan Stoza <stoza@google.com> 2016-10-13 12:15:27 -0700
commit0eeb676e662bd9747ff2fbdb854d3dc3448dfbd7 (patch)
treedf6c6d7d4597a61f74e47607b80439e78925a24c
parent70d2598ce8ef1833496a0be67f2bb52038286666 (diff)
libui: Change hasSignaled to return optional<bool>
Since the android::Fence::wait() call can possibly return an error, we need some way of indicating to the caller of hasSignaled that a fence that has not yet signaled (because it is in an error state) will never signal. To do this, we return an optional<bool>, where true and false indicate both that the fence is valid and that it has or hasn't signaled. If an error is returned from wait(), we return a default optional value (that is neither true nor false). Test: m Change-Id: Ibce48cd2e71ddb8ccf6cabe3284afe0efca8c132
-rw-r--r--include/ui/Fence.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/include/ui/Fence.h b/include/ui/Fence.h
index 2fbc9efb45..1df15f897c 100644
--- a/include/ui/Fence.h
+++ b/include/ui/Fence.h
@@ -27,6 +27,8 @@
#include <utils/String8.h>
#include <utils/Timers.h>
+#include <experimental/optional>
+
struct ANativeWindowBuffer;
namespace android {
@@ -96,16 +98,26 @@ public:
// occurs then -1 is returned.
nsecs_t getSignalTime() const;
+#if __cplusplus > 201103L
// 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() {
+ // signaled. Returns an optional bool, which will have a value if there was
+ // no error.
+ inline std::experimental::optional<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;
+ switch (wait(0)) {
+ case NO_ERROR:
+ return true;
+ case -ETIME:
+ return false;
+ default:
+ return {};
+ }
}
+#endif
// Flattenable interface
size_t getFlattenedSize() const;