margo-timer.h 1.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * (C) 2016 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#ifndef __MARGO_TIMER
#define __MARGO_TIMER

#ifdef __cplusplus
extern "C" {
#endif

typedef void (*margo_timer_cb_fn)(void *);

Shane Snyder's avatar
Shane Snyder committed
16
typedef struct margo_timed_element
17 18 19 20
{
    margo_timer_cb_fn cb_fn;
    void *cb_dat;
    double expiration;
Shane Snyder's avatar
Shane Snyder committed
21 22 23
    struct margo_timed_element *next;
    struct margo_timed_element *prev;
} margo_timer_t;
24

25
/**
Shane Snyder's avatar
Shane Snyder committed
26
 * Initializes the margo timer interface
27
 */
Shane Snyder's avatar
Shane Snyder committed
28
void margo_timer_sys_init(
29 30
    void);

31
/**
Shane Snyder's avatar
Shane Snyder committed
32
 * Shuts down the margo timer interface
33
 */
Shane Snyder's avatar
Shane Snyder committed
34
void margo_timer_sys_shutdown(
35 36
    void);

37
/**
Shane Snyder's avatar
Shane Snyder committed
38 39 40
 * Initializes a margo timer object which will perform some action
 * after a specified time duration
 * @param [in] timer pointer to margo timer object to be initialized
41 42 43 44
 * @param [in] cb_fn callback function for timeout action
 * @param [in] cb_dat callback data passed to the callback function
 * @param [in] timeout_ms timeout duration in milliseconds
 */
Shane Snyder's avatar
Shane Snyder committed
45 46
void margo_timer_init(
    margo_timer_t *timer,
47 48
    margo_timer_cb_fn cb_fn,
    void *cb_dat,
Shane Snyder's avatar
Shane Snyder committed
49
    double timeout_ms);
50 51

/**
Shane Snyder's avatar
Shane Snyder committed
52 53
 * Destroys a margo timer object which was previously initialized
 * @param [in] timer pointer to margo timer object to be destroyed
54
 */
Shane Snyder's avatar
Shane Snyder committed
55 56
void margo_timer_destroy(
    margo_timer_t *timer);
57

58 59 60
/**
 * Checks for expired timers and performs specified timeout action
 */
61 62 63 64 65 66 67 68 69
void margo_check_timers(
    void);


#ifdef __cplusplus
}
#endif

#endif /* __MARGO_TIMER */