CScheduler Class Reference

#include <externs.h>

Collaboration diagram for CScheduler:

Collaboration graph
[legend]

Public Member Functions

void TraverseUnordered (SCHLOOK *pfLook)
void TraverseOrdered (SCHLOOK *pfLook)
 CScheduler (void)
void DeferTask (const CLinearTimeAbsolute &ltWhen, int iPriority, FTASK *fpTask, void *arg_voidptr, int arg_Integer)
void DeferImmediateTask (int iPriority, FTASK *fpTask, void *arg_voidptr, int arg_Integer)
bool WhenNext (CLinearTimeAbsolute *)
int RunTasks (int iCount)
int RunAllTasks (void)
int RunTasks (const CLinearTimeAbsolute &tNow)
void ReadyTasks (const CLinearTimeAbsolute &tNow)
void CancelTask (FTASK *fpTask, void *arg_voidptr, int arg_Integer)
void SetMinPriority (int arg_minPriority)
int GetMinPriority (void)

Private Attributes

CTaskHeap m_WhenHeap
CTaskHeap m_PriorityHeap
int m_Ticket
int m_minPriority

Detailed Description

Definition at line 928 of file externs.h.


Constructor & Destructor Documentation

CScheduler::CScheduler ( void   )  [inline]

Definition at line 939 of file externs.h.

References m_minPriority, m_Ticket, and PRIORITY_CF_DEQUEUE_ENABLED.


Member Function Documentation

void CScheduler::CancelTask ( FTASK fpTask,
void *  arg_voidptr,
int  arg_Integer 
)

Definition at line 487 of file timer.cpp.

References CTaskHeap::CancelTask(), m_PriorityHeap, and m_WhenHeap.

Referenced by do_timewarp(), and sighandler().

00488 {
00489     m_WhenHeap.CancelTask(fpTask, arg_voidptr, arg_Integer);
00490     m_PriorityHeap.CancelTask(fpTask, arg_voidptr, arg_Integer);
00491 }

void CScheduler::DeferImmediateTask ( int  iPriority,
FTASK fpTask,
void *  arg_voidptr,
int  arg_Integer 
)

Definition at line 467 of file timer.cpp.

References TASK_RECORD::arg_Integer, TASK_RECORD::arg_voidptr, CompareWhen(), TASK_RECORD::fpTask, CTaskHeap::Insert(), TASK_RECORD::iPriority, m_Ticket, TASK_RECORD::m_Ticket, and m_WhenHeap.

Referenced by save_command(), Task_ProcessCommand(), and wait_que().

00468 {
00469     PTASK_RECORD pTask = new TASK_RECORD;
00470     if (!pTask) return;
00471 
00472     //pTask->ltaWhen = ltaWhen;
00473     pTask->iPriority = iPriority;
00474     pTask->fpTask = fpTask;
00475     pTask->arg_voidptr = arg_voidptr;
00476     pTask->arg_Integer = arg_Integer;
00477     pTask->m_Ticket = m_Ticket++;
00478 
00479     // Must add to the WhenHeap so that network is still serviced.
00480     //
00481     if (!m_WhenHeap.Insert(pTask, CompareWhen))
00482     {
00483         delete pTask;
00484     }
00485 }

void CScheduler::DeferTask ( const CLinearTimeAbsolute ltWhen,
int  iPriority,
FTASK fpTask,
void *  arg_voidptr,
int  arg_Integer 
)

Definition at line 446 of file timer.cpp.

References TASK_RECORD::arg_Integer, TASK_RECORD::arg_voidptr, CompareWhen(), TASK_RECORD::fpTask, CTaskHeap::Insert(), TASK_RECORD::iPriority, TASK_RECORD::ltaWhen, m_Ticket, TASK_RECORD::m_Ticket, and m_WhenHeap.

Referenced by dispatch_CacheTick(), dispatch_CheckEvents(), dispatch_DatabaseDump(), dispatch_FreeListReconstruction(), dispatch_IdleCheck(), do_timewarp(), init_timer(), sighandler(), Task_ProcessCommand(), and wait_que().

