]> code.delx.au - pulseaudio/blob - src/polyp/mainloop.c
update doxygen docs
[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 #ifndef HAVE_PIPE
44 #include "../polypcore/pipe.h"
45 #endif
46
47 #include <polypcore/util.h>
48 #include <polypcore/idxset.h>
49 #include <polypcore/xmalloc.h>
50 #include <polypcore/log.h>
51
52 #include "mainloop.h"
53
54 struct pa_io_event {
55 pa_mainloop *mainloop;
56 int dead;
57 int fd;
58 pa_io_event_flags_t events;
59 void (*callback) (pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata);
60 struct pollfd *pollfd;
61 void *userdata;
62 void (*destroy_callback) (pa_mainloop_api*a, pa_io_event *e, void *userdata);
63 };
64
65 struct pa_time_event {
66 pa_mainloop *mainloop;
67 int dead;
68 int enabled;
69 struct timeval timeval;
70 void (*callback)(pa_mainloop_api*a, pa_time_event *e, const struct timeval*tv, void *userdata);
71 void *userdata;
72 void (*destroy_callback) (pa_mainloop_api*a, pa_time_event *e, void *userdata);
73 };
74
75 struct pa_defer_event {
76 pa_mainloop *mainloop;
77 int dead;
78 int enabled;
79 void (*callback)(pa_mainloop_api*a, pa_defer_event*e, void *userdata);
80 void *userdata;
81 void (*destroy_callback) (pa_mainloop_api*a, pa_defer_event *e, void *userdata);
82 };
83
84 struct pa_mainloop {
85 pa_idxset *io_events, *time_events, *defer_events;
86 int io_events_scan_dead, defer_events_scan_dead, time_events_scan_dead;
87
88 struct pollfd *pollfds;
89 unsigned max_pollfds, n_pollfds;
90 int rebuild_pollfds;
91
92 int prepared_timeout;
93
94 int quit, retval;
95 pa_mainloop_api api;
96
97 int deferred_pending;
98
99 int wakeup_pipe[2];
100
101 enum {
102 STATE_PASSIVE,
103 STATE_PREPARED,
104 STATE_POLLING,
105 STATE_POLLED,
106 STATE_QUIT
107 } state;
108
109 pa_poll_func poll_func;
110 void *poll_func_userdata;
111 };
112
113 /* IO events */
114 static pa_io_event* mainloop_io_new(
115 pa_mainloop_api*a,
116 int fd,
117 pa_io_event_flags_t events,
118 void (*callback) (pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata),
119 void *userdata) {
120
121 pa_mainloop *m;
122 pa_io_event *e;
123
124 assert(a && a->userdata && fd >= 0 && callback);
125 m = a->userdata;
126 assert(a == &m->api);
127
128 e = pa_xmalloc(sizeof(pa_io_event));
129 e->mainloop = m;
130 e->dead = 0;
131
132 e->fd = fd;
133 e->events = events;
134 e->callback = callback;
135 e->userdata = userdata;
136 e->destroy_callback = NULL;
137 e->pollfd = NULL;
138
139 #ifdef OS_IS_WIN32
140 {
141 fd_set xset;
142 struct timeval tv;
143
144 tv.tv_sec = 0;
145 tv.tv_usec = 0;
146
147 FD_ZERO (&xset);
148 FD_SET (fd, &xset);
149
150 if ((select((SELECT_TYPE_ARG1) fd, NULL, NULL, SELECT_TYPE_ARG234 &xset,
151 SELECT_TYPE_ARG5 &tv) == -1) &&
152 (WSAGetLastError() == WSAENOTSOCK)) {
153 pa_log_warn(__FILE__": WARNING: cannot monitor non-socket file descriptors.");
154 e->dead = 1;
155 }
156 }
157 #endif
158
159 pa_idxset_put(m->io_events, e, NULL);
160 m->rebuild_pollfds = 1;
161
162 pa_mainloop_wakeup(m);
163
164 return e;
165 }
166
167 static void mainloop_io_enable(pa_io_event *e, pa_io_event_flags_t events) {
168 assert(e && e->mainloop);
169
170 e->events = events;
171 e->mainloop->rebuild_pollfds = 1;
172
173 pa_mainloop_wakeup(e->mainloop);
174 }
175
176 static void mainloop_io_free(pa_io_event *e) {
177 assert(e && e->mainloop);
178
179 e->dead = e->mainloop->io_events_scan_dead = e->mainloop->rebuild_pollfds = 1;
180
181 pa_mainloop_wakeup(e->mainloop);
182 }
183
184 static void mainloop_io_set_destroy(pa_io_event *e, void (*callback)(pa_mainloop_api*a, pa_io_event *e, void *userdata)) {
185 assert(e);
186 e->destroy_callback = callback;
187 }
188
189 /* Defer events */
190 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) {
191 pa_mainloop *m;
192 pa_defer_event *e;
193
194 assert(a && a->userdata && callback);
195 m = a->userdata;
196 assert(a == &m->api);
197
198 e = pa_xmalloc(sizeof(pa_defer_event));
199 e->mainloop = m;
200 e->dead = 0;
201
202 e->enabled = 1;
203 e->callback = callback;
204 e->userdata = userdata;
205 e->destroy_callback = NULL;
206
207 pa_idxset_put(m->defer_events, e, NULL);
208
209 m->deferred_pending++;
210
211 pa_mainloop_wakeup(e->mainloop);
212
213 return e;
214 }
215
216 static void mainloop_defer_enable(pa_defer_event *e, int b) {
217 assert(e);
218
219 if (e->enabled && !b) {
220 assert(e->mainloop->deferred_pending > 0);
221 e->mainloop->deferred_pending--;
222 } else if (!e->enabled && b) {
223 e->mainloop->deferred_pending++;
224 pa_mainloop_wakeup(e->mainloop);
225 }
226
227 e->enabled = b;
228 }
229
230 static void mainloop_defer_free(pa_defer_event *e) {
231 assert(e);
232 e->dead = e->mainloop->defer_events_scan_dead = 1;
233
234 if (e->enabled) {
235 e->enabled = 0;
236 assert(e->mainloop->deferred_pending > 0);
237 e->mainloop->deferred_pending--;
238 }
239 }
240
241 static void mainloop_defer_set_destroy(pa_defer_event *e, void (*callback)(pa_mainloop_api*a, pa_defer_event *e, void *userdata)) {
242 assert(e);
243 e->destroy_callback = callback;
244 }
245
246 /* Time events */
247 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) {
248 pa_mainloop *m;
249 pa_time_event *e;
250
251 assert(a && a->userdata && callback);
252 m = a->userdata;
253 assert(a == &m->api);
254
255 e = pa_xmalloc(sizeof(pa_time_event));
256 e->mainloop = m;
257 e->dead = 0;
258
259 e->enabled = !!tv;
260 if (tv)
261 e->timeval = *tv;
262
263 e->callback = callback;
264 e->userdata = userdata;
265 e->destroy_callback = NULL;
266
267 pa_idxset_put(m->time_events, e, NULL);
268
269 if (e->enabled)
270 pa_mainloop_wakeup(m);
271
272 return e;
273 }
274
275 static void mainloop_time_restart(pa_time_event *e, const struct timeval *tv) {
276 assert(e);
277
278 if (tv) {
279 e->enabled = 1;
280 e->timeval = *tv;
281
282 pa_mainloop_wakeup(e->mainloop);
283 } else
284 e->enabled = 0;
285 }
286
287 static void mainloop_time_free(pa_time_event *e) {
288 assert(e);
289
290 e->dead = e->mainloop->time_events_scan_dead = 1;
291
292 /* no wakeup needed here. Think about it! */
293 }
294
295 static void mainloop_time_set_destroy(pa_time_event *e, void (*callback)(pa_mainloop_api*a, pa_time_event *e, void *userdata)) {
296 assert(e);
297 e->destroy_callback = callback;
298 }
299
300 /* quit() */
301
302 static void mainloop_quit(pa_mainloop_api*a, int retval) {
303 pa_mainloop *m;
304 assert(a && a->userdata);
305 m = a->userdata;
306 assert(a == &m->api);
307
308 pa_mainloop_quit(m, retval);
309 }
310
311 static const pa_mainloop_api vtable = {
312 .userdata = NULL,
313
314 .io_new= mainloop_io_new,
315 .io_enable= mainloop_io_enable,
316 .io_free= mainloop_io_free,
317 .io_set_destroy= mainloop_io_set_destroy,
318
319 .time_new = mainloop_time_new,
320 .time_restart = mainloop_time_restart,
321 .time_free = mainloop_time_free,
322 .time_set_destroy = mainloop_time_set_destroy,
323
324 .defer_new = mainloop_defer_new,
325 .defer_enable = mainloop_defer_enable,
326 .defer_free = mainloop_defer_free,
327 .defer_set_destroy = mainloop_defer_set_destroy,
328
329 .quit = mainloop_quit,
330 };
331
332 pa_mainloop *pa_mainloop_new(void) {
333 pa_mainloop *m;
334
335 m = pa_xmalloc(sizeof(pa_mainloop));
336
337 if (pipe(m->wakeup_pipe) < 0) {
338 pa_log_error(__FILE__": ERROR: cannot create wakeup pipe");
339 pa_xfree(m);
340 return NULL;
341 }
342
343 pa_make_nonblock_fd(m->wakeup_pipe[0]);
344 pa_make_nonblock_fd(m->wakeup_pipe[1]);
345
346 m->io_events = pa_idxset_new(NULL, NULL);
347 m->defer_events = pa_idxset_new(NULL, NULL);
348 m->time_events = pa_idxset_new(NULL, NULL);
349
350 assert(m->io_events && m->defer_events && m->time_events);
351
352 m->io_events_scan_dead = m->defer_events_scan_dead = m->time_events_scan_dead = 0;
353
354 m->pollfds = NULL;
355 m->max_pollfds = m->n_pollfds = 0;
356 m->rebuild_pollfds = 1;
357
358 m->quit = m->retval = 0;
359
360 m->api = vtable;
361 m->api.userdata = m;
362
363 m->deferred_pending = 0;
364
365 m->state = STATE_PASSIVE;
366
367 m->poll_func = NULL;
368 m->poll_func_userdata = NULL;
369
370 m->retval = -1;
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);
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 pa_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 (pa_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 retval) {
776 assert(m);
777
778 m->quit = 1;
779 m->retval = retval;
780 pa_mainloop_wakeup(m);
781 }
782
783 pa_mainloop_api* pa_mainloop_get_api(pa_mainloop*m) {
784 assert(m);
785 return &m->api;
786 }
787
788 void pa_mainloop_set_poll_func(pa_mainloop *m, pa_poll_func poll_func, void *userdata) {
789 assert(m);
790
791 m->poll_func = poll_func;
792 m->poll_func_userdata = userdata;
793 }
794
795
796 #if 0
797 void pa_mainloop_dump(pa_mainloop *m) {
798 assert(m);
799
800 pa_log(__FILE__": Dumping mainloop sources START");
801
802 {
803 uint32_t idx = PA_IDXSET_INVALID;
804 pa_io_event *e;
805 for (e = pa_idxset_first(m->io_events, &idx); e; e = pa_idxset_next(m->io_events, &idx)) {
806 if (e->dead)
807 continue;
808
809 pa_log(__FILE__": kind=io fd=%i events=%i callback=%p userdata=%p", e->fd, (int) e->events, (void*) e->callback, (void*) e->userdata);
810 }
811 }
812 {
813 uint32_t idx = PA_IDXSET_INVALID;
814 pa_defer_event *e;
815 for (e = pa_idxset_first(m->defer_events, &idx); e; e = pa_idxset_next(m->defer_events, &idx)) {
816 if (e->dead)
817 continue;
818
819 pa_log(__FILE__": kind=defer enabled=%i callback=%p userdata=%p", e->enabled, (void*) e->callback, (void*) e->userdata);
820 }
821 }
822 {
823 uint32_t idx = PA_IDXSET_INVALID;
824 pa_time_event *e;
825 for (e = pa_idxset_first(m->time_events, &idx); e; e = pa_idxset_next(m->time_events, &idx)) {
826 if (e->dead)
827 continue;
828
829 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);
830 }
831 }
832
833 pa_log(__FILE__": Dumping mainloop sources STOP");
834
835 }
836 #endif