mux/src/timer.cpp File Reference

#include "copyright.h"
#include "autoconf.h"
#include "config.h"
#include "externs.h"
#include <signal.h>
#include "command.h"
#include "mguests.h"

Include dependency graph for timer.cpp:

Go to the source code of this file.

Defines

#define INITIAL_TASKS   100
#define EXTRA_TASKS   50
#define HEAP_LEFT_CHILD(x)   (2*(x)+1)
#define HEAP_RIGHT_CHILD(x)   (2*(x)+2)
#define HEAP_PARENT(x)   (((x)-1)/2)

Functions

void dispatch_FreeListReconstruction (void *pUnused, int iUnused)
void dispatch_DatabaseDump (void *pUnused, int iUnused)
void dispatch_IdleCheck (void *pUnused, int iUnused)
void dispatch_CheckEvents (void *pUnused, int iUnused)
void dispatch_CacheTick (void *pUnused, int iUnused)
static void dispatch_CanRestart (void *pUnused, int iUnused)
void init_timer (void)
void do_timewarp (dbref executor, dbref caller, dbref enactor, int key, char *arg)
static int ComparePriority (PTASK_RECORD pTaskA, PTASK_RECORD pTaskB)
static int CompareWhen (PTASK_RECORD pTaskA, PTASK_RECORD pTaskB)

Variables

CScheduler scheduler


Define Documentation

#define EXTRA_TASKS   50

Definition at line 324 of file timer.cpp.

Referenced by CTaskHeap::Grow().

#define HEAP_LEFT_CHILD (  )     (2*(x)+1)

Definition at line 596 of file timer.cpp.

Referenced by CTaskHeap::SiftDown().

#define HEAP_PARENT (  )     (((x)-1)/2)

Definition at line 598 of file timer.cpp.

Referenced by CTaskHeap::SiftUp().

#define HEAP_RIGHT_CHILD (  )     (2*(x)+2)

Definition at line 597 of file timer.cpp.

Referenced by CTaskHeap::SiftDown().

#define INITIAL_TASKS   100

Definition at line 323 of file timer.cpp.

Referenced by CTaskHeap::CTaskHeap().


Function Documentation

static int ComparePriority ( PTASK_RECORD  pTaskA,
PTASK_RECORD  pTaskB 
) [static]

Definition at line 419 of file timer.cpp.

References TASK_RECORD::iPriority, and TASK_RECORD::m_Ticket.

Referenced by CScheduler::ReadyTasks(), CScheduler::RunTasks(), CScheduler::TraverseOrdered(), and CScheduler::TraverseUnordered().

00420 {
00421     int i = (pTaskA->iPriority) - (pTaskB->iPriority);
00422     if (i == 0)
00423     {
00424         // Must subtract so that ticket rollover is handled properly.
00425         //
00426         return  (pTaskA->m_Ticket) - (pTaskB->m_Ticket);
00427     }
00428     return i;
00429 }

static int CompareWhen ( PTASK_RECORD  pTaskA,
PTASK_RECORD  pTaskB 
) [static]

Definition at line 431 of file timer.cpp.

References TASK_RECORD::ltaWhen.

Referenced by CScheduler::DeferImmediateTask(), CScheduler::DeferTask(), CScheduler::ReadyTasks(), CScheduler::TraverseOrdered(), and CScheduler::TraverseUnordered().

00432 {
00433     // Can't simply subtract because comparing involves a truncation cast.
00434     //
00435     if (pTaskA->ltaWhen < pTaskB->ltaWhen)
00436     {
00437         return -1;
00438     }
00439     else if (pTaskA->ltaWhen > pTaskB->ltaWhen)
00440     {
00441         return 1;
00442     }
00443     return 0;
00444 }

void dispatch_CacheTick ( void *  pUnused,
int  iUnused 
)

Definition at line 141 of file timer.cpp.

