#include <BaServerLib.h>
#include <SplayTree.h>
#include <DoubleList.h>
#include <ThreadLib.h>
Go to the source code of this file.
|
| struct | BaTimer |
| | Timer manager used for one-shot and periodic callbacks. More...
|
| |
|
| 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...
|
| |
◆ 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
-
| data | Borrowed 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.
◆ BaTimer_cancel()
| BA_API int BaTimer_cancel |
( |
BaTimer * |
o, |
|
|
size_t |
tkey |
|
) |
| |
Cancel an event; its application data is not freed.
- Parameters
-
| [in,out] | o | Initialized manager; its mutex is acquired if needed. |
| [in] | tkey | Key returned by BaTimer_set. |
- Returns
- 0 on cancellation, -1 if the key is not present.
◆ BaTimer_constructor()
Initialize and start a timer manager.
- Parameters
-
| [out] | o | Caller-owned storage. |
| [in] | mutex | Required borrowed mutex, held during callbacks. |
| [in] | stackSize | Worker stack bytes accepted by the platform Thread port. |
| [in] | ticklen | Positive tick interval in milliseconds. |
| [in] | priority | Worker thread priority. |
| [in] | alloc | Borrowed 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] | o | Initialized 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] | o | Initialized manager; its mutex is acquired if needed. |
| [in] | tkey | Key returned by BaTimer_set. |
| [in] | milliSec | New 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()
Schedule an event; the manager acquires its mutex if needed.
- Parameters
-
| [in,out] | o | Initialized manager. |
| [in] | cb | Required callback; see BaTimer_CB. |
| [in] | data | Borrowed callback context, possibly NULL. |
| [in] | milliSec | Delay in milliseconds; zero still queues asynchronously. |
- Returns
- Nonzero event key, or zero on allocation failure or shutdown.
- See also
- BaTimer::set