#include "copyright.h"
#include "config.h"
#include <signal.h>
#include "mudconf.h"
#include "db.h"
#include "interface.h"
#include "match.h"
#include "externs.h"
#include "command.h"
#include "attrs.h"
#include "powers.h"
Include dependency graph for timer.c:
Go to the source code of this file.
Defines | |
#define | DPSET(n) |
Functions | |
void | pool_reset (void) |
void | do_second (void) |
void | fork_and_dump (int key) |
unsigned int | alarm (unsigned int seconds) |
void | pcache_trim (void) |
void | check_events (void) |
void | timer_callback (int fd, short event, void *arg) |
void | init_timer () |
void | check_idle (void) |
void | dispatch () |
void | do_timewarp (dbref player, dbref cause, int key, char *arg) |
Variables | |
static struct timeval | tv = { 0, 100000 } |
static struct event | timer_event |
#define DPSET | ( | n | ) |
unsigned int alarm | ( | unsigned int | seconds | ) |
void check_events | ( | void | ) |
Definition at line 83 of file timer.c.
References A_DAILY, A_HOURLY, did_it(), DO_WHOLE_DB, ET_DAILY, confdata::events_daily_hour, statedata::events_flag, statedata::events_lasthour, Flags2, Going, HAS_DAILY, HAS_HOURLY, ITER_PARENTS, mudconf, mudstate, statedata::now, and Owner.
Referenced by dispatch().
00084 { 00085 struct tm *ltime; 00086 dbref thing, parent; 00087 int lev; 00088 00089 ltime = localtime(&mudstate.now); 00090 if((ltime->tm_hour == mudconf.events_daily_hour) 00091 && !(mudstate.events_flag & ET_DAILY)) { 00092 mudstate.events_flag = mudstate.events_flag | ET_DAILY; 00093 DO_WHOLE_DB(thing) { 00094 if(Going(thing)) 00095 continue; 00096 00097 ITER_PARENTS(thing, parent, lev) { 00098 if(Flags2(thing) & HAS_DAILY) { 00099 did_it(Owner(thing), thing, 0, NULL, 0, NULL, A_DAILY, 00100 (char **) NULL, 0); 00101 00102 break; 00103 } 00104 } 00105 } 00106 } 00107 if(ltime->tm_hour != mudstate.events_lasthour) { 00108 if(mudstate.events_lasthour >= 0) { 00109 /* Run hourly maintenance */ 00110 DO_WHOLE_DB(thing) { 00111 if(Going(thing)) 00112 continue; 00113 00114 ITER_PARENTS(thing, parent, lev) { 00115 if(Flags2(thing) & HAS_HOURLY) { 00116 did_it(Owner(thing), thing, 0, NULL, 0, NULL, 00117 A_HOURLY, (char **) NULL, 0); 00118 00119 break; 00120 } 00121 } 00122 } 00123 00124 } 00125 mudstate.events_lasthour = ltime->tm_hour; 00126 } 00127 if(ltime->tm_hour == 23) { /* 00128 * Nightly resetting 00129 */ 00130 mudstate.events_flag = 0; 00131 } 00132 }
void check_idle | ( | void | ) |
Definition at line 56 of file timer.c.
References Can_Idle, confdata::conn_timeout, descriptor_data::connected_at, DARK, Dark, DESC_SAFEITER_ALL, DS_AUTODARK, DS_CONNECTED, Flags, descriptor_data::flags, confdata::idle_timeout, confdata::idle_wiz_dark, descriptor_data::last_time, mudconf, mudstate, statedata::now, descriptor_data::player, queue_string(), R_TIMEOUT, s_Flags, shutdownsock(), and descriptor_data::timeout.
Referenced by dispatch().
00057 { 00058 DESC *d, *dnext; 00059 time_t idletime; 00060 00061 DESC_SAFEITER_ALL(d, dnext) { 00062 if(d->flags & DS_CONNECTED) { 00063 idletime = mudstate.now - d->last_time; 00064 if((idletime > d->timeout) && !Can_Idle(d->player)) { 00065 queue_string(d, "*** Inactivity Timeout ***\r\n"); 00066 shutdownsock(d, R_TIMEOUT); 00067 } else if(mudconf.idle_wiz_dark && 00068 (idletime > mudconf.idle_timeout) && Can_Idle(d->player) 00069 && !Dark(d->player)) { 00070 s_Flags(d->player, Flags(d->player) | DARK); 00071 d->flags |= DS_AUTODARK; 00072 } 00073 } else { 00074 idletime = mudstate.now - d->connected_at; 00075 if(idletime > mudconf.conn_timeout) { 00076 queue_string(d, "*** Login Timeout ***\r\n"); 00077 shutdownsock(d, R_TIMEOUT); 00078 } 00079 } 00080 } 00081 }
void dispatch | ( | ) |
Definition at line 135 of file timer.c.
References statedata::alarm_triggered, CF_CHECKPOINT, CF_DBCHECK, CF_EVENTCHECK, CF_IDLECHECK, statedata::check_counter, check_events(), check_idle(), confdata::check_interval, confdata::control_flags, statedata::debug_cmd, do_dbck(), do_second(), DPSET, statedata::dump_counter, confdata::dump_interval, statedata::events_counter, fork_and_dump(), confdata::have_specials, statedata::idle_counter, confdata::idle_interval, statedata::mstat_curr, statedata::mstat_idrss, statedata::mstat_isrss, statedata::mstat_ixrss, statedata::mstat_secs, statedata::mstats_counter, mudconf, mudstate, NOTHING, statedata::now, pcache_trim(), time(), and UpdateSpecialObjects().
Referenced by timer_callback().
00136 { 00137 char *cmdsave; 00138 00139 #ifdef USE_PYTHON 00140 mudstate.debug_cmd = "< Python >"; 00141 updatePython(); 00142 #endif 00143 00144 cmdsave = mudstate.debug_cmd; 00145 DPSET("< dispatch >"); 00146 /* 00147 * this routine can be used to poll from interface.c 00148 */ 00149 00150 if(!mudstate.alarm_triggered) 00151 return; 00152 mudstate.alarm_triggered = 0; 00153 mudstate.now = time(NULL); 00154 00155 do_second(); 00156 00157 /* 00158 * Free list reconstruction 00159 */ 00160 00161 if((mudconf.control_flags & CF_DBCHECK) && 00162 (mudstate.check_counter <= mudstate.now)) { 00163 mudstate.check_counter = mudconf.check_interval + mudstate.now; 00164 DPSET("< dbck >"); 00165 do_dbck(NOTHING, NOTHING, 0); 00166 pcache_trim(); 00167 } 00168 /* 00169 * Database dump routines 00170 */ 00171 00172 if((mudconf.control_flags & CF_CHECKPOINT) && 00173 (mudstate.dump_counter <= mudstate.now)) { 00174 mudstate.dump_counter = mudconf.dump_interval + mudstate.now; 00175 DPSET("< dump >"); 00176 fork_and_dump(0); 00177 } 00178 /* 00179 Mech stuff ; hopefully it means once ~per sec, although you 00180 can never be sure - therefore, the code does 'timejumps' as 00181 needed (see UpdateSpecialObjects for details) 00182 */ 00183 00184 if(mudconf.have_specials) 00185 UpdateSpecialObjects(); 00186 00187 /* 00188 * Idle user check 00189 */ 00190 00191 if((mudconf.control_flags & CF_IDLECHECK) && 00192 (mudstate.idle_counter <= mudstate.now)) { 00193 mudstate.idle_counter = mudconf.idle_interval + mudstate.now; 00194 DPSET("< idlecheck >"); 00195 check_idle(); 00196 00197 } 00198 /* 00199 * Check for execution of attribute events 00200 */ 00201 00202 if((mudconf.control_flags & CF_EVENTCHECK) && 00203 (mudstate.events_counter <= mudstate.now)) { 00204 mudstate.events_counter = 900 + mudstate.now; 00205 DPSET("< eventcheck >"); 00206 check_events(); 00207 } 00208 #ifdef HAVE_GETRUSAGE 00209 /* 00210 * Memory use stats 00211 */ 00212 00213 if(mudstate.mstats_counter <= mudstate.now) { 00214 00215 int curr; 00216 00217 mudstate.mstats_counter = 15 + mudstate.now; 00218 curr = mudstate.mstat_curr; 00219 if(mudstate.now > mudstate.mstat_secs[curr]) { 00220 00221 struct rusage usage; 00222 00223 curr = 1 - curr; 00224 getrusage(RUSAGE_SELF, &usage); 00225 mudstate.mstat_ixrss[curr] = usage.ru_ixrss; 00226 mudstate.mstat_idrss[curr] = usage.ru_idrss; 00227 mudstate.mstat_isrss[curr] = usage.ru_isrss; 00228 mudstate.mstat_secs[curr] = mudstate.now; 00229 mudstate.mstat_curr = curr; 00230 } 00231 } 00232 #endif 00233 00234 mudstate.debug_cmd = cmdsave; 00235 }
void do_second | ( | void | ) |
Definition at line 862 of file cque.c.
References add_to(), bque::attr, CF_DEQUEUE, bque::comm, confdata::control_flags, cque_enqueue(), statedata::debug_cmd, mudconf, mudstate, bque::next, NOTHING, statedata::now, bque::player, printk, statedata::qsemfirst, statedata::qsemlast, bque::sem, and bque::waittime.
Referenced by dispatch(), do_queue(), and process_preload().
00863 { 00864 BQUE *trail, *point, *next; 00865 char *cmdsave; 00866 00867 /* 00868 * move contents of low priority queue onto end of normal one this 00869 * helps to keep objects from getting out of control since 00870 * its affects on other objects happen only after one 00871 * second this should allow @halt to be type before 00872 * getting blown away by scrolling text 00873 */ 00874 00875 if((mudconf.control_flags & CF_DEQUEUE) == 0) 00876 return; 00877 00878 cmdsave = mudstate.debug_cmd; 00879 mudstate.debug_cmd = (char *) "< do_second >"; 00880 00881 /* 00882 * Note: the point->waittime test would be 0 except the command is 00883 * being put in the low priority queue to be done in one 00884 * second anyways 00885 */ 00886 00887 /* 00888 * Check the semaphore queue for expired timed-waits 00889 */ 00890 00891 for(point = mudstate.qsemfirst, trail = NULL; point; point = next) { 00892 if(point->waittime == 0) { 00893 next = (trail = point)->next; 00894 continue; /* 00895 * Skip if not timed-wait 00896 */ 00897 } 00898 if(point->waittime <= mudstate.now) { 00899 if(trail != NULL) 00900 trail->next = next = point->next; 00901 else 00902 mudstate.qsemfirst = next = point->next; 00903 if(point == mudstate.qsemlast) 00904 mudstate.qsemlast = trail; 00905 add_to(point->sem, -1, point->attr); 00906 point->sem = NOTHING; 00907 point->waittime = 0; 00908 printk("promoting, %d/%s", point->player, point->comm); 00909 cque_enqueue(point->player, point); 00910 } else 00911 next = (trail = point)->next; 00912 } 00913 mudstate.debug_cmd = cmdsave; 00914 return; 00915 }
Adjust various internal timers.
Definition at line 247 of file timer.c.
References statedata::check_counter, do_queue(), statedata::dump_counter, statedata::events_counter, statedata::idle_counter, mudstate, QUEUE_WARP, TWARP_CLEAN, TWARP_DUMP, TWARP_EVENTS, TWARP_IDLE, and TWARP_QUEUE.
00248 { 00249 int secs; 00250 00251 secs = atoi(arg); 00252 00253 if((key == 0) || (key & TWARP_QUEUE)) /* 00254 * Sem/Wait queues 00255 */ 00256 do_queue(player, cause, QUEUE_WARP, arg); 00257 if(key & TWARP_DUMP) 00258 mudstate.dump_counter -= secs; 00259 if(key & TWARP_CLEAN) 00260 mudstate.check_counter -= secs; 00261 if(key & TWARP_IDLE) 00262 mudstate.idle_counter -= secs; 00263 if(key & TWARP_EVENTS) 00264 mudstate.events_counter -= secs; 00265 }
void fork_and_dump | ( | int | key | ) |
void init_timer | ( | void | ) |
Definition at line 32 of file timer.c.
References statedata::check_counter, confdata::check_interval, confdata::check_offset, statedata::dump_counter, confdata::dump_interval, confdata::dump_offset, statedata::events_counter, statedata::idle_counter, confdata::idle_interval, statedata::mstats_counter, mudconf, mudstate, statedata::now, time(), timer_callback(), timer_event, and tv.
Referenced by main().
00033 { 00034 mudstate.now = time(NULL); 00035 mudstate.dump_counter = 00036 ((mudconf.dump_offset == 00037 0) ? mudconf.dump_interval : mudconf.dump_offset) + mudstate.now; 00038 mudstate.check_counter = 00039 ((mudconf.check_offset == 00040 0) ? mudconf.check_interval : mudconf.check_offset) + mudstate.now; 00041 mudstate.idle_counter = mudconf.idle_interval + mudstate.now; 00042 mudstate.mstats_counter = 15 + mudstate.now; 00043 mudstate.events_counter = 900 + mudstate.now; 00044 evtimer_set(&timer_event, timer_callback, NULL); 00045 evtimer_add(&timer_event, &tv); 00046 }
void pcache_trim | ( | void | ) |
Definition at line 97 of file player_c.c.
References player_cache::cflags, player_cache::next, pcache_head, pcache_save(), pcache_tree, PF_DEAD, PF_REF, player_cache::queue, and rb_delete().
Referenced by dispatch().
00098 { 00099 PCACHE *pp, *pplast, *ppnext; 00100 return; 00101 00102 pp = pcache_head; 00103 pplast = NULL; 00104 while (pp) { 00105 if(!(pp->cflags & PF_DEAD) && (pp->queue || (pp->cflags & PF_REF))) { 00106 pp->cflags &= ~PF_REF; 00107 pplast = pp; 00108 pp = pp->next; 00109 } else { 00110 ppnext = pp->next; 00111 if(pplast) 00112 pplast->next = ppnext; 00113 else 00114 pcache_head = ppnext; 00115 if(!(pp->cflags & PF_DEAD)) { 00116 pcache_save(pp); 00117 rb_delete(pcache_tree, (void *)pp->player); 00118 } 00119 free(pp); 00120 pp = ppnext; 00121 } 00122 } 00123 }
void pool_reset | ( | void | ) |
void timer_callback | ( | int | fd, | |
short | event, | |||
void * | arg | |||
) |
Definition at line 237 of file timer.c.
References statedata::alarm_triggered, dispatch(), mudstate, timer_event, and tv.
Referenced by init_timer().
00238 { 00239 mudstate.alarm_triggered = 1; 00240 evtimer_add(&timer_event, &tv); 00241 dispatch(); 00242 }
struct event timer_event [static] |
struct timeval tv = { 0, 100000 } [static] |