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>
33 const char vlc_module_name
[] = "test_timer";
43 static void callback (void *ptr
)
45 struct timer_data
*data
= ptr
;
47 vlc_mutex_lock (&data
->lock
);
48 data
->count
+= 1 + vlc_timer_getoverrun (data
->timer
);
49 vlc_cond_signal (&data
->wait
);
50 vlc_mutex_unlock (&data
->lock
);
56 struct timer_data data
;
60 vlc_mutex_init (&data
.lock
);
61 vlc_cond_init (&data
.wait
);
64 val
= vlc_timer_create (&data
.timer
, callback
, &data
);
66 vlc_timer_destroy (data
.timer
);
67 assert (data
.count
== 0);
69 val
= vlc_timer_create (&data
.timer
, callback
, &data
);
71 vlc_timer_schedule (data
.timer
, false, CLOCK_FREQ
<< 20, CLOCK_FREQ
);
72 vlc_timer_destroy (data
.timer
);
73 assert (data
.count
== 0);
75 val
= vlc_timer_create (&data
.timer
, callback
, &data
);
80 vlc_timer_schedule (data
.timer
, false, 1, VLC_TICK_FROM_MS(10));
82 vlc_mutex_lock (&data
.lock
);
83 while (data
.count
<= 10)
84 vlc_cond_wait(&data
.wait
, &data
.lock
);
86 ts
= vlc_tick_now () - ts
;
87 printf ("%u iterations in %"PRId64
" us\n", data
.count
, ts
);
89 vlc_mutex_unlock (&data
.lock
);
90 assert(ts
>= VLC_TICK_FROM_MS(100));
92 vlc_timer_disarm (data
.timer
);
97 vlc_timer_schedule (data
.timer
, true, ts
+ VLC_TICK_FROM_MS(100),
98 VLC_TICK_FROM_MS(10));
100 vlc_mutex_lock (&data
.lock
);
101 while (data
.count
<= 10)
102 vlc_cond_wait(&data
.wait
, &data
.lock
);
104 ts
= vlc_tick_now () - ts
;
105 printf ("%u iterations in %"PRId64
" us\n", data
.count
, ts
);
106 vlc_mutex_unlock (&data
.lock
);
107 assert(ts
>= VLC_TICK_FROM_MS(200));
109 vlc_timer_destroy (data
.timer
);