• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #ifndef CRAS_TM_H_
7 #define CRAS_TM_H_
8 
9 /* cras_timer provides an interface to register a function to be called at a
10  * later time.  This interface should be used from the main thread only, it is
11  * not thread safe.
12  */
13 
14 struct cras_tm; /* timer manager */
15 struct cras_timer;
16 
17 /* Creates a timer.  Must later be removed with cras_rm_cancel_timer.
18  * Args:
19  *    tm - Timer manager.
20  *    ms - Call 'cb' in ms milliseconds.
21  *    cb - The callback to call at timeout.
22  *    cb_data - Passed to the callback when it is run.
23  * Returns:
24  *    Pointer to a newly allocated timer, passed timer to cras_tm_cancel_timer
25  *    to cancel before it fires.
26  */
27 struct cras_timer *cras_tm_create_timer(
28 		struct cras_tm *tm,
29 		unsigned int ms,
30 		void (*cb)(struct cras_timer *t, void *data),
31 		void *cb_data);
32 
33 /* Deletes a timer returned from cras_tm_create_timer. */
34 void cras_tm_cancel_timer(struct cras_tm *tm, struct cras_timer *t);
35 
36 /* Interface for system to create the timer manager. */
37 struct cras_tm *cras_tm_init();
38 
39 /* Interface for system to destroy the timer manager. */
40 void cras_tm_deinit(struct cras_tm *tm);
41 
42 /* Get the amount of time before the next timer expires. ts is set to an
43  * the amount of time before the next timer expires (0 if already past due).
44  * Args:
45  *    tm - Timer manager.
46  *    ts - Filled with time before next event.
47  * Returns:
48  *    0 if no timers are active, 1 if they are.
49  */
50 int cras_tm_get_next_timeout(const struct cras_tm *tm, struct timespec *ts);
51 
52 /* Calls any expired timers. */
53 void cras_tm_call_callbacks(struct cras_tm *tm);
54 
55 #endif /* CRAS_TM_H_ */
56