]>
code.delx.au - pulseaudio/blob - src/tests/thread-mainloop-test.c
2 This file is part of PulseAudio.
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.
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.
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
28 #include <pulse/timeval.h>
29 #include <pulse/util.h>
30 #include <pulse/thread-mainloop.h>
31 #include <pulse/gccmacro.h>
33 #include <pulsecore/macro.h>
35 static void tcb(pa_mainloop_api
*a
, pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
36 pa_assert_se(pa_threaded_mainloop_in_thread(userdata
));
37 fprintf(stderr
, "TIME EVENT START\n");
38 pa_threaded_mainloop_signal(userdata
, 1);
39 fprintf(stderr
, "TIME EVENT END\n");
42 int main(PA_GCC_UNUSED
int argc
, PA_GCC_UNUSED
char *argv
[]) {
44 pa_threaded_mainloop
*m
;
47 pa_assert_se(m
= pa_threaded_mainloop_new());
48 pa_assert_se(a
= pa_threaded_mainloop_get_api(m
));
50 pa_threaded_mainloop_start(m
);
52 pa_threaded_mainloop_lock(m
);
54 pa_assert_se(!pa_threaded_mainloop_in_thread(m
));
58 a
->time_new(a
, &tv
, tcb
, m
);
60 fprintf(stderr
, "waiting 5s (signal)\n");
61 pa_threaded_mainloop_wait(m
);
62 fprintf(stderr
, "wait completed\n");
63 pa_threaded_mainloop_accept(m
);
64 fprintf(stderr
, "signal accepted\n");
66 pa_threaded_mainloop_unlock(m
);
68 fprintf(stderr
, "waiting 5s (sleep)\n");
71 fprintf(stderr
, "shutting down\n");
73 pa_threaded_mainloop_stop(m
);
75 pa_threaded_mainloop_free(m
);