/* * Take the delta between the present values and the last recorded * values, storing the present values in the 'last' structure, and * the delta values in the 'cur' structure. */ void drvswap(void) { u_int64_t tmp; size_t i; #define SWAP(fld) do { \ tmp = cur.fld; \ cur.fld -= last.fld; \ last.fld = tmp; \ } while (/* CONSTCOND */0) for (i = 0; i < ndrive; i++) { struct timeval tmp_timer; if (!cur.select[i]) continue; /* Delta Values. */ SWAP(rxfer[i]); SWAP(wxfer[i]); SWAP(seek[i]); SWAP(rbytes[i]); SWAP(wbytes[i]); /* Delta Time. */ timerclear(&tmp_timer); timerset(&(cur.time[i]), &tmp_timer); timersub(&tmp_timer, &(last.time[i]), &(cur.time[i])); timerclear(&(last.time[i])); timerset(&tmp_timer, &(last.time[i])); } }
Timer* addclock0link(void (*f)(void), int ms) { Timer *nt; uvlong when; if(!timersinited) panic("addclock0link: timersinit not called yet"); /* Synchronize to hztimer if ms is 0 */ nt = malloc(sizeof(Timer)); if(nt == nil) error(Enomem); if(ms == 0) ms = 1000/HZ; nt->tns = (vlong)ms*1000000LL; nt->tmode = Tperiodic; nt->tt = nil; nt->tf = (void (*)(Ureg*, Timer*))f; ilock(&timers[0]); when = tadd(&timers[0], nt); if(when) timerset(when); iunlock(&timers[0]); return nt; }
int _stdc timeup(long timer) { long now; now=timerset (0); if (now < (timer-65536L)) now += 360000L; return ((now-timer) >= 0L); }
void _stdc timer(unsigned int duration) { long tim; tim=timerset(duration); while (! timeup(tim)) #ifdef UNIX sleep(0) #endif ; }
void timerintr(Ureg *u, Tval) { Timer *t; Timers *tt; uvlong when, now; int count, callhzclock; intrcount[m->machno]++; callhzclock = 0; tt = &timers[m->machno]; now = fastticks(nil); if(now == 0) panic("timerintr: zero fastticks()"); ilock(tt); count = Maxtimerloops; while((t = tt->head) != nil){ /* * No need to ilock t here: any manipulation of t * requires tdel(t) and this must be done with a * lock to tt held. We have tt, so the tdel will * wait until we're done */ when = t->twhen; if(when > now){ timerset(when); iunlock(tt); if(callhzclock) hzclock(u); return; } tt->head = t->tnext; assert(t->tt == tt); t->tt = nil; fcallcount[m->machno]++; iunlock(tt); if(t->tf) (*t->tf)(u, t); else callhzclock++; ilock(tt); if(t->tmode == Tperiodic) tadd(tt, t); if (--count <= 0) { count = Maxtimerloops; iprint("timerintr: probably stuck in while loop; " "scrutinise clock.c or use faster cycle " "counter\n"); } } iunlock(tt); }
void timerdel(Timer *dt) { Timers *tt; int64_t when; ilock(&dt->l); if(tt = dt->tt){ ilock(&tt->l); when = tdel(dt); if(when && tt == &timers[machp()->machno]) timerset(tt->head->twhen); iunlock(&tt->l); } iunlock(&dt->l); }
void timerdel(Timer *dt) { Timers *tt; uvlong when; ilock(dt); if(tt = dt->tt){ ilock(tt); when = tdel(dt); if(when && tt == &timers[m->machno]) timerset(tt->head->twhen); iunlock(tt); } iunlock(dt); }
void timerintr(Ureg *u, Tval) { Timer *t; Timers *tt; uvlong when, now; int callhzclock; static int sofar; intrcount[m->machno]++; callhzclock = 0; tt = &timers[m->machno]; now = fastticks(nil); ilock(tt); while(t = tt->head){ /* * No need to ilock t here: any manipulation of t * requires tdel(t) and this must be done with a * lock to tt held. We have tt, so the tdel will * wait until we're done */ when = t->twhen; if(when > now){ timerset(when); iunlock(tt); if(callhzclock) hzclock(u); return; } tt->head = t->tnext; assert(t->tt == tt); t->tt = nil; fcallcount[m->machno]++; iunlock(tt); if(t->tf) (*t->tf)(u, t); else callhzclock++; ilock(tt); if(t->tmode == Tperiodic) tadd(tt, t); } iunlock(tt); }
word Shall_We_Continue(word timeout, char *do_what) { word pause, ret; int ch; long tmr; ret=TRUE; Putc('\n'); Printf(pause_msg, pause=timeout, do_what); while (pause-- > 0) { Printf(pause_time, pause); tmr=timerset(100); vbuf_flush(); while (!timeup(tmr) && !Mdm_keyp()) Giveaway_Slice(); if (Mdm_keyp()) { ch=Mdm_getcw(); if (ch=='\x0d') /* C/R */ break; else if (ch=='\x1b') /* ESC */ { /* Puts(xferaborted);*/ ret=FALSE; break; } } } Puts("\r" CLEOL); WhiteN(); return ret; }
/* add or modify a timer */ void timeradd(Timer *nt) { Timers *tt; int64_t when; /* Must lock Timer struct before Timers struct */ ilock(&nt->l); if(tt = nt->tt){ ilock(&tt->l); tdel(nt); iunlock(&tt->l); } tt = &timers[machp()->machno]; ilock(&tt->l); when = tadd(tt, nt); if(when) timerset(when); iunlock(&tt->l); iunlock(&nt->l); }
/* add or modify a timer */ void timeradd(Timer *nt) { Timers *tt; vlong when; /* Must lock Timer struct before Timers struct */ ilock(nt); if(tt = nt->tt){ ilock(tt); tdel(nt); iunlock(tt); } tt = &timers[m->machno]; ilock(tt); when = tadd(tt, nt); if(when) timerset(when); iunlock(tt); iunlock(nt); }
Timer* addclock0link(void (*f)(void), int ms) { Timer *nt; int64_t when; /* Synchronize to hztimer if ms is 0 */ nt = malloc(sizeof(Timer)); if(ms == 0) ms = 1000/HZ; nt->tns = (int64_t)ms*1000000LL; nt->tmode = Tperiodic; nt->tt = nil; nt->tf = (void (*)(Ureg*, Timer*))f; ilock(&timers[0].l); when = tadd(&timers[0], nt); if(when) timerset(when); iunlock(&timers[0].l); return nt; }
static void near Clear_MNP_Garbage(void) { long done=timerset(500); int state=0; int ch; /* Wait for five seconds, or until we get two <cr>s or two <esc>s */ while (!timeup(done)) { if ((ch=mdm_getc())==-1) Giveaway_Slice(); else switch (state) { case 2: if (ch=='\r') return; else state=0; break; case 1: if (ch=='\x1b') return; else state=0; break; case 0: default: if (ch=='\x1b') state=1; else if (ch=='\r') state=2; else state=0; break; } } }
static int near WFC_IdleInternal(void) { static time_t last_ct=-1L; union stamp_combo now; time_t ct; if (loc_kbhit()) { switch (loc_getch()) { case K_ONEMORE: switch (loc_getch()) { case K_ALTX: kexit=TRUE; return 1; case K_ALTJ: #ifdef TTYVIDEO if (displaymode==VIDEO_IBM) #endif { if (dspwin) { WinClose(dspwin); dspwin=NULL; } VidCls(CGRAY | _BLACK); } Shell_To_Dos(); break; case K_ALTI: WFC_Init_Modem(); Update_Status(wfc_waiting); break; case K_ALTB: break; case K_ALTK: local=TRUE; baud=0L; return 1; } break; default: logit(log_wfc_keybjunk); } } ct=time(NULL); Get_Dos_Date(&now); if (now.dos_st.date != today.dos_st.date) { today=now; bstats.today_callers=0; Update_Callers(); Read_Event_File(event_num); Get_Next_Event(); } if (ct >= next_event_time) { if (!next_event.erl) Get_Next_Event(); else { next_event.flags |= EFLAG_DONE; Write_One_Event(&next_event); do_next_event=TRUE; return 1; } } if (last_ct != ct) { Update_Event_Time(); DrawMaxHeader(); if (init_tmr==-1) init_tmr=timerset(INIT_TIME); } /* If it's time to reinitialize the modem, do so now. */ #if (COMMAPI_VER > 1) if(ComIsAModem(hcModem)) { if (timeup(init_tmr)) { WFC_Init_Modem(); Update_Status(wfc_waiting); init_tmr=timerset(INIT_TIME); } Check_For_Message(NULL, NULL); } #endif Giveaway_Slice(); #if (COMMAPI_VER > 1) if(ComIsAModem(hcModem)) sleep(1); #endif return 0; }
static char * near Get_Modem_Response(void) { #define RESP_TIMEOUT 500 #define MAX_RESP_LEN 60 static char resp[MAX_RESP_LEN]; char *rsptr; long tm1; mdm_dtr(DTR_UP); for (*resp='\0';*resp=='\0';) { tm1=timerset(RESP_TIMEOUT); for (rsptr=resp; !timeup(tm1) && rsptr < resp+MAX_RESP_LEN;) { #ifndef __MSDOS__ if (!loc_kbhit()) if(ComIsAModem(hcModem)) ComRxWait(hcModem, 1000L); /* block for 1 second or until char avail*/ #endif if (! mdm_avail()) { /* As long as the string is empty, keep resetting the five-second * * timer. */ if (rsptr==resp) tm1=timerset(RESP_TIMEOUT); if (WFC_IdleInternal()) return NULL; } else { *rsptr=(char)mdm_ggetcw(); if (*rsptr=='\r' || *rsptr=='\n') break; rsptr++; } } /* Cap string */ *rsptr='\0'; /* Suppress any 'OK' messages */ /* if (eqstri(resp,"ok")) *resp='\0';*/ /* Reset the modem initialization timer so that we don't * try to reinit in the middle of a ring! */ init_tmr=timerset(INIT_TIME); /* If we got a response... */ if (*resp) { #ifdef TTYVIDEO if (displaymode==VIDEO_IBM) { #endif WinPutc(win_modem,'\r'); WinPutc(win_modem,'\n'); WinPutc(win_modem,' '); WinPuts(win_modem,resp); WinSync(win_modem,FALSE); #ifdef TTYVIDEO } else logit("#%s", cfancy_str(resp)); #endif } } return resp; }