SW Task Event Loop Framework v1.0.0
High-performance C++ asynchronous event loop framework with timer management and promise-based programming
Loading...
Searching...
No Matches
Timer.h
Go to the documentation of this file.
1
9 #pragma once
10
11 #include <memory>
12 #include <functional>
13 #include <atomic>
14
15 namespace swt {
16 class SLLooper;
17
25 using TimerId = uint64_t;
26
68 class Timer {
69 private:
70 TimerId mId;
71 std::weak_ptr<SLLooper> mLooper;
72 std::atomic<bool> mCancelled{false};
73 mutable std::atomic<bool> mMoved{false};
75 public:
86 Timer(TimerId id, std::weak_ptr<SLLooper> looper);
87
94 Timer(const Timer&) = delete;
95
101 Timer& operator=(const Timer&) = delete;
102
116 Timer(Timer&& other) noexcept;
117
129 Timer& operator=(Timer&& other) noexcept;
130
141 ~Timer();
142
143 // ========== Public API (boost-style) ==========
144
163 void cancel();
164
187 bool isActive() const;
188
199 TimerId getId() const { return mId; }
200
221 void restart(uint64_t delay_ms);
222
229 friend class SLLooper;
230
231 private:
244 void moveFrom(Timer&& other) noexcept;
245 };
246
247 } // namespace swt
Central event loop coordinator providing asynchronous task execution and timer management.
Definition SLLooper.h:83
RAII timer wrapper with boost-style API and move semantics.
Definition Timer.h:68
bool isActive() const
Check if timer is currently active.
Definition Timer.cpp:75
void restart(uint64_t delay_ms)
Restart timer with new delay (one-shot timers only)
Definition Timer.cpp:86
Timer(const Timer &)=delete
Copy constructor - deleted (move-only semantics)
void cancel()
Cancel the timer.
Definition Timer.cpp:59
TimerId getId() const
Get unique timer identifier.
Definition Timer.h:199
Timer & operator=(const Timer &)=delete
Copy assignment - deleted (move-only semantics)
~Timer()
Destructor - automatic timer cleanup.
Definition Timer.cpp:49
Software Timer namespace containing all timer-related classes.
Definition Awaitable.h:21
uint64_t TimerId
Unique identifier type for timer instances.
Definition Timer.h:25