148 {
149 if ( pthread_mutex_lock (&_mutex) != 0 )
150 return false;
151
152
153
154 if ( clientmutex ) pthread_mutex_unlock (clientmutex);
155
156
157
158 if ( _busy && !pthread_equal(_thread, pthread_self()) ) {
159
160 if ( !immediate ) {
161 if ( when != 0 )
162 pthread_cond_timedwait (&_cond, &_mutex, when);
163 else
164 pthread_cond_wait (&_cond, &_mutex);
165 }
166
167 } else {
168
169 _busy = true;
170 _thread = pthread_self();
171
172 struct timespec now;
174
175 if ( _timerQ->HasEvents () ) {
176
177 AsyncEvent *tevent;
178
179
180 while ( (tevent = _timerQ->First (now)) != 0 ) {
181 LOG_DEBUG (("timerQ event %p due", tevent));
182 _mainQ->Insert (tevent, 0);
183 }
184 }
185
186 _duetime = 0;
187
188 const struct timespec *nextdue = _timerQ->NextPrio();
189
190 if ( nextdue != 0 )
191 _duetime = nextdue;
192
193 if ( when != 0 ) {
195 _duetime = when;
196 }
197
198 LOG_DEBUG (("PollManager: events=%d",_mainQ->HasEvents()));
199
200 if ( _mainQ->HasEvents() ) {
201
202 AsyncEvent *event = _mainQ->First();
203
204 Receiver *rcvr = event ? event->GetReceiver() : 0;
205
206
207 if ( rcvr != 0 ) {
208
209
210
211
212
213 LOG_DEBUG (("Manager: queue %p", event));
214 rcvr->Queue (event);
215
216 pthread_mutex_unlock (&_mutex);
217
218 rcvr->Process ();
219
220 } else {
221
222 pthread_mutex_unlock (&_mutex);
223
224 LOG_DEBUG (("Manager: deliver %p", event));
225
226 event->Deliver();
227 }
228
229 if ( pthread_mutex_lock(&_mutex) != 0 ) {
230 return false;
231 }
232
233 } else if ( _duetime != 0 ) {
234
235 (void) pthread_cond_timedwait (&_cond, &_mutex, _duetime);
236 }
237
238 _busy = false;
239 }
240
241 bool retval = ( _mainQ->HasEvents() &&
242 *(_mainQ->NextPrio()) < (unsigned) MAXPRIO );
243
244
245 pthread_cond_broadcast (&_cond);
246
247 pthread_mutex_unlock (&_mutex);
248
249 if ( clientmutex ) pthread_mutex_lock (clientmutex);
250
251 return retval;
252 }
bool timespec_cmp(const struct timespec *time1, const struct timespec *time2)
Function for comparing two times.
void getNow(struct timespec &now)
Return the current time.