1 /*****************************************************************************
2 * timer.c: Test for timer API
3 *****************************************************************************
4 * Copyright (C) 2009 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
30 #include <vlc_common.h>
41 static void callback (void *ptr
)
43 struct timer_data
*data
= ptr
;
45 vlc_mutex_lock (&data
->lock
);
46 data
->count
+= 1 + vlc_timer_getoverrun (data
->timer
);
47 vlc_cond_signal (&data
->wait
);
48 vlc_mutex_unlock (&data
->lock
);
54 struct timer_data data
;
58 vlc_mutex_init (&data
.lock
);
59 vlc_cond_init (&data
.wait
);
62 val
= vlc_timer_create (&data
.timer
, callback
, &data
);
64 vlc_timer_destroy (data
.timer
);
65 assert (data
.count
== 0);
67 val
= vlc_timer_create (&data
.timer
, callback
, &data
);
69 vlc_timer_schedule (data
.timer
, false, CLOCK_FREQ
<< 20, CLOCK_FREQ
);
70 vlc_timer_destroy (data
.timer
);
71 assert (data
.count
== 0);
73 val
= vlc_timer_create (&data
.timer
, callback
, &data
);
78 vlc_timer_schedule (data
.timer
, false, 1, CLOCK_FREQ
/ 100);
80 vlc_mutex_lock (&data
.lock
);
81 while (data
.count
<= 10)
82 vlc_cond_wait(&data
.wait
, &data
.lock
);
85 printf ("%u iterations in %"PRId64
" us\n", data
.count
, ts
);
87 vlc_mutex_unlock (&data
.lock
);
88 assert(ts
>= (CLOCK_FREQ
/ 10));
90 vlc_timer_schedule (data
.timer
, false, 0, 0);
95 vlc_timer_schedule (data
.timer
, true, ts
+ CLOCK_FREQ
/ 10,
98 vlc_mutex_lock (&data
.lock
);
99 while (data
.count
<= 10)
100 vlc_cond_wait(&data
.wait
, &data
.lock
);
103 printf ("%u iterations in %"PRId64
" us\n", data
.count
, ts
);
104 vlc_mutex_unlock (&data
.lock
);
105 assert(ts
>= (CLOCK_FREQ
/ 5));
107 vlc_timer_destroy (data
.timer
);
108 vlc_cond_destroy (&data
.wait
);
109 vlc_mutex_destroy (&data
.lock
);