Struct tasklet::context
Defined in File tasklet.h
Nested Relationships
This struct is a nested type of Class tasklet.
Struct Documentation
-
struct context
The thread context. This is passed to the task function (below).
Public Functions
-
explicit context(sleep_condition *condition)
Constructor
- Parameters
condition – [in] optional sleep_condition.
-
virtual ~context()
Destructor
-
template<typename durationT>
inline bool sleep(durationT const &duration) const Sleep function. Use with std::chrono’s durations. Returns true if the tasklet is still supposed to be running (i.e. sleep was interrupted by wakeup() rather than stop()), so you can build your thread function like this:
void func(tasklet & t, void * baton) { while (t.sleep()) { // Do something } }
- Parameters
duration – [in] The duration for which to sleep, in any of the std::chrono units.
- Returns
true if the tasklet is still running, false otherwise.
Public Members
-
std::atomic<bool> running
Gets set or unset by tasklet functions. Can also be used in the task_function to determine whether to exit the thread loop.
-
sleep_condition *condition
Gets notified when the running flag changes. Wait on this condition variable to sleep in the thread loop.
-
explicit context(sleep_condition *condition)