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 vlc_tick_t value
, vlc_tick_t interval
)
68 if (timer
->handle
!= INVALID_HANDLE_VALUE
)
70 DeleteTimerQueueTimer (NULL
, timer
->handle
, INVALID_HANDLE_VALUE
);
71 timer
->handle
= INVALID_HANDLE_VALUE
;
73 if (value
== VLC_TIMER_DISARM
)
78 value
-= vlc_tick_now ();
83 DWORD val
= MS_FROM_VLC_TICK(value
);
84 DWORD interv
= MS_FROM_VLC_TICK(interval
);
85 if (val
== 0 && value
!= 0)
86 val
= 1; /* rounding error */
87 if (interv
== 0 && interval
!= 0)
88 interv
= 1; /* rounding error */
90 if (!CreateTimerQueueTimer(&timer
->handle
, NULL
, vlc_timer_do
, timer
,
91 val
, interv
, WT_EXECUTEDEFAULT
))
95 unsigned vlc_timer_getoverrun (vlc_timer_t timer
)