Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
BaTimer.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 ****************************************************************************
11 * HEADER
12 *
13 * $Id: BaTimer.h 5978 2026-09-11 16:13:48Z wini $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2008 - 2017
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://www.realtimelogic.com
33 ****************************************************************************
34 *
35 */
36
39#ifndef __BaTimer_h
40#define __BaTimer_h
41
42#include <BaServerLib.h>
43#include <SplayTree.h>
44#include <DoubleList.h>
45#include <ThreadLib.h>
46
47/* The number of slots in the timer. This must be a value of 2^x */
48#define BA_TIMER_SLOTS 32
49
57typedef BaBool (*BaTimer_CB)(void* data);
58
64typedef struct BaTimer
65#ifdef __cplusplus
66: public Thread
67{
81 BaTimer(ThreadMutex* mutex,int stackSize, U32 ticklen=10,
82 ThreadPriority priority=ThreadPrioNormal,
83 AllocatorIntf* alloc=0);
90 ~BaTimer();
91
105 size_t set(BaTimer_CB cb, void* data, U32 milliSec);
106
115 int reset(size_t tkey, U32 milliSec);
116
123 int cancel(size_t tkey);
124#else
125#if 0
126}
127#endif
128{
129 Thread super;
130#endif
131 DoubleList slots[BA_TIMER_SLOTS];
132 DoubleList readyQ;
133 SplayTree tnTree;
134 ThreadMutex* mutex;
135 AllocatorIntf* alloc;
136 U32 ticklen;
137 S16 dataInReadyQ;
138 U16 curIndex;
140
141#ifdef __cplusplus
142extern "C" {
143#endif
153 BaTimer* o, ThreadMutex* mutex,int stackSize, U32 ticklen,
154 ThreadPriority priority, AllocatorIntf* alloc);
166BA_API size_t BaTimer_set(BaTimer* o, BaTimer_CB cb, void* data, U32 milliSec);
173BA_API int BaTimer_reset(BaTimer* o, size_t tkey, U32 milliSec);
178BA_API int BaTimer_cancel(BaTimer* o, size_t tkey);
179#ifdef __cplusplus
180}
181inline BaTimer::BaTimer(ThreadMutex* mutex,int stackSize, U32 ticklen,
182 ThreadPriority priority, AllocatorIntf* alloc) {
183 BaTimer_constructor(this, mutex, stackSize, ticklen, priority,alloc);
184}
186 BaTimer_destructor(this);
187}
188inline size_t BaTimer::set(BaTimer_CB cb, void* data, U32 milliSec) {
189 return BaTimer_set(this, cb, data, milliSec);
190}
191inline int BaTimer::reset(size_t tkey, U32 milliSec) {
192 return BaTimer_reset(this, tkey, milliSec);
193}
194inline int BaTimer::cancel(size_t tkey) {
195 return BaTimer_cancel(this, tkey);
196}
197#endif
198
199#endif
BA_API int BaTimer_reset(BaTimer *o, size_t tkey, U32 milliSec)
Replace an existing event's delay while preserving its key and callback.
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.
BA_API void BaTimer_destructor(BaTimer *o)
Stop and release a timer manager's worker and queued events.
BaTimer BaTimer
Timer manager used for one-shot and periodic callbacks.
BA_API int BaTimer_cancel(BaTimer *o, size_t tkey)
Cancel an event; its application data is not freed.
BA_API void BaTimer_constructor(BaTimer *o, ThreadMutex *mutex, int stackSize, U32 ticklen, ThreadPriority priority, AllocatorIntf *alloc)
Initialize and start a timer manager.
BaBool(* BaTimer_CB)(void *data)
Timer callback function.
Definition: BaTimer.h:57
ThreadPriority
Portable priority choices, mapped to the target operating system.
Definition: ThreadLib.h:61
uint16_t U16
Unsigned 16-bit integer.
Definition: GenPrimT.h:91
uint32_t U32
Unsigned 32-bit integer.
Definition: GenPrimT.h:93
int16_t S16
Signed 16-bit integer.
Definition: GenPrimT.h:83
U8 BaBool
Boolean stored in an unsigned byte; FALSE is zero and TRUE is one.
Definition: GenPrimT.h:118
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:98
Timer manager used for one-shot and periodic callbacks.
Definition: BaTimer.h:67
BaTimer(ThreadMutex *mutex, int stackSize, U32 ticklen=10, ThreadPriority priority=ThreadPrioNormal, AllocatorIntf *alloc=0)
Create a BaTimer object and its worker thread.
Definition: BaTimer.h:181
~BaTimer()
Stop the worker and discard outstanding timer events without calling their callbacks.
Definition: BaTimer.h:185
size_t set(BaTimer_CB cb, void *data, U32 milliSec)
Create a timer event.
Definition: BaTimer.h:188
int reset(size_t tkey, U32 milliSec)
Resets the timer.
Definition: BaTimer.h:191
int cancel(size_t tkey)
Cancels the timer.
Definition: BaTimer.h:194
Self-adjusting tree of caller-owned nodes, with unique keys.
Definition: SplayTree.h:109
A mutual exclusion class.
Definition: ThreadLib.h:196
A simple thread class.
Definition: ThreadLib.h:261