/** * Stops the idle so it won't be called by the specified event loop. * * Usage: * idle:stop(loop) * * [+0, -0, e] */ static int idle_stop(lua_State *L) { ev_idle* idle = check_idle(L, 1); struct ev_loop* loop = *check_loop_and_init(L, 2); loop_stop_watcher(L, 2, 1); ev_idle_stop(loop, idle); return 0; }
/** * Starts the idle so it won't be called by the specified event loop. * * Usage: * idle:start(loop [, is_daemon]) * * [+0, -0, e] */ static int idle_start(lua_State *L) { ev_idle* idle = check_idle(L, 1); struct ev_loop* loop = *check_loop_and_init(L, 2); int is_daemon = lua_toboolean(L, 3); ev_idle_start(loop, idle); loop_start_watcher(L, 2, 1, is_daemon); return 0; }
void jack_raw_output::start () { check_idle (); jack_activate (_client); auto grd_activate = base::make_guard ([&] { jack_deactivate (_client); }); connect_ports (); grd_activate.dismiss (); set_state (async_state::running); }
void connect_pool::put(connect_client* conn, bool keep /* = true */) { time_t now = time(NULL); lock_.lock(); // 检查是否设置了自销毁标志位 if (delay_destroy_) { delete conn; count_--; if (count_ <= 0) { // 如果引用计数为 0 则自销毁 lock_.unlock(); delete this; } else lock_.unlock(); return; } if (keep && alive_) { conn->set_when(now); // 将归还的连接放在链表首部,这样在调用释放过期连接 // 时比较方便,有利于尽快将不忙的数据库连接关闭 pool_.push_front(conn); } else { acl_assert(count_ > 0); delete conn; count_--; } if (idle_ttl_ >= 0 && now - last_check_ >= check_inter_) { (void) check_idle(idle_ttl_, false); (void) time(&last_check_); } lock_.unlock(); }
void db_pool::put(db_handle* conn, bool keep /* = true */) { acl_assert(conn); const char* id = conn->get_id(); bool eq; if (id && strcmp(id, id_) == 0) eq = true; else eq = false; time_t now = time(NULL); locker_->lock(); if (keep) { conn->set_when(now); // 将归还的连接放在链表首部,这样在调用释放过期连接 // 时比较方便,有利于尽快将不忙的数据库连接关闭 pool_.push_front(conn); // 如果该连接句柄不是由本连接池产生的,则需要 // 重新设置连接句柄的 ID 标识 if (!eq) conn->set_id(id_); } else { // 只有当该连接句柄由本连接池产生时,才需要 // 减少记数器 if (eq) dbcount_--; delete conn; } if (ttl_ >= 0 && now - last_check_ >= check_inter_) { (void) check_idle(ttl_, false); (void) time(&last_check_); } locker_->unlock(); }
void connect_pool::put(connect_client* conn, bool keep /* = true */) { time_t now = time(NULL); lock_->lock(); // 检查是否设置了自销毁标志位 if (delay_destroy_) { delete conn; count_--; assert(count_ >= 0); if (count_ == 0) { // 如果引用计数为 0 则自销毁 lock_->unlock(); delete this; } return; } if (keep && alive_) { conn->set_when(now); pool_.push_front(conn); } else { delete conn; count_--; assert(count_ >= 0); } if (idle_ttl_ >= 0 && now - last_check_ >= check_inter_) { (void) check_idle(idle_ttl_, false); (void) time(&last_check_); } lock_->unlock(); }
static void parse_user_command_idle_in(char *str) { char *oldstack, *job_id, *name = 0; player *p; oldstack = stack; /*Format will be job_id:name */ job_id = str; if (job_id && *job_id) { name = strchr(job_id, ':'); if (name) *name++ = '\0'; } if (!name || !*name || !job_id || !*job_id) { log("error", "Bad format in idle from intercom.\n"); return; } if (!strcasecmp(name, "me")) { send_to_intercom(NULL, "%c%c%s:me", REPLY_IS, NO_SUCH_PLAYER, job_id); return; } /*We know they are here, and exist, so we can examine, otherwise end */ send_to_intercom(NULL, "%c%c%s:x:%c", REPLY_IS, COMMAND_IDLE, job_id, (char) INCOMPLETE_MESSAGE); p = make_dummy_intercom_player(); check_idle(p, name); send_to_intercom(NULL, "%c", (char) END_MESSAGE); stack = oldstack; return; }
// Idle Check Task routine. // void dispatch_IdleCheck(void *pUnused, int iUnused) { UNUSED_PARAMETER(pUnused); UNUSED_PARAMETER(iUnused); if (mudconf.control_flags & CF_IDLECHECK) { const char *cmdsave = mudstate.debug_cmd; mudstate.debug_cmd = (char *)"< idlecheck >"; check_idle(); mudstate.debug_cmd = cmdsave; } // Schedule ourselves again. // CLinearTimeAbsolute ltaNow; ltaNow.GetUTC(); CLinearTimeDelta ltd; ltd.SetSeconds(mudconf.idle_interval); mudstate.idle_counter = ltaNow + ltd; scheduler.DeferTask(mudstate.idle_counter, PRIORITY_SYSTEM, dispatch_IdleCheck, 0, 0); }
// Start Of Program - this is where we setup everything before getting into the main loop void main(void) { // Oscillator setup OSCCON = 0b11100000; // device enters idle on Sleep(), 8Mhz Clock, OSCTUNE = 0b00000000; // Internal oscillator low freq comes from 31Khz clock from LFINTOSC, PLL disabled // Analog / Digital pins setup ANSEL = 0b00000000; // disable all analog inputs (make them all digital) must do this! ANSELH = 0b00000000; // disable all analog inputs (make them all digital) must do this! // Tristate setup TRISA = 0b00000011; TRISB = 0b11111110; TRISC = 0b00000000; TRISD = 0b00000000; TRISE = 0b00000000; // configure TIMER2: // prescaler 16, period register for 1ms, timer stopped T2CON = 0b00000010; TMR2 = 0; PR2 = _XTAL_FREQ / 1000 / 16 / 4; // initialize subsystems btn_init(); init_all(); // disable INT1, config for raising endge INT1IE = 0; INTEDG1 = 1; // enable interrupts TMR2IE = 1; // TIMER2 interrupt PEIE = 1; // peripheral interrupt GIE = 1; // global interrupt enable // start TIMER2 TMR2ON = 1; // main loop while (true) { off_flag = false; // go to idle and wait for timer Sleep(); // read button inputs btn_update(); // check for commands check_select(); check_off(); check_idle(); // execute mode task switch (mode) { case modeSelect: mode_select(); break; case modeSparkle: sparkle_leds(); break; case modeShiftReg: shiftreg_task(); break; case modeLightTest: led_group(LED_ALL, true); break; case modePOV: povmsg_task(); break; case modeBinDice: case modeDecDice: dice_task(mode == modeDecDice); break; case modeGame: game_task(); break; case mode4BitLogic: logic_4bit_task(); break; default: logic_task(); flipflop_task(); counter_task(mode == modeGrayCnt); } if (off_flag) { switch_off(); } } }
void NDECL(dispatch) { char *cmdsave; cmdsave = mudstate.debug_cmd; mudstate.debug_cmd = (char *)"< dispatch >"; /* this routine can be used to poll from interface.c */ if (!mudstate.alarm_triggered) return; mudstate.alarm_triggered = 0; mudstate.lastnowmsec = mudstate.nowmsec; mudstate.lastnow = mudstate.now; mudstate.nowmsec = time_ng(NULL); mudstate.now = (time_t) floor(mudstate.nowmsec); do_second(); local_second(); /* Free list reconstruction */ if ((mudconf.control_flags & CF_DBCHECK) && (mudstate.check_counter <= mudstate.nowmsec)) { mudstate.check_counter = mudconf.check_interval + mudstate.nowmsec; mudstate.debug_cmd = (char *)"< dbck >"; cache_reset(0); do_dbck (NOTHING, NOTHING, 0); cache_reset(0); pcache_trim(); } /* Database dump routines */ if ((mudconf.control_flags & CF_CHECKPOINT) && (mudstate.dump_counter <= mudstate.nowmsec)) { mudstate.dump_counter = mudconf.dump_interval + mudstate.nowmsec; mudstate.debug_cmd = (char *)"< dump >"; fork_and_dump(0, (char *)NULL); } /* Idle user check */ if ((mudconf.control_flags & CF_IDLECHECK) && (mudstate.idle_counter <= mudstate.nowmsec)) { mudstate.idle_counter = mudconf.idle_interval + mudstate.nowmsec; mudstate.debug_cmd = (char *)"< idlecheck >"; cache_reset(0); check_idle(); } #ifdef HAVE_GETRUSAGE /* Memory use stats */ if (mudstate.mstats_counter <= mudstate.nowmsec) { int curr; mudstate.mstats_counter = 15 + mudstate.nowmsec; curr = mudstate.mstat_curr; if ( (curr >= 0 ) && (mudstate.now > mudstate.mstat_secs[curr]) ) { struct rusage usage; curr = 1-curr; getrusage(RUSAGE_SELF, &usage); mudstate.mstat_ixrss[curr] = usage.ru_ixrss; mudstate.mstat_idrss[curr] = usage.ru_idrss; mudstate.mstat_isrss[curr] = usage.ru_isrss; mudstate.mstat_secs[curr] = mudstate.now; mudstate.mstat_curr = curr; } } #endif #ifdef RWHO_IN_USE if ((mudconf.control_flags & CF_RWHO_XMIT) && (mudstate.rwho_counter <= mudstate.nowmsec)) { mudstate.rwho_counter = mudconf.rwho_interval + mudstate.nowmsec; mudstate.debug_cmd = (char *)"< rwho update >"; rwho_update(); } #endif /* reset alarm */ alarm_msec (next_timer()); mudstate.debug_cmd = cmdsave; }
void set_callback (callback_type cb) { check_idle (); _callback = cb; }