1 #ifndef CALLBACKMANAGER_H_INCLUDED
2 #define CALLBACKMANAGER_H_INCLUDED
6 #include "nta/ThreadPool.h"
30 static void dequeue(uint64_t
id);
35 static std::map<uint64_t, std::vector<event*>>
m_queue;
44 static std::mutex m_mutex;
45 static std::condition_variable_any m_cv;
53 static uint64_t
setInterval(
const Thunk& thunk, uint64_t when, uint64_t period);
55 static uint64_t
setTimeout(
const Thunk& thunk, uint64_t when);
57 static bool delay(uint64_t
id, uint64_t when,
bool absolute =
true);
61 static void clear(uint64_t
id);
69 #endif // CALLBACKMANAGER_H_INCLUDED
uint64_t when
How many frames to run it in.
A function to run at a certain time with some regularity.
static void increment_frame()
Informs CallbackManager that a frame has passed.
Thunk thunk
Function to execute.
static uint64_t setTimeout(const Thunk &thunk, uint64_t when)
Schedules a function to be called once after when frames and then repeatedly after.
static std::atomic< uint64_t > m_next
id given to the next created event
static std::map< uint64_t, event > m_active
The events waiting to happen (key is event.id)
static std::map< uint64_t, std::vector< event * > > m_queue
"Priority queue" of events ordered by when they should occur
static void clear(uint64_t id)
Removes the event with the given id.
uint64_t period
How many frames between consecutive runs.
static bool delay(uint64_t id, uint64_t when, bool absolute=true)
Changes when an event is next scheduled to run.
static void dequeue(uint64_t id)
Removes event from m_queue but not m_active (assumes id is valid)
static utils::ThreadPool m_pool
ThreadPool used for scheduling events to happen.
static void init()
Initializes the CallbackManager.
static uint64_t m_curr_frame
The current frame.
Collection of threads for running scheduled functions.
static std::thread m_dispatcher
Thread used to dispatch events.
static void destroy()
Destroys the CallbackManager.
static uint64_t setInterval(const Thunk &thunk, uint64_t when, uint64_t period)
static bool m_working
Global flag saying whether or not the CallbackManager has been destroyed.