]> code.delx.au - pulseaudio/blob - src/tests/rtpoll-test.c
Merge dead branch 'lockfree'
[pulseaudio] / src / tests / rtpoll-test.c
1 /***
2 This file is part of PulseAudio.
3
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2 of the License,
7 or (at your option) any later version.
8
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with PulseAudio; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 USA.
18 ***/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <signal.h>
25 #include <poll.h>
26
27 #include <pulsecore/log.h>
28 #include <pulsecore/rtpoll.h>
29 #include <pulsecore/rtsig.h>
30
31 static int before(pa_rtpoll_item *i) {
32 pa_log("before");
33 return 0;
34 }
35
36 static void after(pa_rtpoll_item *i) {
37 pa_log("after");
38 }
39
40 static int worker(pa_rtpoll_item *w) {
41 pa_log("worker");
42 return 0;
43 }
44
45 int main(int argc, char *argv[]) {
46 pa_rtpoll *p;
47 pa_rtpoll_item *i, *w;
48 struct pollfd *pollfd;
49
50 #ifdef SIGRTMIN
51 pa_rtsig_configure(SIGRTMIN+10, SIGRTMAX);
52 #endif
53
54 p = pa_rtpoll_new();
55
56 i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1);
57 pa_rtpoll_item_set_before_callback(i, before);
58 pa_rtpoll_item_set_after_callback(i, after);
59
60 pollfd = pa_rtpoll_item_get_pollfd(i, NULL);
61 pollfd->fd = 0;
62 pollfd->events = POLLIN;
63
64 w = pa_rtpoll_item_new(p, PA_RTPOLL_NORMAL, 0);
65 pa_rtpoll_item_set_before_callback(w, worker);
66
67 pa_rtpoll_install(p);
68 pa_rtpoll_set_timer_relative(p, 10000000); /* 10 s */
69
70 pa_rtpoll_run(p, 1);
71
72 pa_rtpoll_item_free(i);
73
74 i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1);
75 pa_rtpoll_item_set_before_callback(i, before);
76 pa_rtpoll_item_set_after_callback(i, after);
77
78 pollfd = pa_rtpoll_item_get_pollfd(i, NULL);
79 pollfd->fd = 0;
80 pollfd->events = POLLIN;
81
82 pa_rtpoll_run(p, 1);
83
84 pa_rtpoll_item_free(i);
85
86 pa_rtpoll_item_free(w);
87
88 pa_rtpoll_free(p);
89
90 return 0;
91 }