References cache_tick(), confdata::cache_tick_period, statedata::debug_cmd, CScheduler::DeferTask(), dispatch_CacheTick(), CLinearTimeAbsolute::GetUTC(), mudconf, mudstate, PRIORITY_SYSTEM, scheduler, CLinearTimeDelta::SetSeconds(), and UNUSED_PARAMETER.

Referenced by CallBack_ShowDispatches(), dispatch_CacheTick(), and init_timer().

00142 {
00143     UNUSED_PARAMETER(pUnused);
00144     UNUSED_PARAMETER(iUnused);
00145 
00146     char *cmdsave = mudstate.debug_cmd;
00147     mudstate.debug_cmd = (char *)"< cachetick >";
00148 
00149     CLinearTimeDelta ltd = 0;
00150     if (mudconf.cache_tick_period <= ltd)
00151     {
00152         mudconf.cache_tick_period.SetSeconds(1);
00153     }
00154 
00155     cache_tick();
00156 
00157     // Schedule ourselves again.
00158     //
00159     CLinearTimeAbsolute ltaNextTime;
00160     ltaNextTime.GetUTC();
00161     ltaNextTime += mudconf.cache_tick_period;
00162     scheduler.DeferTask(ltaNextTime, PRIORITY_SYSTEM, dispatch_CacheTick, 0, 0);
00163     mudstate.debug_cmd = cmdsave;
00164 }

static void dispatch_CanRestart ( void *  pUnused,
int  iUnused 
) [static]

Definition at line 185 of file timer.cpp.

References statedata::bCanRestart, mudstate, and UNUSED_PARAMETER.

Referenced by init_timer().

00186 {
00187     UNUSED_PARAMETER(pUnused);
00188     UNUSED_PARAMETER(iUnused);
00189     mudstate.bCanRestart = true;
00190 }

void dispatch_CheckEvents ( void *  pUnused,
int  iUnused 
)

Definition at line 118 of file timer.cpp.

References CF_EVENTCHECK, check_events(), confdata::control_flags, statedata::debug_cmd, CScheduler::DeferTask(), dispatch_CheckEvents(), statedata::events_counter, CLinearTimeAbsolute::GetUTC(), mudconf, mudstate, PRIORITY_SYSTEM, scheduler, time_15m, and UNUSED_PARAMETER.

Referenced by CallBack_ShowDispatches(), dispatch_CheckEvents(), do_timewarp(), and init_timer().

00119 {
00120     UNUSED_PARAMETER(pUnused);
00121     UNUSED_PARAMETER(iUnused);
00122 
00123     if (mudconf.control_flags & CF_EVENTCHECK)
00124     {
00125         char *cmdsave = mudstate.debug_cmd;
00126         mudstate.debug_cmd = (char *)"< eventcheck >";
00127         check_events();
00128         mudstate.debug_cmd = cmdsave;
00129     }
00130 
00131     // Schedule ourselves again.
00132     //
00133     CLinearTimeAbsolute ltaNow;
00134     ltaNow.GetUTC();
00135     CLinearTimeDelta ltd = time_15m;
00136     mudstate.events_counter = ltaNow + ltd;
00137     scheduler.DeferTask(mudstate.events_counter, PRIORITY_SYSTEM, dispatch_CheckEvents, 0, 0);
00138 }

void dispatch_DatabaseDump ( void *  pUnused,
int  iUnused 
)

Definition at line 52 of file timer.cpp.

References CF_CHECKPOINT, confdata::control_flags, statedata::debug_cmd, CScheduler::DeferTask(), dispatch_DatabaseDump(), statedata::dump_counter, confdata::dump_interval, statedata::dumping, fork_and_dump(), CLinearTimeAbsolute::GetUTC(), mudconf, mudstate, PRIORITY_SYSTEM, scheduler, CLinearTimeDelta::SetSeconds(), and UNUSED_PARAMETER.

Referenced by CallBack_ShowDispatches(), dispatch_DatabaseDump(), do_timewarp(), init_timer(), and sighandler().

