Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
BaTimer.h File Reference
#include <BaServerLib.h>
#include <SplayTree.h>
#include <DoubleList.h>
#include <ThreadLib.h>
Include dependency graph for BaTimer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  BaTimer
 Timer manager used for one-shot and periodic callbacks. More...
 

Typedefs

typedef BaBool(* BaTimer_CB) (void *data)
 Timer callback function. More...
 
typedef BaTimer BaTimer
 Timer manager used for one-shot and periodic callbacks. More...
 

Functions

BA_API void BaTimer_constructor (BaTimer *o, ThreadMutex *mutex, int stackSize, U32 ticklen, ThreadPriority priority, AllocatorIntf *alloc)
 Initialize and start a timer manager. More...
 
BA_API void BaTimer_destructor (BaTimer *o)
 Stop and release a timer manager's worker and queued events. More...
 
BA_API size_t BaTimer_set (BaTimer *o, BaTimer_CB cb, void *data, U32 milliSec)
 Schedule an event; the manager acquires its mutex if needed. More...
 
BA_API int BaTimer_reset (BaTimer *o, size_t tkey, U32 milliSec)
 Replace an existing event's delay while preserving its key and callback. More...
 
BA_API int BaTimer_cancel (BaTimer *o, size_t tkey)
 Cancel an event; its application data is not freed. More...
 

Typedef Documentation

◆ BaTimer

typedef BaTimer BaTimer

Timer manager used for one-shot and periodic callbacks.

BaTimer runs its own worker thread. Timer callbacks are therefore not executed in the HTTP request thread that created the timer.

◆ BaTimer_CB

typedef BaBool(* BaTimer_CB) (void *data)

Timer callback function.

Parameters
dataBorrowed application pointer supplied to set(); may be NULL. The callback runs with the manager's mutex held. Keep data valid until cancellation or until the callback returns FALSE; it is never freed by the timer manager. Do not destroy the timer manager from its callback.
Returns
TRUE to keep a periodic timer active, or FALSE to remove the timer.

Function Documentation

◆ BaTimer_cancel()

BA_API int BaTimer_cancel ( BaTimer o,
size_t  tkey 
)

Cancel an event; its application data is not freed.

Parameters
[in,out]oInitialized manager; its mutex is acquired if needed.
[in]tkeyKey returned by BaTimer_set.
Returns
0 on cancellation, -1 if the key is not present.

◆ BaTimer_constructor()

BA_API void BaTimer_constructor ( BaTimer o,
ThreadMutex mutex,
int  stackSize,
U32  ticklen,
ThreadPriority  priority,
AllocatorIntf alloc 
)

Initialize and start a timer manager.

Parameters
[out]oCaller-owned storage.
[in]mutexRequired borrowed mutex, held during callbacks.
[in]stackSizeWorker stack bytes accepted by the platform Thread port.
[in]ticklenPositive tick interval in milliseconds.
[in]priorityWorker thread priority.
[in]allocBorrowed allocator, or NULL for the default.
See also
BaTimer::BaTimer

◆ BaTimer_destructor()

BA_API void BaTimer_destructor ( BaTimer o)

Stop and release a timer manager's worker and queued events.

Parameters
[in,out]oInitialized manager. See BaTimer::~BaTimer for thread, synchronization and application-data lifetime requirements.

◆ BaTimer_reset()

BA_API int BaTimer_reset ( BaTimer o,
size_t  tkey,
U32  milliSec 
)

Replace an existing event's delay while preserving its key and callback.

Parameters
[in,out]oInitialized manager; its mutex is acquired if needed.
[in]tkeyKey returned by BaTimer_set.
[in]milliSecNew delay in milliseconds.
Returns
0 on success, -1 if not found, -2 if replacement allocation fails or shutdown has begun. On -2, the original event is already cancelled.

◆ BaTimer_set()

BA_API size_t BaTimer_set ( BaTimer o,
BaTimer_CB  cb,
void *  data,
U32  milliSec 
)

Schedule an event; the manager acquires its mutex if needed.

Parameters
[in,out]oInitialized manager.
[in]cbRequired callback; see BaTimer_CB.
[in]dataBorrowed callback context, possibly NULL.
[in]milliSecDelay in milliseconds; zero still queues asynchronously.
Returns
Nonzero event key, or zero on allocation failure or shutdown.
See also
BaTimer::set