00448 {
00449     PTASK_RECORD pTask = new TASK_RECORD;
00450     if (!pTask) return;
00451 
00452     pTask->ltaWhen = ltaWhen;
00453     pTask->iPriority = iPriority;
00454     pTask->fpTask = fpTask;
00455     pTask->arg_voidptr = arg_voidptr;
00456     pTask->arg_Integer = arg_Integer;
00457     pTask->m_Ticket = m_Ticket++;
00458 
00459     // Must add to the WhenHeap so that network is still serviced.
00460     //
00461     if (!m_WhenHeap.Insert(pTask, CompareWhen))
00462     {
00463         delete pTask;
00464     }
00465 }

int CScheduler::GetMinPriority ( void   )  [inline]

Definition at line 950 of file externs.h.

References m_minPriority.

Referenced by do_queue().

00950 { return m_minPriority; }

void CScheduler::ReadyTasks ( const CLinearTimeAbsolute tNow  ) 

Definition at line 493 of file timer.cpp.

References ComparePriority(), CompareWhen(), TASK_RECORD::fpTask, CTaskHeap::Insert(), TASK_RECORD::ltaWhen, m_PriorityHeap, m_WhenHeap, CTaskHeap::PeekAtTopmost(), and CTaskHeap::RemoveTopmost().

Referenced by do_queue(), and RunTasks().

00494 {
00495     // Move ready-to-run tasks off the WhenHeap and onto the PriorityHeap.
00496     //
00497     PTASK_RECORD pTask = m_WhenHeap.PeekAtTopmost();
00498     while (  pTask
00499           && pTask->ltaWhen < ltaNow)
00500     {
00501         pTask = m_WhenHeap.RemoveTopmost(CompareWhen);
00502         if (pTask)
00503         {
00504             if (  NULL == pTask->fpTask
00505                || !m_PriorityHeap.Insert(pTask, ComparePriority))
00506             {
00507                 delete pTask;
00508             }
00509         }
00510         pTask = m_WhenHeap.PeekAtTopmost();
00511     }
00512 }

int CScheduler::RunAllTasks ( void   ) 

Definition at line 557 of file timer.cpp.

References RunTasks().

Referenced by RunTasks().

00558 {
00559     int nTotalTasks = 0;
00560 
00561     int nTasks;
00562     do
00563     {
00564         nTasks = RunTasks(100);
00565         nTotalTasks += nTasks;
00566     } while (nTasks);
00567 
00568     return nTotalTasks;
00569 }

int CScheduler::RunTasks ( const CLinearTimeAbsolute tNow  ) 

Definition at line 514 of file timer.cpp.

References confdata::active_q_chunk, mudconf, ReadyTasks(), RunAllTasks(), and RunTasks().

00515 {
00516     ReadyTasks(ltaNow);
00517     if (mudconf.active_q_chunk)
00518     {
00519         return RunTasks(mudconf.active_q_chunk);
00520     }
00521     else
00522     {
00523         return RunAllTasks();
00524     }
00525 }

int CScheduler::RunTasks ( int  iCount  ) 

Definition at line 527 of file timer.cpp.

References TASK_RECORD::arg_Integer, TASK_RECORD::arg_voidptr, ComparePriority(), TASK_RECORD::fpTask, TASK_RECORD::iPriority, m_minPriority, m_PriorityHeap, CTaskHeap::PeekAtTopmost(), and CTaskHeap::RemoveTopmost().

Referenced by do_queue(), process_preload(), RunAllTasks(), RunTasks(), and shovechars().

