NCBI C++ ToolKit
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
CScheduler_MT Class Reference

Search Toolkit Book for CScheduler_MT

Thread-safe implementation of IScheduler interface. More...

+ Inheritance diagram for CScheduler_MT:
+ Collaboration diagram for CScheduler_MT:

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...
 
CObjectoperator= (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_CompareTSchedQueue
 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_MToperator= (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< Uint8TCounter
 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< ISchedulerCreate (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...
 

Detailed Description

Thread-safe implementation of IScheduler interface.

Definition at line 117 of file scheduler.cpp.

Member Typedef Documentation

◆ TExecList

Type of list of information about currently executing tasks.

Definition at line 241 of file scheduler.cpp.

◆ TListenersList

Type of list of all scheduler listeners.

Definition at line 243 of file scheduler.cpp.

◆ TSchedQueue

Type of queue for information about scheduled tasks.

Definition at line 239 of file scheduler.cpp.

Constructor & Destructor Documentation

◆ CScheduler_MT() [1/2]

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().

◆ ~CScheduler_MT()

CScheduler_MT::~CScheduler_MT ( void  )
protectedvirtual

Destructor. To be called from CRef.

Definition at line 272 of file scheduler.cpp.

◆ CScheduler_MT() [2/2]

CScheduler_MT::CScheduler_MT ( const CScheduler_MT )
private

Prohibit copying and assigning.

Member Function Documentation

◆ AddRepetitiveTask()

TScheduler_SeriesID CScheduler_MT::AddRepetitiveTask ( IScheduler_Task task,
const CTime start_time,
const CTimeSpan period,
ERepeatPattern  repeat_pattern 
)
virtual

Schedule task for repetitive execution.

Implements IScheduler.

Definition at line 351 of file scheduler.cpp.

References m_MainMutex, start_time, and x_AddQueueTask().

◆ AddTask()

TScheduler_SeriesID CScheduler_MT::AddTask ( IScheduler_Task task,
const CTime exec_time 
)
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().

◆ GetNextExecutionTime()

CTime CScheduler_MT::GetNextExecutionTime ( void  ) const
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.

◆ GetNextTaskToExecute()

SScheduler_SeriesInfo CScheduler_MT::GetNextTaskToExecute ( const CTime now)
virtual

◆ GetScheduledSeries()

void CScheduler_MT::GetScheduledSeries ( vector< SScheduler_SeriesInfo > *  series) const
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().

◆ HasTasksToExecute()

bool CScheduler_MT::HasTasksToExecute ( const CTime now) const
virtual

Check if there are tasks ready to execute.

Implements IScheduler.

Definition at line 492 of file scheduler.cpp.

References m_MainMutex, and m_NextExecTime.

◆ IsEmpty()

bool CScheduler_MT::IsEmpty ( void  ) const
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.

◆ operator=()

CScheduler_MT& CScheduler_MT::operator= ( const CScheduler_MT )
private

◆ RegisterListener()

void CScheduler_MT::RegisterListener ( IScheduler_Listener listener)
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.

◆ RemoveAllSeries()

void CScheduler_MT::RemoveAllSeries ( void  )
virtual

Unschedule all series waiting in scheduler queue.

Implements IScheduler.

Definition at line 410 of file scheduler.cpp.

References x_RemoveTaskImpl().

◆ RemoveSeries()

void CScheduler_MT::RemoveSeries ( TScheduler_SeriesID  series_id)
virtual

Remove series from scheduler queue.

Implements IScheduler.

Definition at line 398 of file scheduler.cpp.

References x_RemoveTaskImpl().

◆ RemoveTask()

void CScheduler_MT::RemoveTask ( IScheduler_Task task)
virtual

Remove task from scheduler queue.

Implements IScheduler.

Definition at line 404 of file scheduler.cpp.

References x_RemoveTaskImpl().

◆ TaskExecuted()

void CScheduler_MT::TaskExecuted ( TScheduler_SeriesID  series_id,
const CTime now 
)
virtual

◆ UnregisterListener()

void CScheduler_MT::UnregisterListener ( IScheduler_Listener listener)
virtual

Remove scheduler listener.

Implements IScheduler.

Definition at line 451 of file scheduler.cpp.

References m_Listeners, and m_MainMutex.

◆ x_AddQueueTask()

TScheduler_SeriesID CScheduler_MT::x_AddQueueTask ( TScheduler_SeriesID  id,
IScheduler_Task task,
const CTime exec_time,
const CTimeSpan period,
CScheduler_QueueEvent::ERepeatPattern  repeat_pattern,
CMutexGuard guard 
)
private

Schedule task execution.

Parameters
idid of the scheduler series. if 0 then it is assigned automatically
taskTask to execute
exec_timeTime when task will be executed
num_repeatsTotal number of task executions
periodPeriod between task executions
isDelayWhether period is executed from the beginning oor from the ending of the task execution
guardGuard 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().

◆ x_RemoveTaskImpl()

template<class T >
void CScheduler_MT::x_RemoveTaskImpl ( T  task)
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().

See also
CScheduler_QueueEvent::IsMatch(), RemoveSeries(), RemoveTask()

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().

◆ x_SchedQueueChanged()

void CScheduler_MT::x_SchedQueueChanged ( CMutexGuard guard)
private

Change next execution time when queue of scheduled tasks is changed.

Notify all listeners about change if needed.

Parameters
guardGuardian 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().

Member Data Documentation

◆ m_ExecutingTasks

TExecList CScheduler_MT::m_ExecutingTasks
private

List of executing tasks.

Definition at line 248 of file scheduler.cpp.

Referenced by GetNextTaskToExecute(), GetScheduledSeries(), IsEmpty(), TaskExecuted(), and x_RemoveTaskImpl().

◆ m_IDCounter

CAtomicCounter CScheduler_MT::m_IDCounter
private

Counter for generating task id.

Definition at line 250 of file scheduler.cpp.

Referenced by CScheduler_MT(), and x_AddQueueTask().

◆ m_Listeners

TListenersList CScheduler_MT::m_Listeners
private

List of all scheduler listeners.

Definition at line 254 of file scheduler.cpp.

Referenced by RegisterListener(), UnregisterListener(), and x_SchedQueueChanged().

◆ m_MainMutex

CMutex CScheduler_MT::m_MainMutex
mutableprivate

◆ m_NextExecTime

CTime CScheduler_MT::m_NextExecTime
private

Time of execution of nearest task.

Definition at line 256 of file scheduler.cpp.

Referenced by CScheduler_MT(), GetNextExecutionTime(), HasTasksToExecute(), and x_SchedQueueChanged().

◆ m_ScheduledTasks

TSchedQueue CScheduler_MT::m_ScheduledTasks
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().


The documentation for this class was generated from the following file:
Modified on Fri Sep 20 14:57:58 2024 by modify_doxy.py rev. 669887