[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Dev_Poll_Reactor.inl
blob96e71f2dea58f01bc090c1fea42ec44b05c8ad58
1 // -*- C++ -*-
2 //
3 // $Id: Dev_Poll_Reactor.inl 80826 2008-03-04 14:51:23Z wotte $
5 #include "ace/Log_Msg.h"
7 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
9 ACE_INLINE
10 ACE_Dev_Poll_Event_Tuple::ACE_Dev_Poll_Event_Tuple (void)
11   : event_handler (0),
12     mask (ACE_Event_Handler::NULL_MASK),
13     suspended (0)
17 // ---------------------------------------------------------------------
19 #if 0
20 ACE_INLINE
21 ACE_Dev_Poll_Ready_Set::ACE_Dev_Poll_Ready_Set (void)
22   : pfds (0),
23     nfds (0)
26 #endif  /* 0 */
28 // ---------------------------------------------------------------------
30 ACE_INLINE void
31 ACE_Dev_Poll_Reactor_Handler_Repository::mask (ACE_HANDLE handle,
32                                                ACE_Reactor_Mask mask)
34   ACE_TRACE ("ACE_Dev_Poll_Reactor_Handler_Repository::mask");
36   // Only bother to search for the handle if it's in range.
37   if (this->handle_in_range (handle))
38     this->handlers_[handle].mask = mask;
41 ACE_INLINE ACE_Reactor_Mask
42 ACE_Dev_Poll_Reactor_Handler_Repository::mask (ACE_HANDLE handle)
44   ACE_TRACE ("ACE_Dev_Poll_Reactor_Handler_Repository::mask");
46   ACE_Reactor_Mask mask = ACE_Event_Handler::NULL_MASK;
48   // Only bother to search for the handle if it's in range.
49   if (this->handle_in_range (handle))
50     mask = this->handlers_[handle].mask;
52   if (mask == ACE_Event_Handler::NULL_MASK)
53     errno = ENOENT;
55   return mask;
58 ACE_INLINE void
59 ACE_Dev_Poll_Reactor_Handler_Repository::suspend (ACE_HANDLE handle)
61   ACE_TRACE ("ACE_Dev_Poll_Reactor_Handler_Repository::suspend");
63   // Only bother to search for the handle if it's in range.
64   if (this->handle_in_range (handle))
65     this->handlers_[handle].suspended = 1;
68 ACE_INLINE void
69 ACE_Dev_Poll_Reactor_Handler_Repository::resume (ACE_HANDLE handle)
71   ACE_TRACE ("ACE_Dev_Poll_Reactor_Handler_Repository::resume");
73   // Only bother to search for the handle if it's in range.
74   if (this->handle_in_range (handle))
75     this->handlers_[handle].suspended = 0;
78 ACE_INLINE int
79 ACE_Dev_Poll_Reactor_Handler_Repository::suspended (ACE_HANDLE handle) const
81   ACE_TRACE ("ACE_Dev_Poll_Reactor_Handler_Repository::suspended");
83   if (this->handle_in_range (handle))
84     return this->handlers_[handle].suspended;
86   return -1;
89 ACE_INLINE size_t
90 ACE_Dev_Poll_Reactor_Handler_Repository::size (void) const
92   ACE_TRACE ("ACE_Dev_Poll_Reactor_Handler_Repository::size");
94   return this->max_size_;
97 // -----------------------------------------------------------------
99 ACE_INLINE
100 ACE_Dev_Poll_Handler_Guard::ACE_Dev_Poll_Handler_Guard
101   (ACE_Event_Handler *eh,
102    bool do_incr)
103   : eh_ (eh),
104     refcounted_ (false)
106   if (eh == 0)
107     return;
109   this->refcounted_ =
110     eh->reference_counting_policy ().value () ==
111     ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
113   if (do_incr && this->refcounted_)
114     eh->add_reference ();
116   /**
117    * The below comments were here when I replaced the old refcount
118    * scheme was replaced. They may still need addressing.   -Steve Huston
119    */
121   /**
122    * @todo Suspend the handler so that other threads will not cause
123    *       an event that is already in an upcall from being dispatched
124    *       again.
125    *
126    * @note The naive approach would be to simply call
127    *       suspend_handler_i() on the reactor.  However, that would
128    *       cause a system call (write()) to occur.  Obviously this
129    *       can potentially have an adverse affect on performance.
130    *       Ideally, the handler would only be marked as "suspended" in
131    *       the handler repository.  If an event arrives for a
132    *       suspended handler that event can be "queued" in a
133    *       "handle readiness queue."  "Queued" is quoted since a real
134    *       queue need not be used since duplicate events can be
135    *       coalesced, thus avoiding unbounded queue growth.  Event
136    *       coalescing is already done by Linux's event poll driver
137    *       (/dev/epoll) so Solaris' poll driver (/dev/poll) is the
138    *       main concern here.  The largest the queue can be is the
139    *       same size as the number of handlers stored in the handler
140    *       repository.
141    */
144 ACE_INLINE
145 ACE_Dev_Poll_Handler_Guard::~ACE_Dev_Poll_Handler_Guard (void)
147   if (this->refcounted_ && this->eh_ != 0)
148     this->eh_->remove_reference ();
150   /**
151    * The below comments were here when I replaced the old refcount
152    * scheme was replaced. They may still need addressing.   -Steve Huston
153    */
154   /**
155    * @todo Resume the handler so that other threads will be allowed to
156    *       dispatch the handler.
157    */
160 ACE_INLINE void
161 ACE_Dev_Poll_Handler_Guard::release (void)
163   this->eh_ = 0;
166 // ---------------------------------------------------------------------
168 ACE_INLINE int
169 ACE_Dev_Poll_Reactor::upcall (ACE_Event_Handler *event_handler,
170                               int (ACE_Event_Handler::*callback)(ACE_HANDLE),
171                               ACE_HANDLE handle)
173   // If the handler returns positive value (requesting a reactor
174   // callback) just call back as many times as the handler requests
175   // it.  Other threads are off handling other things.
176   int status = 0;
178   do
179     {
180       status = (event_handler->*callback) (handle);
181     }
182   while (status > 0);
184   return status;
188 /************************************************************************/
189 // Methods for ACE_Dev_Poll_Reactor::Token_Guard
190 /************************************************************************/
192 ACE_INLINE
193 ACE_Dev_Poll_Reactor::Token_Guard::Token_Guard (ACE_Dev_Poll_Reactor_Token &token)
195   : token_ (token),
196     owner_ (0)
200 ACE_INLINE
201 ACE_Dev_Poll_Reactor::Token_Guard::~Token_Guard (void)
203   if (this->owner_ == 1)
204     {
205       ACE_MT (this->token_.release ());
206       this->owner_ = 0;
207     }
210 ACE_INLINE void
211 ACE_Dev_Poll_Reactor::Token_Guard::release_token (void)
213   if (this->owner_)
214     {
215       ACE_MT (this->token_.release ());
217       // We are not the owner anymore..
218       this->owner_ = 0;
219     }
222 ACE_INLINE int
223 ACE_Dev_Poll_Reactor::Token_Guard::is_owner (void)
225   return this->owner_;
228 ACE_END_VERSIONED_NAMESPACE_DECL