Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::Promise< T > Class Template Reference

#include <promise.h>

Collaboration diagram for impala::Promise< T >:

Public Member Functions

 Promise ()
 
void Set (const T &val)
 
const T & Get ()
 
const T & Get (int64_t timeout_millis, bool *timed_out)
 
bool IsSet ()
 Returns whether the value is set. More...
 

Private Attributes

boost::condition_variable val_set_cond_
 
bool val_is_set_
 
boost::mutex val_lock_
 
val_
 The actual value transferred from producer to consumer. More...
 

Detailed Description

template<typename T>
class impala::Promise< T >

A stripped-down replacement for boost::promise which, to the best of our knowledge, actually works. A single producer provides a single value by calling Set(..), which one or more consumers retrieve through calling Get(..). Consumers must be consistent in their use of Get(), i.e., for a particular promise all consumers should either have a timeout or not.

Definition at line 32 of file promise.h.

Constructor & Destructor Documentation

template<typename T>
impala::Promise< T >::Promise ( )
inline

Definition at line 34 of file promise.h.

Member Function Documentation

template<typename T>
const T& impala::Promise< T >::Get ( )
inline

Blocks until a value is set, and then returns a reference to that value. Once Get() returns, the returned value will not change, since Set(..) may not be called twice.

Definition at line 59 of file promise.h.

Referenced by impala::AdmissionController::AdmitQuery(), impala::HdfsOperationSet::Execute(), impala::BlockingJoinNode::Open(), impala::ThriftThread::start(), impala::Thread::StartThread(), impala::TEST(), and impala::ResourceBroker::WaitForNotification().

template<typename T>
const T& impala::Promise< T >::Get ( int64_t  timeout_millis,
bool timed_out 
)
inline

Blocks until a value is set or the given timeout was reached. Returns a reference to that value which is invalid if the timeout was reached. Once Get() returns and *timed_out is false, the returned value will not change, since Set(..) may not be called twice. timeout_millis: The max wall-clock time in milliseconds to wait (must be > 0). timed_out: Indicates whether Get() returned due to timeout. Must be non-NULL.

Definition at line 73 of file promise.h.

template<typename T>
bool impala::Promise< T >::IsSet ( )
inline

Returns whether the value is set.

Definition at line 92 of file promise.h.

Referenced by impala::AdmissionController::AdmitQuery(), and impala::AdmissionController::DequeueLoop().

template<typename T>
void impala::Promise< T >::Set ( const T &  val)
inline

Copies val into this promise, and notifies any consumers blocked in Get(). It is invalid to call Set() twice.

Note: this must be called with 'val_lock_' taken. There are places where we use this object with this pattern: { Promise p; ... p.get(); } < promise object gets destroyed > Calling notify_all() with the val_lock_ guarantees that the thread calling Set() is done and the promise is safe to delete.

Definition at line 38 of file promise.h.

Referenced by impala::AdmissionController::AdmitQuery(), impala::BlockingJoinNode::BuildSideThread(), impala::AdmissionController::DequeueLoop(), impala::BufferedBlockMgrTest::GetFreeBlock(), impala::HdfsOperationSet::MarkOneOpDone(), impala::SaslAuthProvider::RunKinit(), impala::ThriftThread::RunRunnable(), impala::RunThread(), impala::Thread::SuperviseThread(), and impala::TEST().

Member Data Documentation

template<typename T>
T impala::Promise< T >::val_
private

The actual value transferred from producer to consumer.

Definition at line 105 of file promise.h.

Referenced by impala::Promise< bool >::Get(), and impala::Promise< bool >::Set().

template<typename T>
bool impala::Promise< T >::val_is_set_
private
template<typename T>
boost::mutex impala::Promise< T >::val_lock_
private
template<typename T>
boost::condition_variable impala::Promise< T >::val_set_cond_
private

These variables deal with coordination between consumer and producer, and protect access to val_;

Definition at line 100 of file promise.h.

Referenced by impala::Promise< bool >::Get(), and impala::Promise< bool >::Set().


The documentation for this class was generated from the following file: