Barracuda Application Server C/C++ Reference
NO
BaTimer.h
1 /*
2  * ____ _________ __ _
3  * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4  * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5  * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6  * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7  * /____/
8  *
9  * Barracuda Embedded Web-Server
10  ****************************************************************************
11  * HEADER
12  *
13  * $Id: BaTimer.h 4915 2021-12-01 18:26:55Z 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 
37 #ifndef __BaTimer_h
38 #define __BaTimer_h
39 
40 #include <BaServerLib.h>
41 #include <SplayTree.h>
42 #include <DoubleList.h>
43 #include <ThreadLib.h>
44 
45 /* The number of slots in the timer. This must be a value of 2^x */
46 #define BA_TIMER_SLOTS 32
47 
50 typedef BaBool (*BaTimer_CB)(void* data);
51 
56 typedef struct BaTimer
57 #ifdef __cplusplus
58 : public Thread
59 {
67  BaTimer(ThreadMutex* mutex,int stackSize, U32 ticklen=10,
68  ThreadPriority priority=ThreadPrioNormal,
69  AllocatorIntf* alloc=0);
72  ~BaTimer();
73 
83  size_t set(BaTimer_CB cb, void* data, U32 milliSec);
84 
90  int reset(size_t tkey, U32 milliSec);
91 
96  int cancel(size_t tkey);
97 #else
98 #if 0
99 }
100 #endif
101 {
102  Thread super;
103 #endif
104  DoubleList slots[BA_TIMER_SLOTS];
105  DoubleList readyQ;
106  SplayTree tnTree;
107  ThreadMutex* mutex;
108  AllocatorIntf* alloc;
109  U32 ticklen;
110  S16 dataInReadyQ;
111  U16 curIndex;
112 } BaTimer;
113 
114 #ifdef __cplusplus
115 extern "C" {
116 #endif
117 BA_API void BaTimer_constructor(
118  BaTimer* o, ThreadMutex* mutex,int stackSize, U32 ticklen,
119  ThreadPriority priority, AllocatorIntf* alloc);
120 BA_API void BaTimer_destructor(BaTimer* o);
121 BA_API size_t BaTimer_set(BaTimer* o, BaTimer_CB cb, void* data, U32 milliSec);
122 BA_API int BaTimer_reset(BaTimer* o, size_t tkey, U32 milliSec);
123 BA_API int BaTimer_cancel(BaTimer* o, size_t tkey);
124 #ifdef __cplusplus
125 }
126 inline BaTimer::BaTimer(ThreadMutex* mutex,int stackSize, U32 ticklen,
127  ThreadPriority priority, AllocatorIntf* alloc) {
128  BaTimer_constructor(this, mutex, stackSize, ticklen, priority,alloc);
129 }
131  BaTimer_destructor(this);
132 }
133 inline size_t BaTimer::set(BaTimer_CB cb, void* data, U32 milliSec) {
134  return BaTimer_set(this, cb, data, milliSec);
135 }
136 inline int BaTimer::reset(size_t tkey, U32 milliSec) {
137  return BaTimer_reset(this, tkey, milliSec);
138 }
139 inline int BaTimer::cancel(size_t tkey) {
140  return BaTimer_cancel(this, tkey);
141 }
142 #endif
143 
144 #endif
BaTimer
The timer class makes it possible to create events that are activated at regular intervals or to crea...
Definition: BaTimer.h:59
AllocatorIntf
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:83
ThreadPriority
ThreadPriority
Thread priority list.
Definition: ThreadLib.h:58
BaTimer::BaTimer
BaTimer(ThreadMutex *mutex, int stackSize, U32 ticklen=10, ThreadPriority priority=ThreadPrioNormal, AllocatorIntf *alloc=0)
Create a BaTimer object and one thread.
Definition: BaTimer.h:126
BaTimer::~BaTimer
~BaTimer()
Terminate the timer.
Definition: BaTimer.h:130
BaTimer::set
size_t set(BaTimer_CB cb, void *data, U32 milliSec)
Create a timer event.
Definition: BaTimer.h:133
BaTimer::reset
int reset(size_t tkey, U32 milliSec)
Resets the timer.
Definition: BaTimer.h:136
Thread
A simple thread class.
Definition: ThreadLib.h:241
BaTimer::cancel
int cancel(size_t tkey)
Cancels the timer.
Definition: BaTimer.h:139
ThreadMutex
A mutual exclusion class.
Definition: ThreadLib.h:186