You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
1.2 KiB
C

#ifndef RMUTIL_PERIODIC_H_
#define RMUTIL_PERIODIC_H_
#include <time.h>
#include <redismodule.h>
/** periodic.h - Utility periodic timer running a task repeatedly every given time interval */
/* RMUtilTimer - opaque context for the timer */
struct RMUtilTimer;
/* RMutilTimerFunc - callback type for timer tasks. The ctx is a thread-safe redis module context
* that should be locked/unlocked by the callback when running stuff against redis. privdata is
* pre-existing private data */
typedef void (*RMutilTimerFunc)(RedisModuleCtx *ctx, void *privdata);
/* Create and start a new periodic timer. Each timer has its own thread and can only be run and
* stopped once. The timer runs `cb` every `interval` with `privdata` passed to the callback. */
struct RMUtilTimer *RMUtil_NewPeriodicTimer(RMutilTimerFunc cb, void *privdata,
struct timespec interval);
/* Stop the timer loop. This should return immediately and join the thread */
int RMUtilTimer_Stop(struct RMUtilTimer *t);
/* Free the timer context. The caller should be responsible for freeing the private data at this
* point */
void RMUtilTimer_Free(struct RMUtilTimer *t);
#endif