Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / Future_Set.h
bloba954d29974602f580f09c4d9725b79cac3a4002a
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Future_Set.h
7 * $Id: Future_Set.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author John Tucker <jtucker@infoglide.com>
11 //=============================================================================
13 #ifndef ACE_FUTURE_SET_H
14 #define ACE_FUTURE_SET_H
15 #include /**/ "ace/pre.h"
17 #include "ace/Thread.h"
18 #include "ace/Message_Queue.h"
19 #include "ace/Future.h"
20 #include "ace/Hash_Map_Manager_T.h"
21 #include "ace/Null_Mutex.h"
23 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 #pragma once
25 #endif /* ACE_LACKS_PRAGMA_ONCE */
27 #if defined (ACE_HAS_THREADS)
29 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
31 /**
32 * @class ACE_Future_Set
34 * @brief This class implements a mechanism which allows the values of
35 * a collection of ACE_Future objects to be accessed by reader threads
36 * as they become available. The caller(s) provide the ACE_Future_Set
37 * (i.e. the observer...) with the collection of ACE_Future objects
38 * (i.e. the subjects...) that are to be observed using the
39 * the ACE_Future_Set::insert() method. The caller(s) may then iterate
40 * over the collection in the order in which they become readable using
41 * the ACE_Future_Set::next_readable() method.
43 template <class T>
44 class ACE_Future_Set : public ACE_Future_Observer<T>
46 public:
47 // = Initialization and termination methods.
49 /// Constructor.
50 ACE_Future_Set (ACE_Message_Queue<ACE_SYNCH> *future_notification_queue_ = 0);
52 /// Destructor.
53 ~ACE_Future_Set (void);
55 /**
56 * Return 1 if their are no ACE_Future objects left on its queue and
57 * 0 otherwise.
59 * When an ACE_Future_Set has no ACE_Future>subjects to observe it is
60 * empty. The ACE_Future_Set is in the empty state when either the caller(s)
61 * have retrieved every readable ACE_Future subject assigned the
62 * ACE_Future_Set via the ACE_Future_Set::next_readable() method,
63 * or when the ACE_Future_Set has not been assigned any subjects.
65 int is_empty (void) const;
67 /**
68 * Enqueus the given ACE_Future into this objects queue when it is
69 * readable.
71 * Returns 0 if the future is successfully inserted, 1 if the
72 * future is already inserted, and -1 if failures occur.
74 int insert (ACE_Future<T> &future);
76 /**
77 * Wait up to @a tv time to get the @a value. Note that @a tv must be
78 * specified in absolute time rather than relative time.); get the
79 * next ACE_Future that is readable. If @a tv = 0, the will block
80 * forever.
82 * If a readable future becomes available, then the input
83 * ACE_Future object param will be assigned with it and 1 will
84 * be returned. If the ACE_Future_Set is empty (i.e. see definition
85 * of ACE_Future_Set::is_empty()), then 0 is returned.
87 * When a readable ACE_Future object is retrieved via the
88 * ACE_Future_Set::next_readable() method, the ACE_Future_Set will
89 * remove that ACE_Future object from its list of subjects.
91 int next_readable (ACE_Future<T> &result,
92 ACE_Time_Value *tv = 0);
94 /// Called by the ACE_Future subject in which we are subscribed to
95 /// when its value is written to.
96 virtual void update (const ACE_Future<T> &future);
98 /// Declare the dynamic allocation hooks.
99 ACE_ALLOC_HOOK_DECLARE;
101 private:
102 // = Disallow these operations.
103 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Future_Set<T> &))
104 ACE_UNIMPLEMENTED_FUNC (ACE_Future_Set (const ACE_Future_Set<T> &))
106 typedef ACE_Future<T> FUTURE;
108 typedef ACE_Future_Rep<T> FUTURE_REP;
110 typedef ACE_Future_Holder<T> FUTURE_HOLDER;
112 typedef ACE_Pointer_Hash<FUTURE_REP *> FUTURE_REP_HASH;
114 typedef ACE_Equal_To<FUTURE_REP *> FUTURE_REP_COMPARE;
116 typedef ACE_Hash_Map_Manager_Ex<FUTURE_REP *,
117 FUTURE_HOLDER *,
118 FUTURE_REP_HASH,
119 FUTURE_REP_COMPARE,
120 ACE_Null_Mutex> FUTURE_HASH_MAP;
122 /// Map of <ACE_Futures>, subjects, which have not been written to by
123 /// client's writer thread.
124 FUTURE_HASH_MAP future_map_;
126 /// Message queue for notifying the reader thread of <ACE_Futures> which
127 /// have been written to by client's writer thread.
128 ACE_Message_Queue<ACE_SYNCH> *future_notification_queue_;
130 /// Keeps track of whether we need to delete the message queue.
131 bool delete_queue_;
134 ACE_END_VERSIONED_NAMESPACE_DECL
136 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
137 #include "ace/Future_Set.cpp"
138 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
140 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
141 #pragma implementation ("Future_Set.cpp")
142 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
144 #endif /* ACE_HAS_THREADS */
145 #include /**/ "ace/post.h"
146 #endif /* ACE_FUTURE_SET_H */