19 #ifndef PSTORE_CORE_HEARTBEAT_HPP 20 #define PSTORE_CORE_HEARTBEAT_HPP 24 #include <condition_variable> 29 #include <unordered_map> 35 static std::shared_ptr<heartbeat>
get ();
52 static_assert (
sizeof (
key_type) <=
sizeof (t),
"heartbeat::key_type is too small");
53 return reinterpret_cast<key_type> (t);
56 using callback = std::function<void (key_type)>;
57 void attach (
key_type key, callback cb);
89 void stop () noexcept;
92 using duration_type = std::chrono::milliseconds;
94 static duration_type
const delay_time_;
97 static duration_type
const max_time_;
103 duration_type
const * sleep_time_;
112 std::condition_variable cv_;
116 std::unordered_map<heartbeat::key_type, heartbeat::callback> callbacks_;
128 std::unique_ptr<state> state_;
133 #endif // PSTORE_CORE_HEARTBEAT_HPP void stop()
Stops the heartbeat thread.
Definition: heartbeat.hpp:64
static key_type to_key_type(T *t)
A small convenience function which will convert a pointer to key_type.
Definition: heartbeat.hpp:51
void stop() noexcept
Instructs the worker thread to exit on its next iteration.
Definition: heartbeat.cpp:77
void step() const
Executes a single invocation of each of the attached callbacks.
Definition: heartbeat.cpp:56
Definition: heartbeat.hpp:33
Definition: nonpod2.cpp:40
void run() noexcept
This is the thread entry point.
Definition: heartbeat.cpp:62
std::uintptr_t key_type
A key_type value is used to distinguish between different callbacks that are attached to the heartbea...
Definition: heartbeat.hpp:47