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