mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-04 15:14:22 +07:00
24 lines
960 B
C
24 lines
960 B
C
#pragma once
|
|
|
|
#include "arch.h"
|
|
|
|
struct mg_timer {
|
|
uint64_t period_ms; // Timer period in milliseconds
|
|
uint64_t prev_ms; // Timestamp of a previous poll
|
|
uint64_t expire; // Expiration timestamp in milliseconds
|
|
unsigned flags; // Possible flags values below
|
|
#define MG_TIMER_REPEAT 1 // Call function periodically, otherwise run once
|
|
#define MG_TIMER_RUN_NOW 2 // Call immediately when timer is set
|
|
void (*fn)(void *); // Function to call
|
|
void *arg; // Function argument
|
|
struct mg_timer *next; // Linkage in g_timers list
|
|
};
|
|
|
|
extern struct mg_timer *g_timers; // Global list of timers
|
|
|
|
void mg_timer_init(struct mg_timer **head, struct mg_timer *timer,
|
|
uint64_t milliseconds, unsigned flags, void (*fn)(void *),
|
|
void *arg);
|
|
void mg_timer_free(struct mg_timer **head, struct mg_timer *);
|
|
void mg_timer_poll(struct mg_timer **head, uint64_t new_ms);
|