TIMER TYPE 1 - register_timer(const timepoint &tp, const timer_callback &cb): Type 1 timer’s callback function should be called exactly at timepoint. It is a one-shot timer.
TIMER TYPE 2 - register_timer(const millisecs &period, const timer_callback &cb): Type 2 timer’s callback function should be called every period_ms constantly. It is a periodic timer.
TIMER TYPE 3 - register_timer(const timepoint &tp, const millisecs &period, const timer_callback &cb): Type 3 timer’s callback function should be called if timepoint_ms is bigger than period_ms.
TIMER TYPE 4 - register_timer(const predicate &pred, const millisecs &period, const timer_callback &cb): Type 4 timer’s callback function should be called if predicate returns true.
- Create timer object.
- Register timer member.
- Preschedule that member’s deadline and save it to scheduler table.
- Sort the table.
- If scheduler table is not empty, sleep the thread according to timer member that has the closest deadline.
- If timer member queue changes, wake up the thread and reschedule the table again.
- After the timer callback call, schedule the table and sort it again.
-
Create a directory for keeping your build configuration: mkdir -p out/build
-
Create a directory for your source files. mkdir src
-
Compile & Run: cmake -S ../../ -B . && make &&./timer

