/*===========================================================================* * do_setalarm * *===========================================================================*/ PUBLIC int do_setalarm(struct proc * caller, message * m_ptr) { /* A process requests a synchronous alarm, or wants to cancel its alarm. */ long exp_time; /* expiration time for this alarm */ int use_abs_time; /* use absolute or relative time */ timer_t *tp; /* the process' timer structure */ clock_t uptime; /* placeholder for current uptime */ /* Extract shared parameters from the request message. */ exp_time = m_ptr->ALRM_EXP_TIME; /* alarm's expiration time */ use_abs_time = m_ptr->ALRM_ABS_TIME; /* flag for absolute time */ if (! (priv(caller)->s_flags & SYS_PROC)) return(EPERM); /* Get the timer structure and set the parameters for this alarm. */ tp = &(priv(caller)->s_alarm_timer); tmr_arg(tp)->ta_int = caller->p_endpoint; tp->tmr_func = cause_alarm; /* Return the ticks left on the previous alarm. */ uptime = get_uptime(); if ((tp->tmr_exp_time != TMR_NEVER) && (uptime < tp->tmr_exp_time) ) { m_ptr->ALRM_TIME_LEFT = (tp->tmr_exp_time - uptime); } else { m_ptr->ALRM_TIME_LEFT = 0; } /* Finally, (re)set the timer depending on the expiration time. */ if (exp_time == 0) { reset_timer(tp); } else { tp->tmr_exp_time = (use_abs_time) ? exp_time : exp_time + get_uptime(); set_timer(tp, tp->tmr_exp_time, tp->tmr_func); } return(OK); }
int main(int argc, char **argv) { int ret; settings_init(); if (set_signal_handler(signals) == -1) { return -1; } tc_time_init(); if (read_args(argc, argv) == -1) { return -1; } if (srv_settings.log_path == NULL) { srv_settings.log_path = "error_intercept.log"; } if (tc_log_init(srv_settings.log_path) == -1) { return -1; } ret = tc_event_loop_init(&s_event_loop, MAX_FD_NUM); if (ret == TC_EVENT_ERROR) { tc_log_info(LOG_ERR, 0, "event loop init failed"); return -1; } /* output debug info */ output_for_debug(); if (set_details() == -1) { return -1; } if (interception_init(&s_event_loop, srv_settings.bound_ip, srv_settings.port) == TC_ERROR) { return -1; } if (set_timer() == -1) { return -1; } #if (INTERCEPT_COMBINED) tc_event_timer_add(&s_event_loop, CHECK_INTERVAL, interception_push); #endif tc_event_timer_add(&s_event_loop, OUTPUT_INTERVAL, interception_output_stat); /* run now */ tc_event_process_cycle(&s_event_loop); server_release_resources(); return 0; }
//正常关闭RUDP SOCKET void RUDPSocket::close() { switch(state_) { case RUDP_CONNECTING: case RUDP_CONNECTED: if(event_handler_ != NULL) { event_handler_->rudp_close_event(rudp_id_); } //发送SYN RUDP_INFO("close rudp socket, state = RUDP_FIN_STATE, rudp id = " << rudp_id_); set_state(RUDP_FIN_STATE); RUDP_DEBUG("send fin, rudp socket id = " << rudp_id_); send_fin(); set_timer(ccc_.get_rtt() + TIMER_MIN_DELAY); send_count_ ++; break; case RUDP_FIN2_STATE: set_state(RUDP_CLOSE); break; } }
static bool vtimer_cntp_cval(struct cpu_user_regs *regs, uint64_t *r, bool read) { struct vcpu *v = current; if ( !ACCESS_ALLOWED(regs, EL0PTEN) ) return false; if ( read ) { *r = ns_to_ticks(v->arch.phys_timer.cval); } else { v->arch.phys_timer.cval = ticks_to_ns(*r); if ( v->arch.phys_timer.ctl & CNTx_CTL_ENABLE ) { v->arch.phys_timer.ctl &= ~CNTx_CTL_PENDING; set_timer(&v->arch.phys_timer.timer, v->arch.phys_timer.cval + v->domain->arch.phys_timer_base.offset); } } return true; }
static bool vtimer_cntp_tval(struct cpu_user_regs *regs, uint32_t *r, bool read) { struct vcpu *v = current; s_time_t now; if ( !ACCESS_ALLOWED(regs, EL0PTEN) ) return false; now = NOW() - v->domain->arch.phys_timer_base.offset; if ( read ) { *r = (uint32_t)(ns_to_ticks(v->arch.phys_timer.cval - now) & 0xffffffffull); } else { v->arch.phys_timer.cval = now + ticks_to_ns(*r); if ( v->arch.phys_timer.ctl & CNTx_CTL_ENABLE ) { v->arch.phys_timer.ctl &= ~CNTx_CTL_PENDING; set_timer(&v->arch.phys_timer.timer, v->arch.phys_timer.cval + v->domain->arch.phys_timer_base.offset); } } return true; }
static bool vtimer_cntp_ctl(struct cpu_user_regs *regs, uint32_t *r, bool read) { struct vcpu *v = current; if ( !ACCESS_ALLOWED(regs, EL0PTEN) ) return false; if ( read ) { *r = v->arch.phys_timer.ctl; } else { uint32_t ctl = *r & ~CNTx_CTL_PENDING; if ( ctl & CNTx_CTL_ENABLE ) ctl |= v->arch.phys_timer.ctl & CNTx_CTL_PENDING; v->arch.phys_timer.ctl = ctl; if ( v->arch.phys_timer.ctl & CNTx_CTL_ENABLE ) { set_timer(&v->arch.phys_timer.timer, v->arch.phys_timer.cval + v->domain->arch.phys_timer_base.offset); } else stop_timer(&v->arch.phys_timer.timer); } return true; }
int main (int argc, char *argv[]) { sigcb (SIGALRM, wrap (timer_event)); set_timer (); amain (); }
int main(int argc, char **argv) { extern int errno; int i, seconds; char * endptr; char **newargv; i = parse_options(argc, argv); errno = 0; seconds = (unsigned int) strtoul(argv[i], &endptr, 10); if (errno || &endptr[0] == argv[i]) usage("Invalid seconds parameter\n"); /* grab command [args ...] */ newargv = argv + (i + 1); /* schedule alarm */ if (xcpu) { if (rlim_cpu(seconds) == -1) { perror("rlimit cpu"); exit(1); } } else { if (set_timer(seconds, timer_type, recur) == -1) { perror("setitimer"); exit(1); } } execvp(newargv[0], newargv); perror("exec"); exit(1); }
static void switcher_led_timer(void *opaque) { static struct timer_t *t = NULL; struct timeval tv; static int onoff = 0; opaque = opaque; if (onoff == 1 && (!mouse_grab_domain || !keyboard_grab_domain || mouse_grab_domain == keyboard_grab_domain)) { if (t) { free_timer(t); t = NULL; } return; } input_leds(onoff); onoff = !onoff; if (t == NULL) t = set_new_timer(switcher_led_timer, NULL); gettimeofday(&tv, NULL); tv.tv_usec += 500 * 1000; if (tv.tv_usec > 1000000) { tv.tv_usec -= 1000000; tv.tv_sec++; } set_timer(t, &tv); }
/* * Check if and when lwIP has its next timeout, and set or cancel our timer * accordingly. */ static void set_lwip_timer(void) { uint32_t next_timeout; clock_t ticks; /* Ask lwIP when the next alarm is supposed to go off, if any. */ next_timeout = sys_timeouts_sleeptime(); /* * Set or update the lwIP timer. We rely on set_timer() asking the * kernel for an alarm only if the timeout is different from the one we * gave it last time (if at all). However, due to conversions between * absolute and relative times, and the fact that we cannot guarantee * that the uptime itself does not change while executing these * routines, set_timer() will sometimes be issuing a kernel call even * if the alarm has not changed. Not a huge deal, but fixing this will * require a different interface to lwIP and/or the timers library. */ if (next_timeout != (uint32_t)-1) { /* * Round up the next timeout (which is in milliseconds) to the * number of clock ticks to add to the current time. Avoid any * potential for overflows, no matter how unrealistic.. */ if (next_timeout > TMRDIFF_MAX / sys_hz()) ticks = TMRDIFF_MAX; else ticks = (next_timeout * sys_hz() + 999) / 1000; set_timer(&lwip_timer, ticks, expire_lwip_timer, 0 /*unused*/); } else cancel_timer(&lwip_timer); /* not really needed.. */ }
void init_scheduling(void) { balance_timeout = BALANCE_TIMEOUT * sys_hz(); srandom(1000); init_timer(&sched_timer); set_timer(&sched_timer, balance_timeout, balance_queues, 0); }
static int32_t ldh_src_init(media_src *src) { ld_src *ld = (ld_src*)src; ldh_src *ldh = (ldh_src*)ld; ld->idx[ST_VIDEO] = ST_MAX; ld->idx[ST_AUDIO] = ST_MAX; ld->ldl = 0; ld->break_off = 0; ld->u = NULL; ldh->state = INIT; ldh->flags = 0; INIT_LIST_HEAD(&ldh->frm_list); ldh->frm_count = 0; ldh->ldh_lock = LOCK_NEW(); ldh->next_frame = NULL; ldh->err = 0; ldh->last_ts = 0; ldh->scale = 1; ldh->timer = set_timer(10, ldh_stm_timer, ldh_stm_timer_del, ldh); if (!ldh->timer) { LOCK_DEL(ldh->ldh_lock); return -ENOMEM; } media_src_ref(src); return 0; }
void start_scan_sambaserver(int use_sys_timer) { //- Remove all smb_srv_info_t *c; for (c = smb_srv_info_list; c; c = c->next) { Cdbg(DBE, "remove , ip=[%s]\n", c->ip->ptr); DLIST_REMOVE(smb_srv_info_list,c); free(c); c = smb_srv_info_list; } free(smb_srv_info_list); init_a_srvInfo(); g_useSystemTimer = use_sys_timer; g_bInitialize = 1; #ifdef _USEMYTIMER if(g_useSystemTimer==0){ Cdbg(DBE, "create timer\n"); timer_t arp_timer = create_timer(TT_SIGUSR2); install_sighandler(TT_SIGUSR2, on_arpping_timer_handler); set_timer(arp_timer, ARP_TIME_INTERVAL); } #endif }
Frames_Play(LCUI_Frames *frames) /* 功能:播放动画 */ { int i, total; LCUI_Frames *tmp_ptr; if( !frames ) { return -1; } frames->state = 1; if(__timer_id == -1){ Queue_Init( &frames_stream, sizeof(LCUI_Frames), NULL ); Queue_UsingPointer( &frames_stream ); __timer_id = set_timer( 50, Process_Frames, TRUE ); } /* 检查该动画是否已存在 */ Queue_Lock( &frames_stream ); total = Queue_GetTotal( &frames_stream ); for( i=0; i<total; ++i ) { tmp_ptr = Queue_Get( &frames_stream, i ); if( tmp_ptr == frames ) { break; } } Queue_Unlock( &frames_stream ); /* 添加至动画更新队列中 */ if( i>=total ) { return Queue_AddPointer(&frames_stream, frames); } return 1; }
void pic8259_device::set_irq_line(int irq, int state) { UINT8 mask = (1 << irq); if (state) { /* setting IRQ line */ if (LOG_GENERAL) logerror("pic8259_set_irq_line() %s: PIC set IRQ line #%d\n", tag(), irq); if(m_level_trig_mode || (!m_level_trig_mode && !(m_irq_lines & mask))) { m_irr |= mask; } m_irq_lines |= mask; } else { /* clearing IRQ line */ if (LOG_GENERAL) { logerror("pic8259_device::set_irq_line() %s: PIC cleared IRQ line #%d\n", tag(), irq); } m_irq_lines &= ~mask; m_irr &= ~mask; } set_timer(); }
int dotcpwatch (int argc, char** argv, void *p) { if(argc < 2) { tprintf ("TCP Watch Dog timer %d/%d seconds\n", read_timer (&TcpWatchTimer)/1000, dur_timer(&TcpWatchTimer)/1000); return 0; } stop_timer (&TcpWatchTimer); /* in case it's already running */ /* what to call on timeout */ TcpWatchTimer.func = (void (*)(void*))dowatchtick; TcpWatchTimer.arg = NULLCHAR; /* dummy value */ /* set timer duration */ set_timer (&TcpWatchTimer, (uint32)atoi (argv[1])*1000); start_timer (&TcpWatchTimer); /* and fire it up */ return 0; }
/********************************* /function name: second_clock() /function: timer *********************************/ void second_clock() { signal(SIGALRM, signal_handler); set_timer(); while(count <= 600); exit(0); }
// respawn character tmp at tmpx,tmpy // if that place is occupied, try again in one second static void respawn_callback(int tmp,int tmpx,int tmpy,int tmpa,int dum) { int cn; cn=create_char_nr(tmp,tmpa); ch[cn].tmpx=tmpx; ch[cn].tmpy=tmpy; if (char_driver(ch[cn].driver,CDT_RESPAWN,cn,0,0)==1 && set_char(cn,tmpx,tmpy,0)) { update_char(cn); ch[cn].hp=ch[cn].value[0][V_HP]*POWERSCALE; ch[cn].endurance=ch[cn].value[0][V_ENDURANCE]*POWERSCALE; ch[cn].mana=ch[cn].value[0][V_MANA]*POWERSCALE; if (ch[cn].lifeshield<0) { elog("respawn_callback(): lifeshield=%d (%X) for char %d (%s). fixed.",ch[cn].lifeshield,ch[cn].lifeshield,cn,ch[cn].name); ch[cn].lifeshield=0; } ch[cn].dir=DX_RIGHTDOWN; register_respawn_respawn(cn); //charlog(cn,"created by respawn"); return; } destroy_char(cn); set_timer(ticker+TICKS*10,respawn_callback,tmp,tmpx,tmpy,tmpa,0); }
static void init_timer(int seconds) { timer = CreateWaitableTimer(NULL, TRUE, NULL); if (timer == NULL) die("CreateWaitableTimer failed"); set_timer(seconds); }
void kickoff_adverts(void) { struct Interface *iface; /* * send initial advertisement and set timers */ for(iface=IfaceList; iface; iface=iface->next) { if( iface->UnicastOnly ) break; init_timer(&iface->tm, timer_handler, (void *) iface); if (!iface->AdvSendAdvert) break; /* send an initial advertisement */ if (send_ra_forall(sock, iface, NULL) == 0) { iface->init_racount++; set_timer(&iface->tm, min(MAX_INITIAL_RTR_ADVERT_INTERVAL, iface->MaxRtrAdvInterval)); } } }
static __inline__ void jpf_service_init(jpf_service *ps) { memset(ps, 0, sizeof(*ps)); ps->jpf_timer = set_timer(1000, jpf_service_timer, NULL, ps); BUG_ON(!ps->jpf_timer); }
/* This function should be called soon after each time the MSB of the * pmtimer register rolls over, to make sure we update the status * registers and SCI at least once per rollover */ static void pmt_timer_callback(void *opaque) { PMTState *s = opaque; uint32_t pmt_cycles_until_flip; uint64_t time_until_flip; spin_lock(&s->lock); /* Recalculate the timer and make sure we get an SCI if we need one */ pmt_update_time(s); /* How close are we to the next MSB flip? */ pmt_cycles_until_flip = TMR_VAL_MSB - (s->pm.tmr_val & (TMR_VAL_MSB - 1)); /* Overall time between MSB flips */ time_until_flip = (1000000000ULL << 23) / FREQUENCE_PMTIMER; /* Reduced appropriately */ time_until_flip = (time_until_flip * pmt_cycles_until_flip) >> 23; /* Wake up again near the next bit-flip */ set_timer(&s->timer, NOW() + time_until_flip + MILLISECS(1)); spin_unlock(&s->lock); }
/************************************************* * Load modules * *************************************************/ void Library_State::load(Modules& modules) { #ifndef BOTAN_TOOLS_ONLY set_timer(modules.timer()); set_transcoder(modules.transcoder()); #endif std::vector<Allocator*> mod_allocs = modules.allocators(); for(u32bit j = 0; j != mod_allocs.size(); j++) add_allocator(mod_allocs[j]); set_default_allocator(modules.default_allocator()); #ifndef BOTAN_TOOLS_ONLY std::vector<Engine*> mod_engines = modules.engines(); for(u32bit j = 0; j != mod_engines.size(); ++j) { Named_Mutex_Holder lock("engine"); engines.push_back(mod_engines[j]); } std::vector<EntropySource*> sources = modules.entropy_sources(); for(u32bit j = 0; j != sources.size(); ++j) add_entropy_source(sources[j]); #endif }
/* This function in called every 100 ticks to rebalance the queues. The current * scheduler bumps processes down one priority when ever they run out of * quantum. This function will find all proccesses that have been bumped down, * and pulls them back up. This default policy will soon be changed. */ PRIVATE void balance_queues(struct timer *tp) { struct schedproc *rmp; int proc_nr; int rv; set_timer(&sched_timer, balance_timeout, balance_queues, 0); }
int main(void) { int id1, id2; int p1; int p2; p1 = 23; p2 = 2; int *result1, *result2; //initialize the threading library. DON'T call this more than once! threadInit(); //always start the timer after threadInit set_timer(); id1 = threadCreate(/*some func*/,(void*)&p1); printf("created thread 1.\n"); id2 = threadCreate(/*some func*/,(void*)&p2); printf("created thread 2.\n"); threadJoin(id1, (void*)&result1); printf("joined #1 --> %d.\n",*result1); }
static int __init init_nonfatal_mce_checker(void) { struct cpuinfo_x86 *c = &boot_cpu_data; /* Check for MCE support */ if (mce_disabled || !mce_available(c)) return -ENODEV; if ( __get_cpu_var(poll_bankmask) == NULL ) return -EINVAL; /* * Check for non-fatal errors every MCE_RATE s */ switch (c->x86_vendor) { case X86_VENDOR_AMD: /* Assume we are on K8 or newer AMD CPU here */ amd_nonfatal_mcheck_init(c); break; case X86_VENDOR_INTEL: init_timer(&mce_timer, mce_work_fn, NULL, 0); set_timer(&mce_timer, NOW() + MCE_PERIOD); break; } printk(KERN_INFO "mcheck_poll: Machine check polling timer started.\n"); return 0; }
static int __init init_nonfatal_mce_checker(void) { struct cpuinfo_x86 *c = &boot_cpu_data; /* Check for MCE support */ if (mce_disabled || !mce_available(c)) return -ENODEV; if ( __get_cpu_var(poll_bankmask) == NULL ) return -EINVAL; /* * Check for non-fatal errors every MCE_RATE s */ switch (c->x86_vendor) { case X86_VENDOR_AMD: if (c->x86 == 6) { /* K7 */ #ifdef CONFIG_XEN_TIMER init_timer(&mce_timer, mce_work_fn, NULL, 0); set_timer(&mce_timer, NOW() + MCE_PERIOD); #endif break; } /* Assume we are on K8 or newer AMD CPU here */ amd_nonfatal_mcheck_init(c); break; case X86_VENDOR_INTEL: /* * The P5 family is different. P4/P6 and latest CPUs share the * same polling methods. */ if ( c->x86 != 5 ) { #ifdef CONFIG_XEN_TIMER init_timer(&mce_timer, mce_work_fn, NULL, 0); set_timer(&mce_timer, NOW() + MCE_PERIOD); #endif } break; } printk(KERN_INFO "mcheck_poll: Machine check polling timer started.\n"); return 0; }
bool MainWindow::on_create(void) { TopWindow::on_create(); timer_id = set_timer(1000, 500); // 2 times per second return true; }
void location(float latitude, float longitude, float altitude, float accuracy, void* context) { // Fix the floats our_latitude = latitude * 10000; our_longitude = longitude * 10000; located = true; request_weather(); set_timer((AppContextRef)context); }
void fornow() { set_timer( boost::posix_time::microsec_clock::universal_time() + boost::posix_time::seconds(1), boost::bind (&foo::callback, this, ai::placeholders::error) ); svc.run(); }