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
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 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 General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
25 #include <vlc_common.h>
39 static void callback (void *ptr
)
41 struct timer_data
*data
= ptr
;
43 vlc_mutex_lock (&data
->lock
);
44 data
->count
+= 1 + vlc_timer_getoverrun (data
->timer
);
45 vlc_mutex_unlock (&data
->lock
);
51 struct timer_data data
;
54 vlc_mutex_init (&data
.lock
);
57 val
= vlc_timer_create (&data
.timer
, callback
, &data
);
61 vlc_timer_schedule (data
.timer
, false, 1, CLOCK_FREQ
/ 10);
63 vlc_mutex_lock (&data
.lock
);
64 data
.count
+= vlc_timer_getoverrun (data
.timer
);
65 printf ("Count = %u\n", data
.count
);
66 assert (data
.count
>= 10);
68 vlc_mutex_unlock (&data
.lock
);
69 vlc_timer_schedule (data
.timer
, false, 0, 0);
72 mtime_t now
= mdate ();
74 vlc_timer_schedule (data
.timer
, true, now
, CLOCK_FREQ
/ 10);
76 vlc_mutex_lock (&data
.lock
);
77 data
.count
+= vlc_timer_getoverrun (data
.timer
);
78 printf ("Count = %u\n", data
.count
);
79 assert (data
.count
>= 10);
80 vlc_mutex_unlock (&data
.lock
);
82 vlc_timer_destroy (data
.timer
);
83 vlc_mutex_destroy (&data
.lock
);