]> code.delx.au - pulseaudio/blob - src/polyp/mainloop.c
* add pa_mainloop_wakeup() calls for deferred events
[pulseaudio] / src / polyp / mainloop.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
10
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <signal.h>
28 #include <unistd.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <assert.h>
32 #include <fcntl.h>
33 #include <errno.h>
34
35 #ifdef HAVE_SYS_POLL_H
36 #include <sys/poll.h>
37 #else
38 #include "../polypcore/poll.h"
39 #endif
40
41 #include "../polypcore/winsock.h"
42
43 #include <polypcore/util.h>
44 #include <polypcore/idxset.h>
45 #include <polypcore/xmalloc.h>
46 #include <polypcore/log.h>
47
48 #include "mainloop.h"
49
50 struct pa_io_event {
51 pa_mainloop *mainloop;
52 int dead;
53 int fd;
54 pa_io_event_flags_t events;
55 void (*callback) (pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata);
56 struct pollfd *pollfd;
57 void *userdata;
58 void (*destroy_callback) (pa_mainloop_api*a, pa_io_event *e, void *userdata);
59 };
60
61 struct pa_time_event {
62 pa_mainloop *mainloop;
63 int dead;
64 int enabled;
65 struct timeval timeval;
66 void (*callback)(pa_mainloop_api*a, pa_time_event *e, const struct timeval*tv, void *userdata);
67 void *userdata;
68 void (*destroy_callback) (pa_mainloop_api*a, pa_time_event *e, void *userdata);
69 };
70
71 struct pa_defer_event {
72 pa_mainloop *mainloop;
73 int dead;
74 int enabled;
75 void (*callback)(pa_mainloop_api*a, pa_defer_event*e, void *userdata);
76 void *userdata;
77 void (*destroy_callback) (pa_mainloop_api*a, pa_defer_event *e, void *userdata);
78 };
79
80 struct pa_mainloop {
81 pa_idxset *io_events, *time_events, *defer_events;
82 int io_events_scan_dead, defer_events_scan_dead, time_events_scan_dead;
83
84 struct pollfd *pollfds;
85 unsigned max_pollfds, n_pollfds;
86 int rebuild_pollfds;
87
88 int prepared_timeout;
89
90 int quit, retval;
91 pa_mainloop_api api;
92
93 int deferred_pending;
94
95 int wakeup_pipe[2];
96
97 enum {
98 STATE_PASSIVE,
99 STATE_PREPARED,
100 STATE_POLLING,
101 STATE_POLLED,
102 STATE_QUIT
103 } state;
104
105 pa_poll_func poll_func;
106 void *poll_func_userdata;
107 };
108
109 /* IO events */
110 static pa_io_event* mainloop_io_new(
111 pa_mainloop_api*a,
112 int fd,
113 pa_io_event_flags_t events,
114 void (*callback) (pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata),
115 void *userdata) {
116
117 pa_mainloop *m;
118 pa_io_event *e;
119
120 assert(a && a->userdata && fd >= 0 && callback);
121 m = a->userdata;
122 assert(a == &m->api);
123
124 e = pa_xmalloc(sizeof(pa_io_event));
125 e->mainloop = m;
126 e->dead = 0;
127
128 e->fd = fd;
129 e->events = events;
130 e->callback = callback;
131 e->userdata = userdata;
132 e->destroy_callback = NULL;
133 e->pollfd = NULL;
134
135 #ifdef OS_IS_WIN32
136 {
137 fd_set xset;
138 struct timeval tv;
139
140 tv.tv_sec = 0;
141 tv.tv_usec = 0;
142
143 FD_ZERO (&xset);
144 FD_SET (fd, &xset);
145
146 if ((select((SELECT_TYPE_ARG1) fd, NULL, NULL, SELECT_TYPE_ARG234 &xset,
147 SELECT_TYPE_ARG5 &tv) == -1) &&
148 (WSAGetLastError() == WSAENOTSOCK)) {
149 pa_log_warn(__FILE__": WARNING: cannot monitor non-socket file descriptors.");
150 e->dead = 1;
151 }
152 }
153 #endif
154
155 pa_idxset_put(m->io_events, e, NULL);
156 m->rebuild_pollfds = 1;
157
158 pa_mainloop_wakeup(m);
159
160 return e;
161 }
162
163 static void mainloop_io_enable(pa_io_event *e, pa_io_event_flags_t events) {
164 assert(e && e->mainloop);
165
166 e->events = events;
167 e->mainloop->rebuild_pollfds = 1;
168
169 pa_mainloop_wakeup(e->mainloop);
170 }
171
172 static void mainloop_io_free(pa_io_event *e) {
173 assert(e && e->mainloop);
174
175 e->dead = e->mainloop->io_events_scan_dead = e->mainloop->rebuild_pollfds = 1;
176
177 pa_mainloop_wakeup(e->mainloop);
178 }
179
180 static void mainloop_io_set_destroy(pa_io_event *e, void (*callback)(pa_mainloop_api*a, pa_io_event *e, void *userdata)) {
181 assert(e);
182 e->destroy_callback = callback;
183 }
184
185 /* Defer events */
186 static pa_defer_event* mainloop_defer_new(pa_mainloop_api*a, void (*callback) (pa_mainloop_api*a, pa_defer_event *e, void *userdata), void *userdata) {
187 pa_mainloop *m;
188 pa_defer_event *e;
189
190 assert(a && a->userdata && callback);
191 m = a->userdata;
192 assert(a == &m->api);
193
194 e = pa_xmalloc(sizeof(pa_defer_event));
195 e->mainloop = m;
196 e->dead = 0;
197
198 e->enabled = 1;
199 e->callback = callback;
200 e->userdata = userdata;
201 e->destroy_callback = NULL;
202
203 pa_idxset_put(m->defer_events, e, NULL);
204
205 m->deferred_pending++;
206
207 pa_mainloop_wakeup(e->mainloop);
208
209 return e;
210 }
211
212 static void mainloop_defer_enable(pa_defer_event *e, int b) {
213 assert(e);
214
215 if (e->enabled && !b) {
216 assert(e->mainloop->deferred_pending > 0);
217 e->mainloop->deferred_pending--;
218 } else if (!e->enabled && b) {
219 e->mainloop->deferred_pending++;
220 pa_mainloop_wakeup(e->mainloop);
221 }
222
223 e->enabled = b;
224 }
225
226 static void mainloop_defer_free(pa_defer_event *e) {
227 assert(e);
228 e->dead = e->mainloop->defer_events_scan_dead = 1;
229
230 if (e->enabled) {
231 e->enabled = 0;
232 assert(e->mainloop->deferred_pending > 0);
233 e->mainloop->deferred_pending--;
234 }
235 }
236
237 static void mainloop_defer_set_destroy(pa_defer_event *e, void (*callback)(pa_mainloop_api*a, pa_defer_event *e, void *userdata)) {
238 assert(e);
239 e->destroy_callback = callback;
240 }
241
242 /* Time events */
243 static pa_time_event* mainloop_time_new(pa_mainloop_api*a, const struct timeval *tv, void (*callback) (pa_mainloop_api*a, pa_time_event*e, const struct timeval *tv, void *userdata), void *userdata) {
244 pa_mainloop *m;
245 pa_time_event *e;
246
247 assert(a && a->userdata && callback);
248 m = a->userdata;
249 assert(a == &m->api);
250
251 e = pa_xmalloc(sizeof(pa_time_event));
252 e->mainloop = m;
253 e->dead = 0;
254
255 e->enabled = !!tv;
256 if (tv)
257 e->timeval = *tv;
258
259 e->callback = callback;
260 e->userdata = userdata;
261 e->destroy_callback = NULL;
262
263 pa_idxset_put(m->time_events, e, NULL);
264
265 if (e->enabled)
266 pa_mainloop_wakeup(m);
267
268 return e;
269 }
270
271 static void mainloop_time_restart(pa_time_event *e, const struct timeval *tv) {
272 assert(e);
273
274 if (tv) {
275 e->enabled = 1;
276 e->timeval = *tv;
277
278 pa_mainloop_wakeup(e->mainloop);
279 } else
280 e->enabled = 0;
281 }
282
283 static void mainloop_time_free(pa_time_event *e) {
284 assert(e);
285
286 e->dead = e->mainloop->time_events_scan_dead = 1;
287
288 /* no wakeup needed here. Think about it! */
289 }
290
291 static void mainloop_time_set_destroy(pa_time_event *e, void (*callback)(pa_mainloop_api*a, pa_time_event *e, void *userdata)) {
292 assert(e);
293 e->destroy_callback = callback;
294 }
295
296 /* quit() */
297
298 static void mainloop_quit(pa_mainloop_api*a, int retval) {
299 pa_mainloop *m;
300 assert(a && a->userdata);
301 m = a->userdata;
302 assert(a == &m->api);
303
304 m->quit = 1;
305 m->retval = retval;
306
307 pa_mainloop_wakeup(m);
308 }
309
310 static const pa_mainloop_api vtable = {
311 .userdata = NULL,
312
313 .io_new= mainloop_io_new,
314 .io_enable= mainloop_io_enable,
315 .io_free= mainloop_io_free,
316 .io_set_destroy= mainloop_io_set_destroy,
317
318 .time_new = mainloop_time_new,
319 .time_restart = mainloop_time_restart,
320 .time_free = mainloop_time_free,
321 .time_set_destroy = mainloop_time_set_destroy,
322
323 .defer_new = mainloop_defer_new,
324 .defer_enable = mainloop_defer_enable,
325 .defer_free = mainloop_defer_free,
326 .defer_set_destroy = mainloop_defer_set_destroy,
327
328 .quit = mainloop_quit,
329 };
330
331 pa_mainloop *pa_mainloop_new(void) {
332 pa_mainloop *m;
333
334 m = pa_xmalloc(sizeof(pa_mainloop));
335
336 #ifndef OS_IS_WIN32
337 if (pipe(m->wakeup_pipe) < 0) {
338 pa_xfree(m);
339 return NULL;
340 }
341
342 pa_make_nonblock_fd(m->wakeup_pipe[0]);
343 pa_make_nonblock_fd(m->wakeup_pipe[1]);
344 #else
345 m->wakeup_pipe[0] = -1;
346 m->wakeup_pipe[1] = -1;
347 #endif
348
349 m->io_events = pa_idxset_new(NULL, NULL);
350 m->defer_events = pa_idxset_new(NULL, NULL);
351 m->time_events = pa_idxset_new(NULL, NULL);
352
353 assert(m->io_events && m->defer_events && m->time_events);
354
355 m->io_events_scan_dead = m->defer_events_scan_dead = m->time_events_scan_dead = 0;
356
357 m->pollfds = NULL;
358 m->max_pollfds = m->n_pollfds = m->rebuild_pollfds = 0;
359
360 m->quit = m->retval = 0;
361
362 m->api = vtable;
363 m->api.userdata = m;
364
365 m->deferred_pending = 0;
366
367 m->state = STATE_PASSIVE;
368
369 m->poll_func = NULL;
370 m->poll_func_userdata = NULL;
371
372 return m;
373 }
374
375 static int io_foreach(void *p, uint32_t PA_GCC_UNUSED idx, int *del, void*userdata) {
376 pa_io_event *e = p;
377 int *all = userdata;
378 assert(e && del && all);
379
380 if (!*all && !e->dead)
381 return 0;
382
383 if (e->destroy_callback)
384 e->destroy_callback(&e->mainloop->api, e, e->userdata);
385 pa_xfree(e);
386 *del = 1;
387 return 0;
388 }
389
390 static int time_foreach(void *p, uint32_t PA_GCC_UNUSED idx, int *del, void*userdata) {
391 pa_time_event *e = p;
392 int *all = userdata;
393 assert(e && del && all);
394
395 if (!*all && !e->dead)
396 return 0;
397
398 if (e->destroy_callback)
399 e->destroy_callback(&e->mainloop->api, e, e->userdata);
400 pa_xfree(e);
401 *del = 1;
402 return 0;
403 }
404
405 static int defer_foreach(void *p, PA_GCC_UNUSED uint32_t idx, int *del, void*userdata) {
406 pa_defer_event *e = p;
407 int *all = userdata;
408 assert(e && del && all);
409
410 if (!*all && !e->dead)
411 return 0;
412
413 if (e->destroy_callback)
414 e->destroy_callback(&e->mainloop->api, e, e->userdata);
415 pa_xfree(e);
416 *del = 1;
417 return 0;
418 }
419
420 void pa_mainloop_free(pa_mainloop* m) {
421 int all = 1;
422 assert(m && (m->state != STATE_POLLING));
423
424 pa_idxset_foreach(m->io_events, io_foreach, &all);
425 pa_idxset_foreach(m->time_events, time_foreach, &all);
426 pa_idxset_foreach(m->defer_events, defer_foreach, &all);
427
428 pa_idxset_free(m->io_events, NULL, NULL);
429 pa_idxset_free(m->time_events, NULL, NULL);
430 pa_idxset_free(m->defer_events, NULL, NULL);
431
432 pa_xfree(m->pollfds);
433
434 if (m->wakeup_pipe[0] >= 0)
435 close(m->wakeup_pipe[0]);
436 if (m->wakeup_pipe[1] >= 0)
437 close(m->wakeup_pipe[1]);
438
439 pa_xfree(m);
440 }
441
442 static void scan_dead(pa_mainloop *m) {
443 int all = 0;
444 assert(m);
445
446 if (m->io_events_scan_dead)
447 pa_idxset_foreach(m->io_events, io_foreach, &all);
448 if (m->time_events_scan_dead)
449 pa_idxset_foreach(m->time_events, time_foreach, &all);
450 if (m->defer_events_scan_dead)
451 pa_idxset_foreach(m->defer_events, defer_foreach, &all);
452
453 m->io_events_scan_dead = m->time_events_scan_dead = m->defer_events_scan_dead = 0;
454 }
455
456 static void rebuild_pollfds(pa_mainloop *m) {
457 pa_io_event*e;
458 struct pollfd *p;
459 uint32_t idx = PA_IDXSET_INVALID;
460 unsigned l;
461
462 l = pa_idxset_size(m->io_events) + 1;
463 if (m->max_pollfds < l) {
464 m->pollfds = pa_xrealloc(m->pollfds, sizeof(struct pollfd)*l);
465 m->max_pollfds = l;
466 }
467
468 m->n_pollfds = 0;
469 p = m->pollfds;
470
471 if (m->wakeup_pipe[0] >= 0) {
472 m->pollfds[0].fd = m->wakeup_pipe[0];
473 m->pollfds[0].events = POLLIN;
474 m->pollfds[0].revents = 0;
475 p++;
476 m->n_pollfds++;
477 }
478
479 for (e = pa_idxset_first(m->io_events, &idx); e; e = pa_idxset_next(m->io_events, &idx)) {
480 if (e->dead) {
481 e->pollfd = NULL;
482 continue;
483 }
484
485 e->pollfd = p;
486 p->fd = e->fd;
487 p->events =
488 ((e->events & PA_IO_EVENT_INPUT) ? POLLIN : 0) |
489 ((e->events & PA_IO_EVENT_OUTPUT) ? POLLOUT : 0) |
490 POLLHUP |
491 POLLERR;
492 p->revents = 0;
493
494 p++;
495 m->n_pollfds++;
496 }
497
498 m->rebuild_pollfds = 0;
499 }
500
501 static int dispatch_pollfds(pa_mainloop *m) {
502 uint32_t idx = PA_IDXSET_INVALID;
503 pa_io_event *e;
504 int r = 0;
505
506 for (e = pa_idxset_first(m->io_events, &idx); e && !m->quit; e = pa_idxset_next(m->io_events, &idx)) {
507 if (e->dead || !e->pollfd || !e->pollfd->revents)
508 continue;
509
510 assert(e->pollfd->fd == e->fd && e->callback);
511 e->callback(&m->api, e, e->fd,
512 (e->pollfd->revents & POLLHUP ? PA_IO_EVENT_HANGUP : 0) |
513 (e->pollfd->revents & POLLIN ? PA_IO_EVENT_INPUT : 0) |
514 (e->pollfd->revents & POLLOUT ? PA_IO_EVENT_OUTPUT : 0) |
515 (e->pollfd->revents & POLLERR ? PA_IO_EVENT_ERROR : 0),
516 e->userdata);
517 e->pollfd->revents = 0;
518 r++;
519 }
520
521 return r;
522 }
523
524 static int dispatch_defer(pa_mainloop *m) {
525 uint32_t idx;
526 pa_defer_event *e;
527 int r = 0;
528
529 if (!m->deferred_pending)
530 return 0;
531
532 for (e = pa_idxset_first(m->defer_events, &idx); e && !m->quit; e = pa_idxset_next(m->defer_events, &idx)) {
533 if (e->dead || !e->enabled)
534 continue;
535
536 assert(e->callback);
537 e->callback(&m->api, e, e->userdata);
538 r++;
539 }
540
541 return r;
542 }
543
544 static int calc_next_timeout(pa_mainloop *m) {
545 uint32_t idx;
546 pa_time_event *e;
547 struct timeval now;
548 int t = -1;
549 int got_time = 0;
550
551 if (pa_idxset_isempty(m->time_events))
552 return -1;
553
554 for (e = pa_idxset_first(m->time_events, &idx); e; e = pa_idxset_next(m->time_events, &idx)) {
555 int tmp;
556
557 if (e->dead || !e->enabled)
558 continue;
559
560 /* Let's save a system call */
561 if (!got_time) {
562 pa_gettimeofday(&now);
563 got_time = 1;
564 }
565
566 if (e->timeval.tv_sec < now.tv_sec || (e->timeval.tv_sec == now.tv_sec && e->timeval.tv_usec <= now.tv_usec))
567 return 0;
568
569 tmp = (e->timeval.tv_sec - now.tv_sec)*1000;
570
571 if (e->timeval.tv_usec > now.tv_usec)
572 tmp += (e->timeval.tv_usec - now.tv_usec)/1000;
573 else
574 tmp -= (now.tv_usec - e->timeval.tv_usec)/1000;
575
576 if (tmp == 0)
577 return 0;
578 else if (t == -1 || tmp < t)
579 t = tmp;
580 }
581
582 return t;
583 }
584
585 static int dispatch_timeout(pa_mainloop *m) {
586 uint32_t idx;
587 pa_time_event *e;
588 struct timeval now;
589 int got_time = 0;
590 int r = 0;
591 assert(m);
592
593 if (pa_idxset_isempty(m->time_events))
594 return 0;
595
596 for (e = pa_idxset_first(m->time_events, &idx); e && !m->quit; e = pa_idxset_next(m->time_events, &idx)) {
597
598 if (e->dead || !e->enabled)
599 continue;
600
601 /* Let's save a system call */
602 if (!got_time) {
603 pa_gettimeofday(&now);
604 got_time = 1;
605 }
606
607 if (e->timeval.tv_sec < now.tv_sec || (e->timeval.tv_sec == now.tv_sec && e->timeval.tv_usec <= now.tv_usec)) {
608 assert(e->callback);
609
610 e->enabled = 0;
611 e->callback(&m->api, e, &e->timeval, e->userdata);
612
613 r++;
614 }
615 }
616
617 return r;
618 }
619
620 void pa_mainloop_wakeup(pa_mainloop *m) {
621 char c = 'W';
622 assert(m);
623
624 if (m->wakeup_pipe[1] >= 0)
625 write(m->wakeup_pipe[1], &c, sizeof(c));
626 }
627
628 static void clear_wakeup(pa_mainloop *m) {
629 char c[10];
630
631 assert(m);
632
633 if (m->wakeup_pipe[0] < 0)
634 return;
635
636 while (read(m->wakeup_pipe[0], &c, sizeof(c)) == sizeof(c));
637 }
638
639 int pa_mainloop_prepare(pa_mainloop *m, int timeout) {
640 assert(m);
641 assert(m->state == STATE_PASSIVE);
642
643 clear_wakeup(m);
644 scan_dead(m);
645
646 if (m->quit)
647 goto quit;
648
649 if (!m->deferred_pending) {
650
651 if (m->rebuild_pollfds)
652 rebuild_pollfds(m);
653
654 m->prepared_timeout = calc_next_timeout(m);
655 if (timeout >= 0 && (timeout < m->prepared_timeout || m->prepared_timeout < 0))
656 m->prepared_timeout = timeout;
657 }
658
659 m->state = STATE_PREPARED;
660 return 0;
661
662 quit:
663 m->state = STATE_QUIT;
664 return -2;
665 }
666
667 int pa_mainloop_poll(pa_mainloop *m) {
668 int r;
669
670 assert(m);
671 assert(m->state == STATE_PREPARED);
672
673 if (m->quit)
674 goto quit;
675
676 m->state = STATE_POLLING;
677
678 if (m->deferred_pending)
679 r = 0;
680 else {
681 if (m->poll_func)
682 r = m->poll_func(m->pollfds, m->n_pollfds, m->prepared_timeout, m->poll_func_userdata);
683 else
684 r = poll(m->pollfds, m->n_pollfds, m->prepared_timeout);
685
686 if (r < 0) {
687 if (errno == EINTR)
688 r = 0;
689 else
690 pa_log(__FILE__": poll(): %s", strerror(errno));
691 }
692 }
693
694 m->state = r < 0 ? STATE_PASSIVE : STATE_POLLED;
695 return r;
696
697 quit:
698 m->state = STATE_QUIT;
699 return -2;
700 }
701
702 int pa_mainloop_dispatch(pa_mainloop *m) {
703 int dispatched = 0;
704
705 assert(m);
706 assert(m->state == STATE_POLLED);
707
708 if (m->quit)
709 goto quit;
710
711 if (m->deferred_pending)
712 dispatched += dispatch_defer(m);
713 else {
714 dispatched += dispatch_timeout(m);
715
716 if (m->quit)
717 goto quit;
718
719 dispatched += dispatch_pollfds(m);
720
721 }
722
723 if (m->quit)
724 goto quit;
725
726 m->state = STATE_PASSIVE;
727
728 return dispatched;
729
730 quit:
731 m->state = STATE_QUIT;
732 return -2;
733 }
734
735 int pa_mainloop_get_retval(pa_mainloop *m) {
736 assert(m);
737 return m->retval;
738 }
739
740 int pa_mainloop_iterate(pa_mainloop *m, int block, int *retval) {
741 int r;
742 assert(m);
743
744 if ((r = pa_mainloop_prepare(m, block ? -1 : 0)) < 0)
745 goto quit;
746
747 if ((r = pa_mainloop_poll(m)) < 0)
748 goto quit;
749
750 if ((r = pa_mainloop_dispatch(m)) < 0)
751 goto quit;
752
753 return r;
754
755 quit:
756
757 if ((r == -2) && retval)
758 *retval = pa_mainloop_get_retval(m);
759 return r;
760 }
761
762 int pa_mainloop_run(pa_mainloop *m, int *retval) {
763 int r;
764
765 while ((r = pa_mainloop_iterate(m, 1, retval)) >= 0);
766
767 if (r == -2)
768 return 1;
769 else if (r < 0)
770 return -1;
771 else
772 return 0;
773 }
774
775 void pa_mainloop_quit(pa_mainloop *m, int r) {
776 assert(m);
777 pa_mainloop_wakeup(m);
778 m->quit = r;
779 }
780
781 pa_mainloop_api* pa_mainloop_get_api(pa_mainloop*m) {
782 assert(m);
783 return &m->api;
784 }
785
786 void pa_mainloop_set_poll_func(pa_mainloop *m, pa_poll_func poll_func, void *userdata) {
787 assert(m);
788
789 m->poll_func = poll_func;
790 m->poll_func_userdata = userdata;
791 }
792
793
794 #if 0
795 void pa_mainloop_dump(pa_mainloop *m) {
796 assert(m);
797
798 pa_log(__FILE__": Dumping mainloop sources START");
799
800 {
801 uint32_t idx = PA_IDXSET_INVALID;
802 pa_io_event *e;
803 for (e = pa_idxset_first(m->io_events, &idx); e; e = pa_idxset_next(m->io_events, &idx)) {
804 if (e->dead)
805 continue;
806
807 pa_log(__FILE__": kind=io fd=%i events=%i callback=%p userdata=%p", e->fd, (int) e->events, (void*) e->callback, (void*) e->userdata);
808 }
809 }
810 {
811 uint32_t idx = PA_IDXSET_INVALID;
812 pa_defer_event *e;
813 for (e = pa_idxset_first(m->defer_events, &idx); e; e = pa_idxset_next(m->defer_events, &idx)) {
814 if (e->dead)
815 continue;
816
817 pa_log(__FILE__": kind=defer enabled=%i callback=%p userdata=%p", e->enabled, (void*) e->callback, (void*) e->userdata);
818 }
819 }
820 {
821 uint32_t idx = PA_IDXSET_INVALID;
822 pa_time_event *e;
823 for (e = pa_idxset_first(m->time_events, &idx); e; e = pa_idxset_next(m->time_events, &idx)) {
824 if (e->dead)
825 continue;
826
827 pa_log(__FILE__": kind=time enabled=%i time=%lu.%lu callback=%p userdata=%p", e->enabled, (unsigned long) e->timeval.tv_sec, (unsigned long) e->timeval.tv_usec, (void*) e->callback, (void*) e->userdata);
828 }
829 }
830
831 pa_log(__FILE__": Dumping mainloop sources STOP");
832
833 }
834 #endif