Add timeout to Queue read operations
This lets us poll a quit flag up a layer in the event loop.
Change-Id: Id25c5098ded06c5af1d74591e4d606c0b7220c38
diff --git a/aos/condition.h b/aos/condition.h
index 9678250..7e9f3c6 100644
--- a/aos/condition.h
+++ b/aos/condition.h
@@ -1,6 +1,8 @@
#ifndef AOS_CONDITION_H_
#define AOS_CONDITION_H_
+#include <chrono>
+
#include "aos/ipc_lib/aos_sync.h"
namespace aos {
@@ -48,6 +50,8 @@
// object will hold on to a reference to it but does not take ownership.
explicit Condition(Mutex *m);
+ enum class WaitResult { kOk, kOwnerDied, kTimeout };
+
// Waits for the condition variable to be signalled, atomically unlocking the
// mutex associated with this condition variable at the same time. The mutex
// associated with this condition variable must be locked when this is called
@@ -57,6 +61,10 @@
// Returns true if the previous owner of the mutex died before we relocked it.
bool Wait() __attribute__((warn_unused_result));
+ // Waits for the condition variable to be signalled with a timeout.
+ WaitResult WaitTimed(::std::chrono::nanoseconds timeout)
+ __attribute__((warn_unused_result));
+
// Signals approximately 1 other process currently Wait()ing on this condition
// variable. Calling this does not require the mutex associated with this
// condition variable to be locked.