1 /*****************************************************************************
2 * timer.c : Win32 timers for LibVLC
3 *****************************************************************************
4 * Copyright (C) 2009-2016 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 *****************************************************************************/
28 #include <vlc_common.h>
33 void (*func
) (void *);
37 static void CALLBACK
vlc_timer_do (void *val
, BOOLEAN timeout
)
39 struct vlc_timer
*timer
= val
;
42 timer
->func (timer
->data
);
45 int vlc_timer_create (vlc_timer_t
*id
, void (*func
) (void *), void *data
)
47 struct vlc_timer
*timer
= malloc (sizeof (*timer
));
53 timer
->handle
= INVALID_HANDLE_VALUE
;
58 void vlc_timer_destroy (vlc_timer_t timer
)
60 if (timer
->handle
!= INVALID_HANDLE_VALUE
)
61 DeleteTimerQueueTimer (NULL
, timer
->handle
, INVALID_HANDLE_VALUE
);
65 void vlc_timer_schedule (vlc_timer_t timer
, bool absolute
,
66 mtime_t value
, mtime_t interval
)
68 if (timer
->handle
!= INVALID_HANDLE_VALUE
)
70 DeleteTimerQueueTimer (NULL
, timer
->handle
, INVALID_HANDLE_VALUE
);
71 timer
->handle
= INVALID_HANDLE_VALUE
;
82 value
= (value
+ 999) / 1000;
83 interval
= (interval
+ 999) / 1000;
85 if (!CreateTimerQueueTimer (&timer
->handle
, NULL
, vlc_timer_do
, timer
,
86 value
, interval
, WT_EXECUTEDEFAULT
))
90 unsigned vlc_timer_getoverrun (vlc_timer_t timer
)