|
BDE 4.39.x Production Release
|
#include <bdlmt_eventscheduler.h>
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.
Classes | |
| struct | Event |
| struct | RecurringEvent |
Public Types | |
| typedef EventSchedulerEventHandle | EventHandle |
| typedef EventSchedulerRecurringEventHandle | RecurringEventHandle |
| typedef bsl::function< void(const bsl::function< void()> &)> | Dispatcher |
Friends | |
| class | EventSchedulerEventHandle |
| class | EventSchedulerRecurringEventHandle |
| class | EventSchedulerTestTimeSource |
| typedef bsl::function<void(const bsl::function<void()>&)> bdlmt::EventScheduler::Dispatcher |
Defines a type alias for the dispatcher functor type.
| bdlmt::EventScheduler::EventScheduler | ( | ) |
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 |
|
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 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 | ( | ) |
Discard all unprocessed events and destroy this object.
|
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 |
Return the allocator used by this object to supply memory.
| 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.
|
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.
|
inline |
| int bdlmt::EventScheduler::cancelEvent | ( | EventHandle * | 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.
handle is released whether this call is successful or not. | int bdlmt::EventScheduler::cancelEvent | ( | RecurringEventHandle * | handle | ) |
| int bdlmt::EventScheduler::cancelEventAndWait | ( | const Event * | 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.
| int bdlmt::EventScheduler::cancelEventAndWait | ( | const RecurringEvent * | handle | ) |
| int bdlmt::EventScheduler::cancelEventAndWait | ( | EventHandle * | 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.
*handle will be released whether this call is successful or not. | int bdlmt::EventScheduler::cancelEventAndWait | ( | RecurringEventHandle * | handle | ) |
|
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 |
Return the number of pending one-time events in this scheduler.
|
inline |
Return the number of recurring events registered with this scheduler.
|
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.
handle is used for any purpose after being released.
|
inline |
| 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 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).
| bsl::optional< bsls::TimeInterval > bdlmt::EventScheduler::scheduledEventTime | ( | const EventHandle & | handle | ) | const |
Return the scheduled starting time of the event having the specified handle. If the handle is invalid, or the event has already been canceled, return an optional without a value.
| bsl::optional< bsls::TimeInterval > bdlmt::EventScheduler::scheduledEventTime | ( | const RecurringEventHandle & | handle | ) | const |
|
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.
|
inline |
| 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.
|
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).
interval is at least one microsecond. 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::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.
interval is at least one microsecond. 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".
| 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".
| 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.
|
friend |
|
friend |
|
friend |