CPN
Computational Process Networks
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Sync::Future< T > Class Template Reference

#include <Future.h>

+ Collaboration diagram for Sync::Future< T >:

Public Member Functions

 Future ()
 
virtual ~Future ()
 
bool Done ()
 
void Cancel ()
 
void Wait ()
 
bool IsCanceled ()
 
virtual void Set (const T &r)
 
virtual T Get ()
 

Protected Member Functions

void InternalWait ()
 
void InternalSet (const T &r)
 

Protected Attributes

PthreadMutex future_lock
 
PthreadCondition future_cond
 
bool done
 
bool canceled
 
ret
 

Detailed Description

template<typename T>
class Sync::Future< T >

The basic idea with the future is an object which will provide a value at some time in the future.

Definition at line 37 of file Future.h.

Constructor & Destructor Documentation

template<typename T>
Sync::Future< T >::Future ( )
inline

Definition at line 39 of file Future.h.

39 : done(false), canceled(false), ret() {}
bool canceled
Definition: Future.h:88
bool done
Definition: Future.h:87
template<typename T>
virtual Sync::Future< T >::~Future ( )
inlinevirtual

Definition at line 40 of file Future.h.

40 {}

Member Function Documentation

template<typename T>
void Sync::Future< T >::Cancel ( )
inline

Definition at line 47 of file Future.h.

47  {
49  canceled = true;
51  }
PthreadCondition & Broadcast(void)
bool canceled
Definition: Future.h:88
PthreadCondition future_cond
Definition: Future.h:86
PthreadMutex future_lock
Definition: Future.h:85
template<typename T>
bool Sync::Future< T >::Done ( )
inline

Definition at line 42 of file Future.h.

42  {
44  return done || canceled;
45  }
bool canceled
Definition: Future.h:88
bool done
Definition: Future.h:87
PthreadMutex future_lock
Definition: Future.h:85
template<typename T>
virtual T Sync::Future< T >::Get ( )
inlinevirtual

Reimplemented in CPN::ConnectionServer::PendingConnection.

Definition at line 68 of file Future.h.

68  {
70  InternalWait();
71  return ret;
72  }
void InternalWait()
Definition: Future.h:75
PthreadMutex future_lock
Definition: Future.h:85
template<typename T>
void Sync::Future< T >::InternalSet ( const T &  r)
inlineprotected

Definition at line 79 of file Future.h.

Referenced by Sync::Future< int >::Set(), and Sync::Future< void >::Set().

79  {
80  ret = r;
81  done = true;
83  }
PthreadCondition & Broadcast(void)
bool done
Definition: Future.h:87
PthreadCondition future_cond
Definition: Future.h:86

+ Here is the caller graph for this function:

template<typename T>
void Sync::Future< T >::InternalWait ( )
inlineprotected

Definition at line 75 of file Future.h.

Referenced by Sync::Future< int >::Get(), Sync::Future< void >::Get(), Sync::Future< int >::Wait(), and Sync::Future< void >::Wait().

75  {
76  while (!canceled && !done) { future_cond.Wait(future_lock); }
77  }
PthreadCondition & Wait(PthreadMutex &mutex)
bool canceled
Definition: Future.h:88
bool done
Definition: Future.h:87
PthreadCondition future_cond
Definition: Future.h:86
PthreadMutex future_lock
Definition: Future.h:85

+ Here is the caller graph for this function:

template<typename T>
bool Sync::Future< T >::IsCanceled ( )
inline

Definition at line 58 of file Future.h.

58  {
60  return canceled;
61  }
bool canceled
Definition: Future.h:88
PthreadMutex future_lock
Definition: Future.h:85
template<typename T>
virtual void Sync::Future< T >::Set ( const T &  r)
inlinevirtual

Definition at line 63 of file Future.h.

63  {
65  InternalSet(r);
66  }
void InternalSet(const T &r)
Definition: Future.h:79
PthreadMutex future_lock
Definition: Future.h:85
template<typename T>
void Sync::Future< T >::Wait ( )
inline

Definition at line 53 of file Future.h.

53  {
55  InternalWait();
56  }
void InternalWait()
Definition: Future.h:75
PthreadMutex future_lock
Definition: Future.h:85

Member Data Documentation

template<typename T>
bool Sync::Future< T >::canceled
protected
template<typename T>
bool Sync::Future< T >::done
protected
template<typename T>
PthreadCondition Sync::Future< T >::future_cond
protected
template<typename T>
PthreadMutex Sync::Future< T >::future_lock
protected
template<typename T>
T Sync::Future< T >::ret
protected

Definition at line 89 of file Future.h.

Referenced by Sync::Future< int >::Get(), and Sync::Future< int >::InternalSet().


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