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