15 #ifndef IMPALA_UTIL_PROMISE_H
16 #define IMPALA_UTIL_PROMISE_H
18 #include <boost/thread.hpp>
38 void Set(
const T& val) {
39 boost::unique_lock<boost::mutex> l(
val_lock_);
40 DCHECK(!
val_is_set_) <<
"Called Set(..) twice on the same Promise";
60 boost::unique_lock<boost::mutex> l(
val_lock_);
73 const T&
Get(int64_t timeout_millis,
bool* timed_out) {
74 DCHECK_GT(timeout_millis, 0);
75 int64_t timeout_micros = timeout_millis * 1000;
76 DCHECK(timed_out != NULL);
77 boost::unique_lock<boost::mutex> l(
val_lock_);
81 while (!
val_is_set_ && (now - start) < timeout_micros) {
82 boost::posix_time::microseconds wait_time =
83 boost::posix_time::microseconds(std::max(1L, timeout_micros - (now - start)));
93 boost::lock_guard<boost::mutex> l(
val_lock_);
const T & Get(int64_t timeout_millis, bool *timed_out)
boost::condition_variable val_set_cond_
bool IsSet()
Returns whether the value is set.
int64_t MonotonicMicros()
T val_
The actual value transferred from producer to consumer.