00528 {
00529     int nTasks = 0;
00530     while (iCount--)
00531     {
00532         PTASK_RECORD pTask = m_PriorityHeap.PeekAtTopmost();
00533         if (!pTask) break;
00534 
00535         if (pTask->iPriority > m_minPriority)
00536         {
00537             // This is related to CF_DEQUEUE and also to untimed (SUSPENDED)
00538             // semaphore entries that we would like to manage together with
00539             // the timed ones.
00540             //
00541             break;
00542         }
00543         pTask = m_PriorityHeap.RemoveTopmost(ComparePriority);
00544         if (pTask)
00545         {
00546             if (pTask->fpTask)
00547             {
00548                 pTask->fpTask(pTask->arg_voidptr, pTask->arg_Integer);
00549                 nTasks++;
00550             }
00551             delete pTask;
00552         }
00553     }
00554     return nTasks;
00555 }

void CScheduler::SetMinPriority ( int  arg_minPriority  ) 

Definition at line 787 of file timer.cpp.

References m_minPriority.

Referenced by do_global(), and do_queue().

00788 {
00789     m_minPriority = arg_minPriority;
00790 }

void CScheduler::TraverseOrdered ( SCHLOOK pfLook  ) 

Definition at line 677 of file timer.cpp.

References ComparePriority(), CompareWhen(), m_PriorityHeap, m_WhenHeap, and CTaskHeap::TraverseOrdered().

Referenced by do_ps(), and nfy_que().

00678 {
00679     m_PriorityHeap.TraverseOrdered(pfLook, ComparePriority);
00680     m_WhenHeap.TraverseOrdered(pfLook, CompareWhen);
00681 }

void CScheduler::TraverseUnordered ( SCHLOOK pfLook  ) 

Definition at line 669 of file timer.cpp.

References ComparePriority(), CompareWhen(), m_PriorityHeap, m_WhenHeap, and CTaskHeap::TraverseUnordered().

Referenced by do_queue(), halt_que(), and nfy_que().

00670 {
00671     if (m_WhenHeap.TraverseUnordered(pfLook, CompareWhen))
00672     {
00673         m_PriorityHeap.TraverseUnordered(pfLook, ComparePriority);
00674     }
00675 }

bool CScheduler::WhenNext ( CLinearTimeAbsolute  ) 

Definition at line 571 of file timer.cpp.

References TASK_RECORD::iPriority, TASK_RECORD::ltaWhen, m_minPriority, m_PriorityHeap, m_WhenHeap, CTaskHeap::PeekAtTopmost(), and CLinearTimeAbsolute::SetSeconds().

Referenced by shovechars().

00572 {
00573     // Check the Priority Queue first.
00574     //
00575     PTASK_RECORD pTask = m_PriorityHeap.PeekAtTopmost();
00576     if (pTask)
00577     {
00578         if (pTask->iPriority <= m_minPriority)
00579         {
00580             ltaWhen->SetSeconds(0);
00581             return true;
00582         }
00583     }
00584 
00585     // Check the When Queue next.
00586     //
00587     pTask = m_WhenHeap.PeekAtTopmost();
00588     if (pTask)
00589     {
00590         *ltaWhen = pTask->ltaWhen;
00591         return true;
00592     }
00593     return false;
00594 }


Field Documentation

int CScheduler::m_minPriority [private]

Definition at line 934 of file externs.h.

Referenced by CScheduler(), GetMinPriority(), RunTasks(), SetMinPriority(), and WhenNext().

CTaskHeap CScheduler::m_PriorityHeap [private]

Definition at line 932 of file externs.h.

Referenced by CancelTask(), ReadyTasks(), RunTasks(), TraverseOrdered(), TraverseUnordered(), and WhenNext().

int CScheduler::m_Ticket [private]

Definition at line 933 of file externs.h.

Referenced by CScheduler(), DeferImmediateTask(), and DeferTask().

CTaskHeap CScheduler::m_WhenHeap [private]

Definition at line 931 of file externs.h.

Referenced by CancelTask(), DeferImmediateTask(), DeferTask(), ReadyTasks(), TraverseOrdered(), TraverseUnordered(), and WhenNext().


The documentation for this class was generated from the following files:
Generated on Mon May 28 04:40:25 2007 for MUX by  doxygen 1.4.7