00053 {
00054     UNUSED_PARAMETER(pUnused);
00055     UNUSED_PARAMETER(iUnused);
00056 
00057     int nNextTimeInSeconds = mudconf.dump_interval;
00058 
00059     if (mudconf.control_flags & CF_CHECKPOINT)
00060     {
00061         char *cmdsave = mudstate.debug_cmd;
00062         mudstate.debug_cmd = (char *)"< dump >";
00063 #ifndef WIN32
00064         if (mudstate.dumping)
00065         {
00066             // There is a dump in progress. These usually happen very quickly.
00067             // We will reschedule ourselves to try again in 20 seconds.
00068             // Ordinarily, you would think "...a dump is a dump...", but some
00069             // dumps might not be the type of dump we're going to do.
00070             //
00071             nNextTimeInSeconds = 20;
00072         }
00073         else
00074 #endif // !WIN32
00075         {
00076             fork_and_dump(0);
00077         }
00078         mudstate.debug_cmd = cmdsave;
00079     }
00080 
00081     // Schedule ourselves again.
00082     //
00083     CLinearTimeAbsolute ltaNow;
00084     ltaNow.GetUTC();
00085     CLinearTimeDelta ltd;
00086     ltd.SetSeconds(nNextTimeInSeconds);
00087     mudstate.dump_counter = ltaNow + ltd;
00088     scheduler.DeferTask(mudstate.dump_counter, PRIORITY_SYSTEM, dispatch_DatabaseDump, 0, 0);
00089 }

void dispatch_FreeListReconstruction ( void *  pUnused,
int  iUnused 
)

Definition at line 23 of file timer.cpp.

References CF_DBCHECK, statedata::check_counter, confdata::check_interval, confdata::control_flags, statedata::debug_cmd, CScheduler::DeferTask(), dispatch_FreeListReconstruction(), do_dbck(), CLinearTimeAbsolute::GetUTC(), Guest, mudconf, mudstate, NOTHING, pcache_trim(), pool_reset(), PRIORITY_SYSTEM, scheduler, CLinearTimeDelta::SetSeconds(), and UNUSED_PARAMETER.

Referenced by CallBack_ShowDispatches(), dispatch_FreeListReconstruction(), do_timewarp(), and init_timer().

00024 {
00025     UNUSED_PARAMETER(pUnused);
00026     UNUSED_PARAMETER(iUnused);
00027 
00028     if (mudconf.control_flags & CF_DBCHECK)
00029     {
00030         char *cmdsave = mudstate.debug_cmd;
00031         mudstate.debug_cmd = (char *)"< dbck >";
00032         do_dbck(NOTHING, NOTHING, NOTHING, 0);
00033         Guest.CleanUp();
00034         pcache_trim();
00035         pool_reset();
00036         mudstate.debug_cmd = cmdsave;
00037     }
00038 
00039     // Schedule ourselves again.
00040     //
00041     CLinearTimeAbsolute ltaNow;
00042     ltaNow.GetUTC();
00043     CLinearTimeDelta ltd;
00044     ltd.SetSeconds(mudconf.check_interval);
00045     mudstate.check_counter = ltaNow + ltd;
00046     scheduler.DeferTask(mudstate.check_counter, PRIORITY_SYSTEM,
00047         dispatch_FreeListReconstruction, 0, 0);
00048 }

void dispatch_IdleCheck ( void *  pUnused,
int  iUnused 
)

Definition at line 93 of file timer.cpp.

References CF_IDLECHECK, check_idle(), confdata::control_flags, statedata::debug_cmd, CScheduler::DeferTask(), dispatch_IdleCheck(), CLinearTimeAbsolute::GetUTC(), statedata::idle_counter, confdata::idle_interval, mudconf, mudstate, PRIORITY_SYSTEM, scheduler, CLinearTimeDelta::SetSeconds(), and UNUSED_PARAMETER.

Referenced by CallBack_ShowDispatches(), dispatch_IdleCheck(), do_timewarp(), and init_timer().

