BDE 4.14.0 Production release
|
#include <bdlmt_eventscheduler.h>
Classes | |
struct | Event |
struct | RecurringEvent |
Public Types | |
typedef EventSchedulerEventHandle | EventHandle |
typedef EventSchedulerRecurringEventHandle | RecurringEventHandle |
typedef bsl::function< void(const bsl::function< void()> &)> | Dispatcher |
Defines a type alias for the dispatcher functor type. | |
Public Member Functions | |
BSLMF_NESTED_TRAIT_DECLARATION (EventScheduler, bslma::UsesBslmaAllocator) | |
EventScheduler (bslma::Allocator *basicAllocator=0) | |
EventScheduler (const bsl::string_view &eventSchedulerName, bdlm::MetricsRegistry *metricsRegistry, bslma::Allocator *basicAllocator=0) | |
EventScheduler (bsls::SystemClockType::Enum clockType, bslma::Allocator *basicAllocator=0) | |
EventScheduler (bsls::SystemClockType::Enum clockType, const bsl::string_view &eventSchedulerName, bdlm::MetricsRegistry *metricsRegistry, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const bsl::chrono::system_clock &, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const bsl::chrono::system_clock &, const bsl::string_view &eventSchedulerName, bdlm::MetricsRegistry *metricsRegistry, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const bsl::chrono::steady_clock &, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const bsl::chrono::steady_clock &, const bsl::string_view &eventSchedulerName, bdlm::MetricsRegistry *metricsRegistry, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const Dispatcher &dispatcherFunctor, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const Dispatcher &dispatcherFunctor, const bsl::string_view &eventSchedulerName, bdlm::MetricsRegistry *metricsRegistry, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const Dispatcher &dispatcherFunctor, bsls::SystemClockType::Enum clockType, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const Dispatcher &dispatcherFunctor, bsls::SystemClockType::Enum clockType, const bsl::string_view &eventSchedulerName, bdlm::MetricsRegistry *metricsRegistry, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const Dispatcher &dispatcherFunctor, const bsl::chrono::system_clock &, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const Dispatcher &dispatcherFunctor, const bsl::chrono::system_clock &, const bsl::string_view &eventSchedulerName, bdlm::MetricsRegistry *metricsRegistry, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const Dispatcher &dispatcherFunctor, const bsl::chrono::steady_clock &, bslma::Allocator *basicAllocator=0) | |
EventScheduler (const Dispatcher &dispatcherFunctor, const bsl::chrono::steady_clock &, const bsl::string_view &eventSchedulerName, bdlm::MetricsRegistry *metricsRegistry, bslma::Allocator *basicAllocator=0) | |
~EventScheduler () | |
void | cancelAllEvents () |
void | cancelAllEventsAndWait () |
int | cancelEvent (const Event *handle) |
int | cancelEvent (const RecurringEvent *handle) |
int | cancelEvent (EventHandle *handle) |
int | cancelEvent (RecurringEventHandle *handle) |
int | cancelEventAndWait (const Event *handle) |
int | cancelEventAndWait (const RecurringEvent *handle) |
int | cancelEventAndWait (EventHandle *handle) |
int | cancelEventAndWait (RecurringEventHandle *handle) |
void | releaseEventRaw (Event *handle) |
void | releaseEventRaw (RecurringEvent *handle) |
int | rescheduleEvent (const Event *handle, const bsls::TimeInterval &newEpochTime) |
template<class t_CLOCK , class t_DURATION > | |
int | rescheduleEvent (const Event *handle, const bsl::chrono::time_point< t_CLOCK, t_DURATION > &newEpochTime) |
int | rescheduleEventAndWait (const Event *handle, const bsls::TimeInterval &newEpochTime) |
template<class t_CLOCK , class t_DURATION > | |
int | rescheduleEventAndWait (const Event *handle, const bsl::chrono::time_point< t_CLOCK, t_DURATION > &newEpochTime) |
void | scheduleEvent (const bsls::TimeInterval &epochTime, const bsl::function< void()> &callback) |
void | scheduleEvent (EventHandle *event, const bsls::TimeInterval &epochTime, const bsl::function< void()> &callback) |
template<class t_CLOCK , class t_DURATION > | |
void | scheduleEvent (const bsl::chrono::time_point< t_CLOCK, t_DURATION > &epochTime, const bsl::function< void()> &callback) |
template<class t_CLOCK , class t_DURATION > | |
void | scheduleEvent (EventHandle *event, const bsl::chrono::time_point< t_CLOCK, t_DURATION > &epochTime, const bsl::function< void()> &callback) |
void | scheduleEventRaw (Event **event, const bsls::TimeInterval &epochTime, const bsl::function< void()> &callback) |
template<class t_CLOCK , class t_DURATION > | |
void | scheduleEventRaw (Event **event, const bsl::chrono::time_point< t_CLOCK, t_DURATION > &epochTime, const bsl::function< void()> &callback) |
void | scheduleRecurringEvent (const bsls::TimeInterval &interval, const bsl::function< void()> &callback, const bsls::TimeInterval &startEpochTime=bsls::TimeInterval(0)) |
void | scheduleRecurringEvent (RecurringEventHandle *event, const bsls::TimeInterval &interval, const bsl::function< void()> &callback, const bsls::TimeInterval &startEpochTime=bsls::TimeInterval(0)) |
template<class t_CLOCK , class t_REP_TYPE , class t_PERIOD_TYPE , class t_DURATION > | |
void | scheduleRecurringEvent (const bsl::chrono::duration< t_REP_TYPE, t_PERIOD_TYPE > &interval, const bsl::function< void()> &callback, const bsl::chrono::time_point< t_CLOCK, t_DURATION > &startEpochTime=t_CLOCK::now()) |
template<class t_CLOCK , class t_REP_TYPE , class t_PERIOD_TYPE , class t_DURATION > | |
void | scheduleRecurringEvent (RecurringEventHandle *event, const bsl::chrono::duration< t_REP_TYPE, t_PERIOD_TYPE > &interval, const bsl::function< void()> &callback, const bsl::chrono::time_point< t_CLOCK, t_DURATION > &startEpochTime=t_CLOCK::now()) |
void | scheduleRecurringEventRaw (RecurringEvent **event, const bsls::TimeInterval &interval, const bsl::function< void()> &callback, const bsls::TimeInterval &startEpochTime=bsls::TimeInterval(0)) |
template<class t_CLOCK , class t_REP_TYPE , class t_PERIOD_TYPE , class t_DURATION > | |
void | scheduleRecurringEventRaw (RecurringEvent **event, const bsl::chrono::duration< t_REP_TYPE, t_PERIOD_TYPE > &interval, const bsl::function< void()> &callback, const bsl::chrono::time_point< t_CLOCK, t_DURATION > &startEpochTime=t_CLOCK::now()) |
int | start () |
int | start (const bslmt::ThreadAttributes &threadAttributes) |
void | stop () |
Event * | addEventRefRaw (Event *handle) const |
RecurringEvent * | addRecurringEventRefRaw (RecurringEvent *handle) const |
bsls::SystemClockType::Enum | clockType () const |
bool | isInDispatcherThread () const |
bool | isStarted () const |
bsls::TimeInterval | now () const |
int | numEvents () const |
Return the number of pending one-time events in this scheduler. | |
int | numRecurringEvents () const |
bsls::TimeInterval | nextPendingEventTime () const |
bslma::Allocator * | allocator () const |
Return the allocator used by this object to supply memory. | |
Friends | |
class | EventSchedulerEventHandle |
class | EventSchedulerRecurringEventHandle |
class | EventSchedulerTestTimeSource |
This class provides a thread-safe event scheduler that executes callbacks in a separate "dispatcher thread." start
must be invoked to start dispatching the callbacks. stop
pauses the dispatching of the callbacks without removing the pending events.
typedef bsl::function<void(const bsl::function<void()>&)> bdlmt::EventScheduler::Dispatcher |
|
explicit |
Create an event scheduler using the default dispatcher functor (see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation) and using the system realtime clock to indicate the epoch used for all time intervals. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
|
explicit |
Create an event scheduler using the default dispatcher functor (see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation), using the system realtime clock to indicate the epoch used for all time intervals, the specified eventSchedulerName
to be used to identify this event scheduler, and the specified metricsRegistry
to be used for reporting metrics. If metricsRegistry
is 0, bdlm::MetricsRegistry::singleton()
is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
|
explicit |
Create an event scheduler using the default dispatcher functor (see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation) and using the specified clockType
to indicate the epoch used for all time intervals (see {Supported Clock Types} in the component documentation). Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
|
explicit |
Create an event scheduler using the default dispatcher functor (see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation), using the specified clockType
to indicate the epoch used for all time intervals (see {Supported Clock Types} in the component documentation), the specified eventSchedulerName
to be used to identify this event scheduler, and the specified metricsRegistry
to be used for reporting metrics. If metricsRegistry
is 0, bdlm::MetricsRegistry::singleton()
is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
|
explicit |
Create an event scheduler using the default dispatcher functor (see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation) and using the system realtime clock to indicate the epoch used for all time intervals. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
|
explicit |
Create an event scheduler using the default dispatcher functor (see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation), using the system realtime clock to indicate the epoch used for all time intervals, the specified eventSchedulerName
to be used to identify this event scheduler, and the specified metricsRegistry
to be used for reporting metrics. If metricsRegistry
is 0, bdlm::MetricsRegistry::singleton()
is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
|
explicit |
Create an event scheduler using the default dispatcher functor (see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation) and using the system monotonic clock to indicate the epoch used for all time intervals. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
|
explicit |
Create an event scheduler using the default dispatcher functor (see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation), using the system monotonic clock to indicate the epoch used for all time intervals, the specified eventSchedulerName
to be used to identify this event scheduler, and the specified metricsRegistry
to be used for reporting metrics. If metricsRegistry
is 0, bdlm::MetricsRegistry::singleton()
is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
|
explicit |
Create an event scheduler using the specified dispatcherFunctor
(see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation) and using the system realtime clock to indicate the epoch used for all time intervals. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
|
explicit |
Create an event scheduler using the specified dispatcherFunctor
(see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation), using the system realtime clock to indicate the epoch used for all time intervals, the specified eventSchedulerName
to be used to identify this event scheduler, and the specified metricsRegistry
to be used for reporting metrics. If metricsRegistry
is 0, bdlm::MetricsRegistry::singleton()
is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
bdlmt::EventScheduler::EventScheduler | ( | const Dispatcher & | dispatcherFunctor, |
bsls::SystemClockType::Enum | clockType, | ||
bslma::Allocator * | basicAllocator = 0 |
||
) |
Create an event scheduler using the specified dispatcherFunctor
(see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation) and using the specified clockType
to indicate the epoch used for all time intervals (see {Supported Clock Types} in the component documentation). Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
bdlmt::EventScheduler::EventScheduler | ( | const Dispatcher & | dispatcherFunctor, |
bsls::SystemClockType::Enum | clockType, | ||
const bsl::string_view & | eventSchedulerName, | ||
bdlm::MetricsRegistry * | metricsRegistry, | ||
bslma::Allocator * | basicAllocator = 0 |
||
) |
Create an event scheduler using the specified dispatcherFunctor
(see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation), using the specified clockType
to indicate the epoch used for all time intervals (see {Supported Clock Types} in the component documentation), the specified eventSchedulerName
to be used to identify this event scheduler, and the specified metricsRegistry
to be used for reporting metrics. If metricsRegistry
is 0, bdlm::MetricsRegistry::singleton()
is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
bdlmt::EventScheduler::EventScheduler | ( | const Dispatcher & | dispatcherFunctor, |
const bsl::chrono::system_clock & | , | ||
bslma::Allocator * | basicAllocator = 0 |
||
) |
Create an event scheduler using the specified dispatcherFunctor
(see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation) and using the system realtime clock to indicate the epoch used for all time intervals. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
bdlmt::EventScheduler::EventScheduler | ( | const Dispatcher & | dispatcherFunctor, |
const bsl::chrono::system_clock & | , | ||
const bsl::string_view & | eventSchedulerName, | ||
bdlm::MetricsRegistry * | metricsRegistry, | ||
bslma::Allocator * | basicAllocator = 0 |
||
) |
Create an event scheduler using the specified dispatcherFunctor
(see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation), using the system realtime clock to indicate the epoch used for all time intervals, the specified eventSchedulerName
to be used to identify this event scheduler, and the specified metricsRegistry
to be used for reporting metrics. If metricsRegistry
is 0, bdlm::MetricsRegistry::singleton()
is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
bdlmt::EventScheduler::EventScheduler | ( | const Dispatcher & | dispatcherFunctor, |
const bsl::chrono::steady_clock & | , | ||
bslma::Allocator * | basicAllocator = 0 |
||
) |
Create an event scheduler using the specified dispatcherFunctor
(see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation) and using the system monotonic clock to indicate the epoch used for all time intervals. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
bdlmt::EventScheduler::EventScheduler | ( | const Dispatcher & | dispatcherFunctor, |
const bsl::chrono::steady_clock & | , | ||
const bsl::string_view & | eventSchedulerName, | ||
bdlm::MetricsRegistry * | metricsRegistry, | ||
bslma::Allocator * | basicAllocator = 0 |
||
) |
Create an event scheduler using the specified dispatcherFunctor
(see {The Dispatcher Thread and the Dispatcher Functor} in the component-level documentation), using the system monotonic clock to indicate the epoch used for all time intervals, the specified eventSchedulerName
to be used to identify this event scheduler, and the specified metricsRegistry
to be used for reporting metrics. If metricsRegistry
is 0, bdlm::MetricsRegistry::singleton()
is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
bdlmt::EventScheduler::~EventScheduler | ( | ) |
Discard all unprocessed events and destroy this object. The behavior is undefined unless the scheduler is stopped.
|
inline |
Increment the reference count for the event referred to by the specified handle
and return handle
. There must be a corresponding call to releaseEventRaw
when the reference is no longer needed.
|
inline |
Increment the reference count for the recurring event referred to by the specified handle
and return handle
. There must be a corresponding call to releaseEventRaw
when the reference is no longer needed.
|
inline |
bdlmt::EventScheduler::BSLMF_NESTED_TRAIT_DECLARATION | ( | EventScheduler | , |
bslma::UsesBslmaAllocator | |||
) |
void bdlmt::EventScheduler::cancelAllEvents | ( | ) |
Cancel all recurring and one-time events scheduled in this EventScheduler.
void bdlmt::EventScheduler::cancelAllEventsAndWait | ( | ) |
Cancel all recurring and one-time events scheduled in this EventScheduler. Block until all events have either been cancelled or dispatched before this call returns. The behavior is undefined if this method is invoked from the dispatcher thread.
|
inline |
|
inline |
Cancel the event having the specified handle
. Return 0 on successful cancellation, and a non-zero value if the handle
is invalid or if the event has already been dispatched or canceled. Note that due to the implicit conversion from Handle types, these methods also match the following:
Compared to the version taking a pointer to Handle, the managed reference to the event is not released until the Handle goes out of scope.
int bdlmt::EventScheduler::cancelEvent | ( | EventHandle * | handle | ) |
int bdlmt::EventScheduler::cancelEvent | ( | RecurringEventHandle * | handle | ) |
Cancel the event having the specified handle
and release the handle. Return 0 on successful cancellation, and a non-zero value if the handle
is invalid or if the event has already been dispatched or canceled. Note that handle
is released whether this call is successful or not.
int bdlmt::EventScheduler::cancelEventAndWait | ( | const Event * | handle | ) |
int bdlmt::EventScheduler::cancelEventAndWait | ( | const RecurringEvent * | handle | ) |
Cancel the event having the specified handle
. Block until the event having handle
(if it is valid) is either successfully canceled or dispatched before the call returns. Return 0 on successful cancellation, and a non-zero value if handle
is invalid or if the event has already been dispatched or canceled. The behavior is undefined if this method is invoked from the dispatcher thread. Note that if the event is being executed when this method is invoked, this method will block until it is completed and then return a nonzero value.
int bdlmt::EventScheduler::cancelEventAndWait | ( | EventHandle * | handle | ) |
int bdlmt::EventScheduler::cancelEventAndWait | ( | RecurringEventHandle * | handle | ) |
Cancel the event having the specified handle
and release *handle
. Block until the event having handle
(if it is valid) is either successfully canceled or dispatched before the call returns. Return 0 on successful cancellation, and a non-zero value if handle
is invalid or if the event has already been dispatched or canceled. The behavior is undefined if this method is invoked from the dispatcher thread. Note that if the event is being executed when this method is invoked, this method will block until it is completed and then return a nonzero value. Also note that it is guaranteed that *handle
will be released whether this call is successful or not.
|
inline |
Return the value of the clock type that this object was created with.
|
inline |
Return true
if the calling thread is the dispatcher thread of this scheduler, and false
otherwise.
bool bdlmt::EventScheduler::isStarted | ( | ) | const |
Return true
if a call to start
has finished successfully more recently than any call to stop
, and false
otherwise.
bsls::TimeInterval bdlmt::EventScheduler::nextPendingEventTime | ( | ) | const |
Return the earliest scheduled starting time of the pending events and recurring events registered with this scheduler. If there are no pending events or recurring events, return INT64_MAX
microseconds.
|
inline |
Return the current epoch time, an absolute time represented as an interval from some epoch, which is determined by the clock indicated at construction (see {Supported Clock Types} in the component documentation).
|
inline |
|
inline |
Return the number of recurring events registered with this scheduler.
|
inline |
|
inline |
Release the specified handle
. Every handle reference added by scheduleEventRaw
, addEventRefRaw
, scheduleRecurringEventRaw
, or addRecurringEventRefRaw
must be released using this method to avoid leaking resources. The behavior is undefined if the value of handle
is used for any purpose after being released.
int bdlmt::EventScheduler::rescheduleEvent | ( | const Event * | handle, |
const bsl::chrono::time_point< t_CLOCK, t_DURATION > & | newEpochTime | ||
) |
Reschedule the event referred to by the specified handle
at the specified newEpochTime
truncated to microseconds. Return 0 on successful reschedule, and a non-zero value if the handle
is invalid or if the event has already been dispatched. The newEpochTime
is an absolute time represented as an interval from some epoch, determined by the clock associated with the time point.
int bdlmt::EventScheduler::rescheduleEvent | ( | const Event * | handle, |
const bsls::TimeInterval & | newEpochTime | ||
) |
Reschedule the event referred to by the specified handle
at the specified newEpochTime
truncated to microseconds. Return 0 on successful reschedule, and a non-zero value if the handle
is invalid or if the event has already been dispatched. The newEpochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock indicated at construction (see {Supported Clock Types} in the component documentation).
int bdlmt::EventScheduler::rescheduleEventAndWait | ( | const Event * | handle, |
const bsl::chrono::time_point< t_CLOCK, t_DURATION > & | newEpochTime | ||
) |
Reschedule the event referred to by the specified handle
at the specified newEpochTime
truncated to microseconds. Block until the event having handle
(if it is valid) is either successfully rescheduled or dispatched before the call returns. Return 0 on successful reschedule, and a non-zero value if handle
is invalid or if the event has already been dispatched. The newEpochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock associated with the time point. The behavior is undefined if this method is invoked from the dispatcher thread.
int bdlmt::EventScheduler::rescheduleEventAndWait | ( | const Event * | handle, |
const bsls::TimeInterval & | newEpochTime | ||
) |
Reschedule the event referred to by the specified handle
at the specified newEpochTime
truncated to microseconds. Block until the event having handle
(if it is valid) is either successfully rescheduled or dispatched before the call returns. Return 0 on successful reschedule, and a non-zero value if handle
is invalid or if the event has already been dispatched. The newEpochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock indicated at construction (see {Supported Clock Types} in the component documentation). The behavior is undefined if this method is invoked from the dispatcher thread.
|
inline |
Schedule the specified callback
to be dispatched at the specified epochTime
truncated to microseconds. Load into the optionally specified event
a handle that can be used to cancel the event (by invoking cancelEvent
). The epochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock associated with the time point. This method guarantees that the event will occur at or after epochTime
. epochTime
may be in the past, in which case the event will be executed as soon as possible.
|
inline |
void bdlmt::EventScheduler::scheduleEvent | ( | EventHandle * | event, |
const bsl::chrono::time_point< t_CLOCK, t_DURATION > & | epochTime, | ||
const bsl::function< void()> & | callback | ||
) |
|
inline |
Schedule the specified callback
to be dispatched at the specified epochTime
truncated to microseconds. Load into the optionally specified event
a handle that can be used to cancel the event (by invoking cancelEvent
). The epochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock indicated at construction (see {Supported Clock Types} in the component documentation). This method guarantees that the event will occur at or after epochTime
. epochTime
may be in the past, in which case the event will be executed as soon as possible.
void bdlmt::EventScheduler::scheduleEventRaw | ( | Event ** | event, |
const bsl::chrono::time_point< t_CLOCK, t_DURATION > & | epochTime, | ||
const bsl::function< void()> & | callback | ||
) |
Schedule the specified callback
to be dispatched at the specified epochTime
truncated to microseconds. Load into the specified event
pointer a handle that can be used to cancel the event (by invoking cancelEvent
). The epochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock associated with the time point. The event
pointer must be released invoking releaseEventRaw
when it is no longer needed.
void bdlmt::EventScheduler::scheduleEventRaw | ( | Event ** | event, |
const bsls::TimeInterval & | epochTime, | ||
const bsl::function< void()> & | callback | ||
) |
Schedule the specified callback
to be dispatched at the specified epochTime
truncated to microseconds. Load into the specified event
pointer a handle that can be used to cancel the event (by invoking cancelEvent
). The epochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock indicated at construction (see {Supported Clock Types} in the component documentation). The event
pointer must be released invoking releaseEventRaw
when it is no longer needed.
void bdlmt::EventScheduler::scheduleRecurringEvent | ( | const bsl::chrono::duration< t_REP_TYPE, t_PERIOD_TYPE > & | interval, |
const bsl::function< void()> & | callback, | ||
const bsl::chrono::time_point< t_CLOCK, t_DURATION > & | startEpochTime = t_CLOCK::now() |
||
) |
Schedule a recurring event that invokes the specified callback
at every specified interval
truncated to microseconds, with the first event dispatched at the optionally specified startEpochTime
truncated to microseconds. If startEpochTime
is not specified, the first event is dispatched at one interval
from now. Load into the optionally specified event
a handle that can be used to cancel the event (by invoking cancelEvent
). The startEpochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock associated with the time point. The behavior is undefined unless interval
is at least one microsecond. Note that if startEpochTime
is in the past, the first event is dispatched immediately, and additional (now() - startEpochTime) / interval
events will be submitted serially.
|
inline |
void bdlmt::EventScheduler::scheduleRecurringEvent | ( | RecurringEventHandle * | event, |
const bsl::chrono::duration< t_REP_TYPE, t_PERIOD_TYPE > & | interval, | ||
const bsl::function< void()> & | callback, | ||
const bsl::chrono::time_point< t_CLOCK, t_DURATION > & | startEpochTime = t_CLOCK::now() |
||
) |
|
inline |
Schedule a recurring event that invokes the specified callback
at every specified interval
truncated to microseconds, with the first event dispatched at the optionally specified startEpochTime
truncated to microseconds. If startEpochTime
is not specified, the first event is dispatched at one interval
from now. Load into the optionally specified event
a handle that can be used to cancel the event (by invoking cancelEvent
). The startEpochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock indicated at construction (see {Supported Clock Types} in the component documentation). The behavior is undefined unless interval
is at least one microsecond. Note that if startEpochTime
is in the past, the first event is dispatched immediately, and additional (now() - startEpochTime) / interval
events will be submitted serially.
void bdlmt::EventScheduler::scheduleRecurringEventRaw | ( | RecurringEvent ** | event, |
const bsl::chrono::duration< t_REP_TYPE, t_PERIOD_TYPE > & | interval, | ||
const bsl::function< void()> & | callback, | ||
const bsl::chrono::time_point< t_CLOCK, t_DURATION > & | startEpochTime = t_CLOCK::now() |
||
) |
Schedule a recurring event that invokes the specified callback
at every specified interval
truncated to microseconds, with the first event dispatched at the optionally specified startEpochTime
truncated to microseconds. If startEpochTime
is not specified, the first event is dispatched at one interval
from now. Load into the specified event
pointer a handle that can be used to cancel the event (by invoking cancelEvent
). The startEpochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock associated with the time point. The event
pointer must be released by invoking releaseEventRaw
when it is no longer needed. The behavior is undefined unless interval
is at least one microsecond. Note that if startEpochTime
is in the past, the first event is dispatched immediately, and additional (now() - startEpochTime) / interval
events will be submitted serially.
void bdlmt::EventScheduler::scheduleRecurringEventRaw | ( | RecurringEvent ** | event, |
const bsls::TimeInterval & | interval, | ||
const bsl::function< void()> & | callback, | ||
const bsls::TimeInterval & | startEpochTime = bsls::TimeInterval(0) |
||
) |
Schedule a recurring event that invokes the specified callback
at every specified interval
truncated to microseconds, with the first event dispatched at the optionally specified startEpochTime
truncated to microseconds. If startEpochTime
is not specified, the first event is dispatched at one interval
from now. Load into the specified event
pointer a handle that can be used to cancel the event (by invoking cancelEvent
). The startEpochTime
is an absolute time represented as an interval from some epoch, which is determined by the clock indicated at construction (see {Supported Clock Types} in the component documentation). The event
pointer must be released by invoking releaseEventRaw
when it is no longer needed. The behavior is undefined unless interval
is at least one microsecond. Note that if startEpochTime
is in the past, the first event is dispatched immediately, and additional (now() - startEpochTime) / interval
events will be submitted serially.
int bdlmt::EventScheduler::start | ( | ) |
Begin dispatching events on this scheduler using default attributes for the dispatcher thread. Return 0 on success, and a nonzero value otherwise. If another thread is currently executing stop
, wait until the dispatcher thread stops before starting a new one. If this scheduler has already started (and is not currently being stopped by another thread) then this invocation has no effect and 0 is returned. The created thread will use the eventSchedulerName
supplied at construction if it is not empty, otherwise "bdl.EventSched". The behavior is undefined if this method is invoked in the dispatcher thread (i.e., in a job executed by this scheduler). Note that any event whose time has already passed is pending and will be dispatched immediately.
int bdlmt::EventScheduler::start | ( | const bslmt::ThreadAttributes & | threadAttributes | ) |
Begin dispatching events on this scheduler using the specified threadAttributes
for the dispatcher thread (except that the DETACHED attribute is ignored). Return 0 on success, and a nonzero value otherwise. If another thread is currently executing stop
, wait until the dispatcher thread stops before starting a new one. If this scheduler has already started (and is not currently being stopped by another thread) then this invocation has no effect and 0 is returned. The created thread will use the name threadAttributes.getThreadName()
if it is not empty, otherwise eventSchedulerName
supplied at construction if it is not empty, otherwise "bdl.EventSched". The behavior is undefined if this method is invoked in the dispatcher thread (i.e., in a job executed by this scheduler). Note that any event whose time has already passed is pending and will be dispatched immediately.
void bdlmt::EventScheduler::stop | ( | ) |
End the dispatching of events on this scheduler (but do not remove any pending events), and wait for any (one) currently executing event to complete. If the scheduler is already stopped then this method has no effect. This scheduler can be restarted by invoking start
. The behavior is undefined if this method is invoked from the dispatcher thread.
|
friend |
|
friend |
|
friend |