NCBI C++ ToolKit
|
Search Toolkit Book for CScheduler_MT
Thread-safe implementation of IScheduler interface. More...
Public Member Functions | |
virtual TScheduler_SeriesID | AddTask (IScheduler_Task *task, const CTime &exec_time) |
Schedule task for one-time execution. More... | |
virtual TScheduler_SeriesID | AddRepetitiveTask (IScheduler_Task *task, const CTime &start_time, const CTimeSpan &period, ERepeatPattern repeat_pattern) |
Schedule task for repetitive execution. More... | |
virtual void | RemoveSeries (TScheduler_SeriesID series_id) |
Remove series from scheduler queue. More... | |
virtual void | RemoveTask (IScheduler_Task *task) |
Remove task from scheduler queue. More... | |
virtual void | RemoveAllSeries (void) |
Unschedule all series waiting in scheduler queue. More... | |
virtual void | GetScheduledSeries (vector< SScheduler_SeriesInfo > *series) const |
Get full scheduler series list. More... | |
virtual void | RegisterListener (IScheduler_Listener *listener) |
Add listener which will be notified about changing in time of availability of next scheduled task. More... | |
virtual void | UnregisterListener (IScheduler_Listener *listener) |
Remove scheduler listener. More... | |
virtual CTime | GetNextExecutionTime (void) const |
Get next time point when scheduler will be ready to execute some task If there are already tasks to execute then return current time. More... | |
virtual bool | IsEmpty (void) const |
Check if there are tasks in scheduler queue (if it is not empty) More... | |
virtual bool | HasTasksToExecute (const CTime &now) const |
Check if there are tasks ready to execute. More... | |
virtual SScheduler_SeriesInfo | GetNextTaskToExecute (const CTime &now) |
Get information about next task that is ready to execute If there are no tasks to execute then return id = 0 and task = NULL. More... | |
virtual void | TaskExecuted (TScheduler_SeriesID series_id, const CTime &now) |
Be aware that task was just finished its execution. More... | |
CScheduler_MT (void) | |
Constructor. More... | |
Public Member Functions inherited from CObject | |
CObject (void) | |
Constructor. More... | |
CObject (const CObject &src) | |
Copy constructor. More... | |
virtual | ~CObject (void) |
Destructor. More... | |
CObject & | operator= (const CObject &src) THROWS_NONE |
Assignment operator. More... | |
bool | CanBeDeleted (void) const THROWS_NONE |
Check if object can be deleted. More... | |
bool | IsAllocatedInPool (void) const THROWS_NONE |
Check if object is allocated in memory pool (not system heap) More... | |
bool | Referenced (void) const THROWS_NONE |
Check if object is referenced. More... | |
bool | ReferencedOnlyOnce (void) const THROWS_NONE |
Check if object is referenced only once. More... | |
void | AddReference (void) const |
Add reference to object. More... | |
void | RemoveReference (void) const |
Remove reference to object. More... | |
void | ReleaseReference (void) const |
Remove reference without deleting object. More... | |
virtual void | DoNotDeleteThisObject (void) |
Mark this object as not allocated in heap – do not delete this object. More... | |
virtual void | DoDeleteThisObject (void) |
Mark this object as allocated in heap – object can be deleted. More... | |
void * | operator new (size_t size) |
Define new operator for memory allocation. More... | |
void * | operator new[] (size_t size) |
Define new[] operator for 'array' memory allocation. More... | |
void | operator delete (void *ptr) |
Define delete operator for memory deallocation. More... | |
void | operator delete[] (void *ptr) |
Define delete[] operator for memory deallocation. More... | |
void * | operator new (size_t size, void *place) |
Define new operator. More... | |
void | operator delete (void *ptr, void *place) |
Define delete operator. More... | |
void * | operator new (size_t size, CObjectMemoryPool *place) |
Define new operator using memory pool. More... | |
void | operator delete (void *ptr, CObjectMemoryPool *place) |
Define delete operator. More... | |
virtual void | DebugDump (CDebugDumpContext ddc, unsigned int depth) const |
Define method for dumping debug information. More... | |
Public Member Functions inherited from CDebugDumpable | |
CDebugDumpable (void) | |
virtual | ~CDebugDumpable (void) |
void | DebugDumpText (ostream &out, const string &bundle, unsigned int depth) const |
void | DebugDumpFormat (CDebugDumpFormatter &ddf, const string &bundle, unsigned int depth) const |
void | DumpToConsole (void) const |
Public Member Functions inherited from IScheduler | |
virtual | ~IScheduler (void) |
Pure virtual destructor. More... | |
Protected Member Functions | |
virtual | ~CScheduler_MT (void) |
Destructor. To be called from CRef. More... | |
Protected Member Functions inherited from CObject | |
virtual void | DeleteThis (void) |
Virtual method "deleting" this object. More... | |
Private Types | |
typedef CSyncQueue_multiset< CRef< CScheduler_QueueEvent >, PScheduler_QueueEvent_Compare > | TSchedQueue |
Type of queue for information about scheduled tasks. More... | |
typedef deque< CRef< CScheduler_QueueEvent > > | TExecList |
Type of list of information about currently executing tasks. More... | |
typedef vector< IScheduler_Listener * > | TListenersList |
Type of list of all scheduler listeners. More... | |
Private Member Functions | |
CScheduler_MT (const CScheduler_MT &) | |
Prohibit copying and assigning. More... | |
CScheduler_MT & | operator= (const CScheduler_MT &) |
TScheduler_SeriesID | x_AddQueueTask (TScheduler_SeriesID id, IScheduler_Task *task, const CTime &exec_time, const CTimeSpan &period, CScheduler_QueueEvent::ERepeatPattern repeat_pattern, CMutexGuard *guard) |
Schedule task execution. More... | |
void | x_SchedQueueChanged (CMutexGuard *guard) |
Change next execution time when queue of scheduled tasks is changed. More... | |
template<class T > | |
void | x_RemoveTaskImpl (T task) |
Implementation of removing task from queue. More... | |
Private Attributes | |
TSchedQueue | m_ScheduledTasks |
Queue of scheduled tasks. More... | |
TExecList | m_ExecutingTasks |
List of executing tasks. More... | |
CAtomicCounter | m_IDCounter |
Counter for generating task id. More... | |
CMutex | m_MainMutex |
Main mutex for protection of changes in scheduler. More... | |
TListenersList | m_Listeners |
List of all scheduler listeners. More... | |
CTime | m_NextExecTime |
Time of execution of nearest task. More... | |
Additional Inherited Members | |
Public Types inherited from CObject | |
enum | EAllocFillMode { eAllocFillNone = 1 , eAllocFillZero , eAllocFillPattern } |
Control filling of newly allocated memory. More... | |
typedef CObjectCounterLocker | TLockerType |
Default locker type for CRef. More... | |
typedef atomic< Uint8 > | TCounter |
Counter type is CAtomiCounter. More... | |
typedef Uint8 | TCount |
Alias for value type of counter. More... | |
Public Types inherited from IScheduler | |
enum | ERepeatPattern { eWithRate , eWithDelay } |
How to run repetitive tasks. More... | |
Static Public Member Functions inherited from CObject | |
static NCBI_XNCBI_EXPORT void | ThrowNullPointerException (void) |
Define method to throw null pointer exception. More... | |
static NCBI_XNCBI_EXPORT void | ThrowNullPointerException (const type_info &type) |
static EAllocFillMode | GetAllocFillMode (void) |
static void | SetAllocFillMode (EAllocFillMode mode) |
static void | SetAllocFillMode (const string &value) |
Set mode from configuration parameter value. More... | |
Static Public Member Functions inherited from CDebugDumpable | |
static void | EnableDebugDump (bool on) |
Static Public Member Functions inherited from IScheduler | |
static CIRef< IScheduler > | Create (void) |
Create a stock MT-safe scheduler. More... | |
Static Public Attributes inherited from CObject | |
static const TCount | eCounterBitsCanBeDeleted = 1 << 0 |
Define possible object states. More... | |
static const TCount | eCounterBitsInPlainHeap = 1 << 1 |
Heap signature was found. More... | |
static const TCount | eCounterBitsPlaceMask |
Mask for 'in heap' state flags. More... | |
static const int | eCounterStep = 1 << 2 |
Skip over the "in heap" bits. More... | |
static const TCount | eCounterValid = TCount(1) << (sizeof(TCount) * 8 - 2) |
Minimal value for valid objects (reference counter is zero) Must be a single bit value. More... | |
static const TCount | eCounterStateMask |
Valid object, and object in heap. More... | |
Thread-safe implementation of IScheduler interface.
Definition at line 117 of file scheduler.cpp.
|
private |
Type of list of information about currently executing tasks.
Definition at line 241 of file scheduler.cpp.
|
private |
Type of list of all scheduler listeners.
Definition at line 243 of file scheduler.cpp.
|
private |
Type of queue for information about scheduled tasks.
Definition at line 239 of file scheduler.cpp.
CScheduler_MT::CScheduler_MT | ( | void | ) |
Constructor.
Definition at line 266 of file scheduler.cpp.
References kInfinityTimeT, m_IDCounter, m_NextExecTime, CAtomicCounter::Set(), and CTime::SetTimeT().
|
protectedvirtual |
Destructor. To be called from CRef.
Definition at line 272 of file scheduler.cpp.
|
private |
Prohibit copying and assigning.
|
virtual |
Schedule task for repetitive execution.
Implements IScheduler.
Definition at line 351 of file scheduler.cpp.
References m_MainMutex, start_time, and x_AddQueueTask().
|
virtual |
Schedule task for one-time execution.
Implements IScheduler.
Definition at line 342 of file scheduler.cpp.
References CScheduler_QueueEvent::eNoRepeat, m_MainMutex, and x_AddQueueTask().
|
virtual |
Get next time point when scheduler will be ready to execute some task If there are already tasks to execute then return current time.
Implements IScheduler.
Definition at line 464 of file scheduler.cpp.
References m_MainMutex, and m_NextExecTime.
|
virtual |
Get information about next task that is ready to execute If there are no tasks to execute then return id = 0 and task = NULL.
Implements IScheduler.
Definition at line 500 of file scheduler.cpp.
References multiset< Key, Compare >::begin(), CScheduler_QueueEvent::eWithRate, CScheduler_QueueEvent::exec_time, CSyncQueue_multiset< Key, Compare, Allocator >::front(), SScheduler_SeriesInfo::id, CScheduler_QueueEvent::id, m_ExecutingTasks, m_MainMutex, m_ScheduledTasks, CScheduler_QueueEvent::period, CSyncQueue_multiset< Key, Compare, Allocator >::pop_front(), CScheduler_QueueEvent::repeat_pattern, multiset< Key, Compare >::size(), SScheduler_SeriesInfo::task, CScheduler_QueueEvent::task, x_AddQueueTask(), and x_SchedQueueChanged().
|
virtual |
Get full scheduler series list.
Implements IScheduler.
Definition at line 416 of file scheduler.cpp.
References CScheduler_QueueEvent::eNoRepeat, ITERATE, m_ExecutingTasks, m_MainMutex, m_ScheduledTasks, and multiset< Key, Compare >::size().
Check if there are tasks ready to execute.
Implements IScheduler.
Definition at line 492 of file scheduler.cpp.
References m_MainMutex, and m_NextExecTime.
|
virtual |
Check if there are tasks in scheduler queue (if it is not empty)
Implements IScheduler.
Definition at line 472 of file scheduler.cpp.
References multiset< Key, Compare >::empty(), CScheduler_QueueEvent::eNoRepeat, ITERATE, m_ExecutingTasks, m_MainMutex, m_ScheduledTasks, and result.
|
private |
|
virtual |
Add listener which will be notified about changing in time of availability of next scheduled task.
Implements IScheduler.
Definition at line 443 of file scheduler.cpp.
References m_Listeners, and m_MainMutex.
|
virtual |
Unschedule all series waiting in scheduler queue.
Implements IScheduler.
Definition at line 410 of file scheduler.cpp.
References x_RemoveTaskImpl().
|
virtual |
Remove series from scheduler queue.
Implements IScheduler.
Definition at line 398 of file scheduler.cpp.
References x_RemoveTaskImpl().
|
virtual |
Remove task from scheduler queue.
Implements IScheduler.
Definition at line 404 of file scheduler.cpp.
References x_RemoveTaskImpl().
|
virtual |
Be aware that task was just finished its execution.
Implements IScheduler.
Definition at line 544 of file scheduler.cpp.
References CScheduler_QueueEvent::eWithDelay, CScheduler_QueueEvent::id, CRef< C, Locker >::IsNull(), m_ExecutingTasks, m_MainMutex, NON_CONST_ITERATE, CScheduler_QueueEvent::period, CScheduler_QueueEvent::repeat_pattern, CScheduler_QueueEvent::task, and x_AddQueueTask().
|
virtual |
Remove scheduler listener.
Implements IScheduler.
Definition at line 451 of file scheduler.cpp.
References m_Listeners, and m_MainMutex.
|
private |
Schedule task execution.
id | id of the scheduler series. if 0 then it is assigned automatically |
task | Task to execute |
exec_time | Time when task will be executed |
num_repeats | Total number of task executions |
period | Period between task executions |
isDelay | Whether period is executed from the beginning oor from the ending of the task execution |
guard | Guard for the main mutex which will be released at the end of method |
Definition at line 277 of file scheduler.cpp.
References CAtomicCounter::Add(), CScheduler_QueueEvent::exec_time, CScheduler_QueueEvent::id, m_IDCounter, m_ScheduledTasks, CScheduler_QueueEvent::period, CSyncQueue_multiset< Key, Compare, Allocator >::push_back(), CScheduler_QueueEvent::repeat_pattern, CScheduler_QueueEvent::task, and x_SchedQueueChanged().
Referenced by AddRepetitiveTask(), AddTask(), GetNextTaskToExecute(), and TaskExecuted().
|
inlineprivate |
Implementation of removing task from queue.
The task is searched by criteria given as a parameter. Parameter can be of any type that is accepted by CScheduler_QueueEvent::IsMatch().
Definition at line 365 of file scheduler.cpp.
References multiset< Key, Compare >::begin(), multiset< Key, Compare >::end(), CScheduler_QueueEvent::eNoRepeat, CSyncQueue_multiset< Key, Compare, Allocator >::erase(), ITERATE, m_ExecutingTasks, m_MainMutex, m_ScheduledTasks, and x_SchedQueueChanged().
Referenced by RemoveAllSeries(), RemoveSeries(), and RemoveTask().
|
private |
Change next execution time when queue of scheduled tasks is changed.
Notify all listeners about change if needed.
guard | Guardian locking main scheduler mutex which must be unlocked before notification of listeners. NB: after method execution mutex is not locked anymore. |
Definition at line 312 of file scheduler.cpp.
References multiset< Key, Compare >::begin(), kInfinityTimeT, m_Listeners, m_NextExecTime, m_ScheduledTasks, NON_CONST_ITERATE, CGuard< Resource, Lock, Unlock, ReportExceptions >::Release(), CTime::SetTimeT(), and multiset< Key, Compare >::size().
Referenced by GetNextTaskToExecute(), x_AddQueueTask(), and x_RemoveTaskImpl().
|
private |
List of executing tasks.
Definition at line 248 of file scheduler.cpp.
Referenced by GetNextTaskToExecute(), GetScheduledSeries(), IsEmpty(), TaskExecuted(), and x_RemoveTaskImpl().
|
private |
Counter for generating task id.
Definition at line 250 of file scheduler.cpp.
Referenced by CScheduler_MT(), and x_AddQueueTask().
|
private |
List of all scheduler listeners.
Definition at line 254 of file scheduler.cpp.
Referenced by RegisterListener(), UnregisterListener(), and x_SchedQueueChanged().
|
mutableprivate |
Main mutex for protection of changes in scheduler.
Definition at line 252 of file scheduler.cpp.
Referenced by AddRepetitiveTask(), AddTask(), GetNextExecutionTime(), GetNextTaskToExecute(), GetScheduledSeries(), HasTasksToExecute(), IsEmpty(), RegisterListener(), TaskExecuted(), UnregisterListener(), and x_RemoveTaskImpl().
|
private |
Time of execution of nearest task.
Definition at line 256 of file scheduler.cpp.
Referenced by CScheduler_MT(), GetNextExecutionTime(), HasTasksToExecute(), and x_SchedQueueChanged().
|
private |
Queue of scheduled tasks.
Definition at line 246 of file scheduler.cpp.
Referenced by GetNextTaskToExecute(), GetScheduledSeries(), IsEmpty(), x_AddQueueTask(), x_RemoveTaskImpl(), and x_SchedQueueChanged().