TwiceAsNice  2019-02-18
Classes | Macros | Functions | Variables
eventloop.c File Reference
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include "eventloop.h"
Include dependency graph for eventloop.c:

Classes

struct  CB
 
struct  TF
 
struct  WP
 

Macros

#define EPOCHDT(tp)   /* ms from epoch to timeval *tp */ (((tp)->tv_usec) / 1000.0 + ((tp)->tv_sec) * 1000.0)
 

Functions

static void runWorkProc (void)
 
static void callCallback (fd_set *rfdp)
 
static void checkTimer ()
 
static void oneLoop (void)
 
static void deferTO (void *p)
 
void eventLoop ()
 Main calls this when ready to hand over control. More...
 
int deferLoop (int maxms, int *flagp)
 
int deferLoop0 (int maxms, int *flagp)
 
int addCallback (int fd, CBF *fp, void *ud)
 Register a new callback, fp, to be called with ud as argument when fd is ready. More...
 
void rmCallback (int cid)
 Remove a callback function. More...
 
int addTimer (int ms, TCF *fp, void *ud)
 Register a new timer function, fp, to be called with ud as argument after ms. More...
 
void rmTimer (int timer_id)
 Remove the timer with the given id, as returned from addTimer(). More...
 
int addWorkProc (WPF *fp, void *ud)
 Add a new work procedure, fp, to be called with ud when nothing else to do. More...
 
void rmWorkProc (int wid)
 Remove the work procedure with the given id, as returned from addWorkProc(). More...
 

Variables

static CBcback
 
static int ncback
 
static int ncbinuse
 
static int lastcb
 
static TFtimef
 
static int ntimef
 
static int tid
 
static WPwproc
 
static int nwproc
 
static int nwpinuse
 
static int lastwp
 

Macro Definition Documentation

◆ EPOCHDT

#define EPOCHDT (   tp)    /* ms from epoch to timeval *tp */ (((tp)->tv_usec) / 1000.0 + ((tp)->tv_sec) * 1000.0)

Function Documentation

◆ addCallback()

int addCallback ( int  fd,
CBF fp,
void *  ud 
)

Register a new callback, fp, to be called with ud as argument when fd is ready.

Parameters
fdfile descriptor.
fpa pointer to the callback function.
uda pointer to be passed to the callback function when called.
Returns
a unique callback id for use with rmCallback().

◆ addTimer()

int addTimer ( int  ms,
TCF fp,
void *  ud 
)

Register a new timer function, fp, to be called with ud as argument after ms.

Add to list in order of decreasing time from epoch, ie, last entry runs soonest. The timer will only invoke the callback function once. You need to call addTimer again if you want to repeat the process.

Parameters
mstimer period in milliseconds.
fpa pointer to the callback function.
uda pointer to be passed to the callback function when called.
Returns
a unique id for use with rmTimer().

◆ addWorkProc()

int addWorkProc ( WPF fp,
void *  ud 
)

Add a new work procedure, fp, to be called with ud when nothing else to do.

Parameters
fpa pointer to the work procedure callback function.
uda pointer to be passed to the callback function when called.
Returns
a unique id for use with rmWorkProc().

◆ callCallback()

static void callCallback ( fd_set *  rfdp)
static

◆ checkTimer()

static void checkTimer ( )
static

◆ deferLoop()

int deferLoop ( int  maxms,
int *  flagp 
)

◆ deferLoop0()

int deferLoop0 ( int  maxms,
int *  flagp 
)

◆ deferTO()

static void deferTO ( void *  p)
static

◆ eventLoop()

void eventLoop ( )

Main calls this when ready to hand over control.

◆ oneLoop()

static void oneLoop ( void  )
static

◆ rmCallback()

void rmCallback ( int  cid)

Remove a callback function.

Parameters
cidthe callback ID returned from addCallback().

◆ rmTimer()

void rmTimer ( int  tid)

Remove the timer with the given id, as returned from addTimer().

Parameters
tidthe timer callback ID returned from addTimer().

◆ rmWorkProc()

void rmWorkProc ( int  wid)

Remove the work procedure with the given id, as returned from addWorkProc().

Parameters
widthe work procedure callback ID returned from addWorkProc().

◆ runWorkProc()

static void runWorkProc ( void  )
static

Variable Documentation

◆ cback

CB* cback
static

◆ lastcb

int lastcb
static

◆ lastwp

int lastwp
static

◆ ncback

int ncback
static

◆ ncbinuse

int ncbinuse
static

◆ ntimef

int ntimef
static

◆ nwpinuse

int nwpinuse
static

◆ nwproc

int nwproc
static

◆ tid

int tid
static

◆ timef

TF* timef
static

◆ wproc

WP* wproc
static