summaryrefslogtreecommitdiff
path: root/include/uvcgadget/timer.h
blob: de93287c61af10fe57ca273604c0003f4e70fd98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * libuvcgadget timer utils
 *
 * Copyright (C) 2022 Daniel Scally
 *
 * Contact: Daniel Scally <dan.scally@ideasonboard.com>
 */

struct timer;

/*
 * timer_new - Create a new timer
 *
 * Allocates and returns a new struct timer. This must be configured with
 * timer_set_fps() and then armed with timer_arm(), following which calls to
 * timer_wait() will block until the expiration of a period as defined by
 * timer_set_fps().
 *
 * Timers allocated with this function should be removed with timer_destroy()
 */
struct timer *timer_new(void);

/*
 * timer_set_fps - Configure the timer's wait period
 *
 * Configure the timer to wait for a period of time such that expirations per
 * second matches @fps
 */
void timer_set_fps(struct timer *timer, int fps);

/*
 * timer_arm
 *
 * Arms the timer such that calls to timer_wait() become blocking until the
 * expiration of a period.
 */
int timer_arm(struct timer *timer);

/*
 * timer_disarm
 *
 * Disarms the timer such that calls to timer_wait() return without blocking.
 */
int timer_disarm(struct timer *timer);

/*
 * timer_wait
 *
 * If the timer is armed, block until the expiration of a period
 */
void timer_wait(struct timer *timer);

/*
 * timer_destroy
 *
 * Close the timer's file descriptor and free the memory
 */
void timer_destroy(struct timer *timer);