Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / Notification_Queue.h
bloba9ad1ad245b816634dca8865da8123eceebf37e1
1 #ifndef ACE_NOTIFICATION_QUEUE_H
2 #define ACE_NOTIFICATION_QUEUE_H
4 #include /**/ "ace/pre.h"
6 /**
7 * @file Notification_Queue.h
9 * $Id: Notification_Queue.h 80826 2008-03-04 14:51:23Z wotte $
11 * @author Carlos O'Ryan <coryan@atdesk.com>
13 #include "ace/Copy_Disabled.h"
14 #include "ace/Event_Handler.h"
15 #include "ace/Intrusive_List.h"
16 #include "ace/Intrusive_List_Node.h"
17 #include "ace/Unbounded_Queue.h"
19 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
21 /**
22 * @class ACE_Notification_Queue_Node
24 * @brief Helper class
26 class ACE_Export ACE_Notification_Queue_Node
27 : public ACE_Intrusive_List_Node<ACE_Notification_Queue_Node>
29 public:
30 /**
31 * @brief Constructor
33 ACE_Notification_Queue_Node();
35 /**
36 * @brief Modifier change the contained buffer
38 void set(ACE_Notification_Buffer const & rhs);
40 /**
41 * @brief Accessor, fetch the contained buffer
43 ACE_Notification_Buffer const & get() const;
45 /**
46 * @brief Checks if the event handler matches the purge condition
48 bool matches_for_purging(ACE_Event_Handler * eh) const;
50 /**
51 * @brief Return true if clearing the mask would leave no
52 * notifications to deliver.
54 bool mask_disables_all_notifications(ACE_Reactor_Mask mask);
56 /**
57 * @brief Clear the notifications specified by @c mask
59 void clear_mask(ACE_Reactor_Mask mask);
61 private:
62 ACE_Notification_Buffer contents_;
65 /**
66 * @class ACE_Notification_Queue
68 * @brief Implements a user-space queue to send Reactor notifications.
70 * The ACE_Reactor uses a pipe to send wake up the thread running the
71 * event loop from other threads. This pipe can be limited in size
72 * under some operating systems. For some applications, this limit
73 * presents a problem. A user-space notification queue is used to
74 * overcome those limitations. The queue tries to use as few
75 * resources on the pipe as possible, while keeping all the data in
76 * user space.
78 * This code was refactored from Select_Reactor_Base.
80 class ACE_Export ACE_Notification_Queue : private ACE_Copy_Disabled
82 public:
83 ACE_Notification_Queue();
84 ~ACE_Notification_Queue();
86 /**
87 * @brief Pre-allocate resources in the queue
89 int open();
91 /**
92 * @brief Release all resources in the queue
94 void reset();
96 /**
97 * @brief Remove all elements in the queue matching @c eh and @c mask
99 * I suggest reading the documentation in ACE_Reactor to find a more
100 * detailed description. This is just a helper function.
102 int purge_pending_notifications(ACE_Event_Handler * eh,
103 ACE_Reactor_Mask mask);
106 * @brief Add a new notification to the queue
108 * @return -1 on failure, 1 if a new message should be sent through
109 * the pipe and 0 otherwise.
111 int push_new_notification(ACE_Notification_Buffer const & buffer);
114 * @brief Extract the next notification from the queue
116 * @return -1 on failure, 1 if a message was popped, 0 otherwise
118 int pop_next_notification(
119 ACE_Notification_Buffer & current,
120 bool & more_messages_queued,
121 ACE_Notification_Buffer & next);
123 private:
125 * @brief Allocate more memory for the queue
127 int allocate_more_buffers();
129 private:
130 /// Keeps track of allocated arrays of type
131 /// ACE_Notification_Buffer. The idea is to amortize allocation
132 /// costs by allocating multiple ACE_Notification_Buffer objects at
133 /// a time.
134 ACE_Unbounded_Queue <ACE_Notification_Queue_Node*> alloc_queue_;
136 typedef ACE_Intrusive_List<ACE_Notification_Queue_Node> Buffer_List;
138 /// Keeps track of all pending notifications.
139 Buffer_List notify_queue_;
141 /// Keeps track of all free buffers.
142 Buffer_List free_queue_;
144 /// Synchronization for handling of queues.
145 ACE_SYNCH_MUTEX notify_queue_lock_;
148 ACE_END_VERSIONED_NAMESPACE_DECL
150 #if defined (__ACE_INLINE__)
151 #include "ace/Notification_Queue.inl"
152 #endif /* __ACE_INLINE__ */
154 #include /**/ "ace/post.h"
156 #endif /* ACE_NOTIFICATION_QUEUE_H */