00094 {
00095     UNUSED_PARAMETER(pUnused);
00096     UNUSED_PARAMETER(iUnused);
00097 
00098     if (mudconf.control_flags & CF_IDLECHECK)
00099     {
00100         char *cmdsave = mudstate.debug_cmd;
00101         mudstate.debug_cmd = (char *)"< idlecheck >";
00102         check_idle();
00103         mudstate.debug_cmd = cmdsave;
00104     }
00105 
00106     // Schedule ourselves again.
00107     //
00108     CLinearTimeAbsolute ltaNow;
00109     ltaNow.GetUTC();
00110     CLinearTimeDelta ltd;
00111     ltd.SetSeconds(mudconf.idle_interval);
00112     mudstate.idle_counter = ltaNow + ltd;
00113     scheduler.DeferTask(mudstate.idle_counter, PRIORITY_SYSTEM, dispatch_IdleCheck, 0, 0);
00114 }

void do_timewarp ( dbref  executor,
dbref  caller,
dbref  enactor,
int  key,
char *  arg 
)

Definition at line 280 of file timer.cpp.

References CScheduler::CancelTask(), statedata::check_counter, CScheduler::DeferTask(), dispatch_CheckEvents(), dispatch_DatabaseDump(), dispatch_FreeListReconstruction(), dispatch_IdleCheck(), do_queue(), statedata::dump_counter, statedata::events_counter, statedata::idle_counter, mudstate, mux_atol(), PRIORITY_SYSTEM, QUEUE_WARP, scheduler, CLinearTimeDelta::SetSeconds(), TWARP_CLEAN, TWARP_DUMP, TWARP_EVENTS, TWARP_IDLE, and TWARP_QUEUE.

00281 {
00282     int secs;
00283 
00284     secs = mux_atol(arg);
00285 
00286     // Sem/Wait queues
00287     //
00288     if ((key == 0) || (key & TWARP_QUEUE))
00289     {
00290         do_queue(executor, caller, enactor, QUEUE_WARP, arg);
00291     }
00292 
00293     // Once these are adjusted, we need to Cancel and reschedule the task.
00294     //
00295     CLinearTimeDelta ltd;
00296     ltd.SetSeconds(secs);
00297     if (key & TWARP_DUMP)
00298     {
00299         mudstate.dump_counter -= ltd;
00300         scheduler.CancelTask(dispatch_DatabaseDump, 0, 0);
00301         scheduler.DeferTask(mudstate.dump_counter, PRIORITY_SYSTEM, dispatch_DatabaseDump, 0, 0);
00302     }
00303     if (key & TWARP_CLEAN)
00304     {
00305         mudstate.check_counter -= ltd;
00306         scheduler.CancelTask(dispatch_FreeListReconstruction, 0, 0);
00307         scheduler.DeferTask(mudstate.check_counter, PRIORITY_SYSTEM, dispatch_FreeListReconstruction, 0, 0);
00308     }
00309     if (key & TWARP_IDLE)
00310     {
00311         mudstate.idle_counter -= ltd;
00312         scheduler.CancelTask(dispatch_IdleCheck, 0, 0);
00313         scheduler.DeferTask(mudstate.idle_counter, PRIORITY_SYSTEM, dispatch_IdleCheck, 0, 0);
00314     }
00315     if (key & TWARP_EVENTS)
00316     {
00317         mudstate.events_counter -= ltd;
00318         scheduler.CancelTask(dispatch_CheckEvents, 0, 0);
00319         scheduler.DeferTask(mudstate.events_counter, PRIORITY_SYSTEM, dispatch_CheckEvents, 0, 0);
00320     }
00321 }

void init_timer ( void   ) 

Definition at line 211 of file timer.cpp.

References confdata::cache_tick_period, statedata::check_counter, confdata::check_interval, confdata::check_offset, CScheduler::DeferTask(), dispatch_CacheTick(), dispatch_CanRestart(), dispatch_CheckEvents(), dispatch_DatabaseDump(), dispatch_FreeListReconstruction(), dispatch_IdleCheck(), statedata::dump_counter, confdata::dump_interval, confdata::dump_offset, statedata::events_counter, CLinearTimeAbsolute::GetUTC(), statedata::idle_counter, confdata::idle_interval, mudconf, mudstate, PRIORITY_OBJECT, PRIORITY_SYSTEM, scheduler, CLinearTimeDelta::SetSeconds(), time_15s, time_30s, and time_45s.

