14 namespace mt {
template<>
struct is_base_of<
honey::priv::SharedObj_tag, PeriodicTask> : std::true_type {}; }
17 class PeriodicTask :
public SharedObj<PeriodicTask>, thread::Pool::Task
25 typedef function<void ()>
Func;
67 virtual void exec() = 0;
90 template<
class Result>
112 virtual void exec() { _func.invoke_delayedReady(); }
113 virtual void readyFunctor(
bool reset) { _func.setReady(reset); }
114 virtual void cancelFunctor() { _func.setFunc([]{
throw_ Cancelled(); }); _func(); }
116 PackagedTask<Result ()> _func;
146 template<class Func, class PeriodicTask_ = PeriodicTask_<typename std::result_of<Func()>::type>>
176 multimap<MonoClock::TimePoint, PeriodicTask::Ptr> _tasks;
177 vector<PeriodicTask::Ptr> _due;
String info() const
Get task info for prepending to a log record.
Definition: PeriodicTask.cpp:68
A scoped lock that references any lockable. Locks on construction and unlocks on destruction.
Definition: Mutex.h:10
virtual bool traceEnabled() const
Definition: PeriodicTask.h:181
virtual ~PeriodicTask()
Definition: PeriodicTask.h:30
Holds a functor and period information, returned by scheduler.
Definition: PeriodicTask.h:91
MonoClock::Duration delay() const
Returns time remaining until task is due for execution (task is due at zero time or less) ...
Definition: PeriodicTask.h:38
optional< MonoClock::Duration > _period
Definition: PeriodicTask.h:77
PeriodicSched & _sched
Definition: PeriodicTask.h:76
Ptr _self
Definition: PeriodicTask.h:81
static TimePoint now()
Get current time.
Definition: Clock.h:48
Atomic< MonoClock::TimePoint > _due
Definition: PeriodicTask.h:83
~PeriodicSched()
Definition: PeriodicTask.cpp:95
Future result when cancelled.
Definition: PeriodicTask.h:28
static optnull_t optnull
Null optional, use to reset an optional to an uninitialized state or test for initialization.
Definition: Optional.h:12
Unique future, guarantees sole access to a future function result.
Definition: Future.h:53
Thread class.
Definition: Thread.h:128
Atomic< State > _state
Definition: PeriodicTask.h:82
A thread lock where the lock is acquired through a busy wait loop.
Definition: Spin.h:17
Base class of PeriodicTask_, returned by scheduler.
Definition: PeriodicTask.h:18
int _priority
Definition: PeriodicTask.h:86
int getPriority() const
Get task's thread execution scheduling priority.
Definition: PeriodicTask.h:50
static AsyncSched & inst()
Definition: Util.h:153
function< void()> Func
Definition: PeriodicTask.h:25
static mt_global(PeriodicSched, inst,(future::AsyncSched::inst()))
Get singleton, uses global future::AsyncSched pool.
void setPriority(int priority)
Set thread execution scheduling priority.
Definition: Thread.h:185
static PeriodicTask & current()
Get the current task object. Must be called from a task functor.
Definition: PeriodicTask.cpp:25
State
Definition: PeriodicTask.h:58
const Id & id() const
Get id used for debug output.
Definition: PeriodicTask.h:53
static PeriodicTask_ & current()
Wrapper for PeriodicTask::current()
Definition: PeriodicTask.h:105
SharedPtr< PeriodicTask > Ptr
Definition: PeriodicTask.h:24
static auto _
Definition: Module.cpp:8
Lock that is bound to a single condition. This is the common usage case of condition variables...
Definition: Lock.h:33
optional< MonoClock::Duration > _delay
Definition: PeriodicTask.h:78
static bool trace
Whether to log task execution flow.
Definition: PeriodicTask.h:156
virtual void trace(const String &file, int line, const String &msg) const
Definition: PeriodicTask.cpp:75
auto reset()
Reset bytestream manipulator state.
Definition: ByteStream.h:417
virtual void cancelFunctor()=0
Thread * _thread
Definition: PeriodicTask.h:85
#define EXCEPTION(Class)
Declares methods required for every subclass of honey::Exception.
Definition: Exception.h:17
void interrupt(const Exception::ConstPtr &e=new thread::Interrupted)
Request an interrupt in the executing task's thread.
Definition: PeriodicTask.h:43
virtual void readyFunctor(bool reset)=0
PeriodicSched(thread::Pool &pool)
Definition: PeriodicTask.cpp:84
PeriodicTask_::Ptr schedule(Func &&f, optional< MonoClock::Duration > period=optnull, optional< MonoClock::Duration > delay=optnull, const Id &id=idnull)
Schedule a task for execution.
Definition: PeriodicTask.h:147
#define idnull
Null id.
Definition: Id.h:124
Unicode UTF-16 string class, wrapper around std::u16string.
Definition: String.h:23
Interrupted exception.
Definition: Thread.h:101
Base exception class. Exceptions inherited from this class provide debug info and can be thrown polym...
Definition: Exception.h:45
#define throw_
Use in place of throw keyword to throw a honey::Exception object polymorphically and provide debug in...
Definition: Exception.h:11
bool interruptRequested()
Check whether an interrupt has been requested for the executing task's thread.
Definition: PeriodicTask.h:45
Enables any type to be optional so it can exist in an uninitialized null state.
Definition: Optional.h:52
SharedPtr< PeriodicTask_ > Ptr
Definition: PeriodicTask.h:96
void cancel()
Unschedule task from further execution. If the task is awaiting execution then its future will throw ...
Definition: PeriodicTask.cpp:32
void setPriority(int priority)
Set task's thread execution scheduling priority.
Definition: PeriodicTask.h:48
Mutex _lock
Definition: PeriodicTask.h:80
PeriodicTask(PeriodicSched &sched, optional< MonoClock::Duration > period, optional< MonoClock::Duration > delay, const Id &id)
Definition: PeriodicTask.cpp:15
Lock-free FIFO queue. Uses auto-expanding freelist allocator so memory is only reclaimed upon destruc...
Definition: Queue.h:14
Future< Result > future()
Get future from which delayed result can be retrieved.
Definition: PeriodicTask.h:102
void interrupt(const Exception::ConstPtr &e=new thread::Interrupted)
Request an interrupt in the thread.
Definition: Thread.cpp:156
Id _id
Definition: PeriodicTask.h:79
A thread lock where the lock is acquired by suspending thread execution until it becomes available...
Definition: Mutex.h:17
bool _cancelled
Definition: PeriodicTask.h:84
Holds a name string and its hashed value for fast comparison ops. See String Identifier.
Definition: Id.h:25
TimePoint::Duration Duration
Definition: Clock.h:41
bool active() const
Check if task is scheduled or executing.
Definition: PeriodicTask.h:36
Scheduler that executes tasks periodically or after a delay given a pool of threads.
Definition: PeriodicTask.h:120
bool interruptRequested() const
Check whether an interrupt has been requested for the thread.
Definition: Thread.cpp:167
Global Honeycomb namespace.
void operator()()
Definition: PeriodicTask.cpp:40
Spreads task execution across a pool of re-usable threads. Uses a lock-free work-stealing queue to en...
Definition: Pool.h:12