Referenced by main().

00212 {
00213     CLinearTimeAbsolute ltaNow;
00214     ltaNow.GetUTC();
00215 
00216     // Setup re-occuring Free List Reconstruction task.
00217     //
00218     CLinearTimeDelta ltd;
00219     ltd.SetSeconds((mudconf.check_offset == 0) ? mudconf.check_interval : mudconf.check_offset);
00220     mudstate.check_counter  = ltaNow + ltd;
00221     scheduler.DeferTask(mudstate.check_counter, PRIORITY_SYSTEM,
00222         dispatch_FreeListReconstruction, 0, 0);
00223 
00224     // Setup re-occuring Database Dump task.
00225     //
00226     ltd.SetSeconds((mudconf.dump_offset == 0) ? mudconf.dump_interval : mudconf.dump_offset);
00227     mudstate.dump_counter  = ltaNow + ltd;
00228     scheduler.DeferTask(mudstate.dump_counter, PRIORITY_SYSTEM,
00229         dispatch_DatabaseDump, 0, 0);
00230 
00231     // Setup re-occuring Idle Check task.
00232     //
00233     ltd.SetSeconds(mudconf.idle_interval);
00234     mudstate.idle_counter   = ltaNow + ltd;
00235     scheduler.DeferTask(mudstate.idle_counter, PRIORITY_SYSTEM,
00236         dispatch_IdleCheck, 0, 0);
00237 
00238     // Setup re-occuring Check Events task.
00239     //
00240     mudstate.events_counter = ltaNow + time_15s;
00241     scheduler.DeferTask(mudstate.events_counter, PRIORITY_SYSTEM,
00242         dispatch_CheckEvents, 0, 0);
00243 
00244 #ifndef MEMORY_BASED
00245     // Setup re-occuring cache_tick task.
00246     //
00247     ltd.SetSeconds(0);
00248     if (mudconf.cache_tick_period <= ltd)
00249     {
00250         mudconf.cache_tick_period.SetSeconds(1);
00251     }
00252     scheduler.DeferTask(ltaNow+mudconf.cache_tick_period, PRIORITY_SYSTEM,
00253         dispatch_CacheTick, 0, 0);
00254 #endif // !MEMORY_BASED
00255 
00256 #if 0
00257     // Setup comsys channel scrubbing.
00258     //
00259     scheduler.DeferTask(ltaNow+time_45s, PRIORITY_SYSTEM, dispatch_CleanChannels, 0, 0);
00260 #endif // 0
00261 
00262     // Setup one-shot task to enable restarting 10 seconds after startmux.
00263     //
00264     scheduler.DeferTask(ltaNow+time_15s, PRIORITY_OBJECT, dispatch_CanRestart, 0, 0);
00265 
00266 #ifdef WIN32
00267     // Setup Periodic QueryPerformance Calibration.
00268     //
00269     scheduler.DeferTask(ltaNow+time_30s, PRIORITY_SYSTEM,
00270         dispatch_CalibrateQueryPerformance, 0, 0);
00271 
00272 #endif // WIN32
00273 }


Variable Documentation

CScheduler scheduler

Definition at line 19 of file timer.cpp.

Referenced by dispatch_CacheTick(), dispatch_CheckEvents(), dispatch_DatabaseDump(), dispatch_FreeListReconstruction(), dispatch_IdleCheck(), do_global(), do_ps(), do_queue(), do_timewarp(), halt_que(), init_timer(), nfy_que(), process_preload(), save_command(), shovechars(), sighandler(), Task_ProcessCommand(), and wait_que().


Generated on Mon May 28 04:40:23 2007 for MUX by  doxygen 1.4.7