void timer_intr(softvec_type_t type, unsigned long sp) { if( timer_is_expired(0)) { puts("timer expired 0. \n"); timer_expire(0); } if( timer_is_expired(1)) { puts("timer expired 1. \n"); timer_cancel(1); } }
// Set a timer and cancel it from its own callback. static bool cancel_from_callback() { BEGIN_TEST; timer_args arg{}; arg.result = 1; timer_t t = TIMER_INITIAL_VALUE(t); const Deadline deadline = Deadline::no_slack(current_time()); timer_set(&t, deadline, timer_cancel_cb, &arg); while (!atomic_load(&arg.timer_fired)) { } ASSERT_FALSE(arg.result, ""); ASSERT_FALSE(timer_cancel(&t), ""); END_TEST; }
void timer_callout_free(timer_callout_t * * callout_p) { timer_callout_t * callout = *callout_p; if (callout == NULL) return; timer_cancel(callout); free(callout); *callout_p = NULL; return; }
/* * Function to wait until the power key is pressed long enough */ static void wait_for_long_pwrkey_pressed() { uint32_t sclk_count = 0; while (!pon_timer_complete) { sclk_count = platform_get_sclk_count(); if (sclk_count > PWRKEY_LONG_PRESS_COUNT) { timer_cancel(&pon_timer); break; } thread_sleep(1); } }
static void input_exit(struct input_t * input) { struct key_gpio_private_data_t * dat = (struct key_gpio_private_data_t *)input->priv; if(!dat) return; if(!dat->state) return; free(dat->state); timer_cancel(&dat->timer); }
static void ledtrig_general_remove(struct device_t * dev) { struct ledtrig_t * ledtrig = (struct ledtrig_t *)dev->priv; struct ledtrig_general_pdata_t * pdat = (struct ledtrig_general_pdata_t *)ledtrig->priv; if(ledtrig && unregister_ledtrig(ledtrig)) { timer_cancel(&pdat->timer); free_device_name(ledtrig->name); free(ledtrig->priv); free(ledtrig); } }
static void motor_gpio_remove(struct device_t * dev) { struct motor_t * m = (struct motor_t *)dev->priv; struct motor_gpio_pdata_t * pdat = (struct motor_gpio_pdata_t *)m->priv; if(m && unregister_motor(m)) { timer_cancel(&pdat->timer); free_device_name(m->name); free(m->priv); free(m); } }
/* Return true if we waited */ bool gps_wait_fix(uint16_t timeout) { Timer ttimer; if (is_fixed) return false; if (timeout > 0) { timer_set(&ttimer, timeout); timer_callback(&ttimer, (CBfunc) notifyAll, &wait_gps); } wait(&wait_gps); timer_cancel(&ttimer); return true; }
static struct device_t * buzzer_pwm_probe(struct driver_t * drv, struct dtnode_t * n) { struct buzzer_pwm_pdata_t * pdat; struct pwm_t * pwm; struct buzzer_t * buzzer; struct device_t * dev; if(!(pwm = search_pwm(dt_read_string(n, "pwm-name", NULL)))) return NULL; pdat = malloc(sizeof(struct buzzer_pwm_pdata_t)); if(!pdat) return NULL; buzzer = malloc(sizeof(struct buzzer_t)); if(!buzzer) { free(pdat); return NULL; } timer_init(&pdat->timer, buzzer_pwm_timer_function, buzzer); pdat->queue = queue_alloc(); pdat->pwm = pwm; pdat->polarity = dt_read_bool(n, "pwm-polarity", 0); pdat->frequency = -1; buzzer->name = alloc_device_name(dt_read_name(n), dt_read_id(n)); buzzer->set = buzzer_pwm_set; buzzer->get = buzzer_pwm_get; buzzer->beep = buzzer_pwm_beep; buzzer->priv = pdat; buzzer_pwm_set(buzzer, 0); if(!register_buzzer(&dev, buzzer)) { timer_cancel(&pdat->timer); queue_free(pdat->queue, iter_queue_node); free_device_name(buzzer->name); free(buzzer->priv); free(buzzer); return NULL; } dev->driver = drv; return dev; }
// Set a timer that re-sets itself from its own callback. static bool set_from_callback() { BEGIN_TEST; timer_args arg{}; arg.remaining = 5; timer_t t = TIMER_INITIAL_VALUE(t); const Deadline deadline = Deadline::no_slack(current_time()); timer_set(&t, deadline, timer_set_cb, &arg); while (atomic_load(&arg.remaining) > 0) { } // We cannot assert the return value below because we don't know if the last timer has fired. timer_cancel(&t); END_TEST; }
static void buzzer_pwm_remove(struct device_t * dev) { struct buzzer_t * buzzer = (struct buzzer_t *)dev->priv; struct buzzer_pwm_pdata_t * pdat = (struct buzzer_pwm_pdata_t *)buzzer->priv; if(buzzer && unregister_buzzer(buzzer)) { timer_cancel(&pdat->timer); queue_free(pdat->queue, iter_queue_node); free_device_name(buzzer->name); free(buzzer->priv); free(buzzer); } }
void timer_cancelall(struct FIFO32 *fifo) { int e, i; struct TIMER *t; e = io_load_eflags(); io_cli(); /* 在设置过程中禁止改变定时器状态 */ for (i = 0; i < MAX_TIMER; i++) { t = &timerctl.timers0[i]; if (t->flags != 0 && t->flags2 != 0 && t->fifo == fifo) { timer_cancel(t); timer_free(t); } } io_store_eflags(e); return; }
void timer_cancelall (struct Queue8* queue) { int e,i; struct TIMER *t; e = io_load_eflags(); io_cli(); for (i = 0; i < MAX_TIMER ; i ++ ) { t = &timerctl.timers0[i]; if (t->flags != 0 && t->flags2 != 0 && t->queue == queue) { timer_cancel(t); timer_free(t); } } io_store_eflags (e); return; }
static void failover_cancel_pending_events(ServiceRef service_p) { Service_failover_t * failover; failover = (Service_failover_t *)ServiceGetPrivate(service_p); if (failover == NULL) return; if (failover->timer) { timer_cancel(failover->timer); } if (failover->arp) { arp_client_cancel(failover->arp); } return; }
static void manual_cancel_pending_events(ServiceRef service_p) { Service_manual_t * manual; manual = (Service_manual_t *)ServiceGetPrivate(service_p); if (manual == NULL) return; if (manual->timer) { timer_cancel(manual->timer); } if (manual->arp) { arp_client_cancel(manual->arp); } return; }
static void linklocal_cancel_pending_events(ServiceRef service_p) { Service_linklocal_t * linklocal; linklocal = (Service_linklocal_t *)ServiceGetPrivate(service_p); if (linklocal == NULL) return; if (linklocal->timer) { timer_cancel(linklocal->timer); } if (linklocal->arp) { arp_client_cancel(linklocal->arp); } return; }
// See that timer_trylock_or_cancel acquires the lock when the holder releases it. static bool trylock_or_cancel_get_lock() { BEGIN_TEST; // We need 2 or more CPUs for this test. if (get_num_cpus_online() < 2) { printf("skipping test trylock_or_cancel_get_lock, not enough online cpus\n"); return true; } timer_args arg{}; timer_t t = TIMER_INITIAL_VALUE(t); SpinLock lock; arg.lock = lock.GetInternal(); arg.wait = 1; arch_disable_ints(); uint timer_cpu = arch_curr_cpu_num(); const Deadline deadline = Deadline::no_slack(current_time() + ZX_USEC(100)); timer_set(&t, deadline, timer_trylock_cb, &arg); // The timer is set to run on timer_cpu, switch to a different CPU, acquire the spinlock then // signal the callback to proceed. thread_set_cpu_affinity(get_current_thread(), ~cpu_num_to_mask(timer_cpu)); DEBUG_ASSERT(arch_curr_cpu_num() != timer_cpu); arch_enable_ints(); { AutoSpinLock guard(&lock); while (!atomic_load(&arg.timer_fired)) { } // Callback should now be running. Tell it to stop waiting and start trylocking. atomic_store(&arg.wait, 0); } // See that timer_cancel returns false indicating that the timer ran. ASSERT_FALSE(timer_cancel(&t), ""); // Note, we cannot assert the value of arg.result. We have both released the lock and canceled // the timer, but we don't know which of these events the timer observed first. END_TEST; }
InputContext::~InputContext() { #if UIM_XIM_USE_DELAY timer_cancel(); #endif if (mFocusedContext == this) mFocusedContext = NULL; if (mConvdisp) mConvdisp->set_pe(NULL); delete m_pe; uim_release_context(mUc); mServer->deleteContext(this); free(mEngineName); free(mLocaleName); }
static void sess_destroyed(Event_Type et, Object *obj, Any_Type regarg, Any_Type callarg) { Sess_Private_Data *priv; Sess *sess; assert(et == EV_SESS_DESTROYED && object_is_sess(obj)); sess = (Sess *) obj; priv = SESS_PRIVATE_DATA (sess); if (priv->timer) { timer_cancel(priv->timer); priv->timer = 0; } if (++num_sessions_destroyed >= param.wsesslog.num_sessions) core_exit(); }
static int cmd_threadload(int argc, const cmd_args *argv) { static bool showthreadload = false; static timer_t tltimer; if (showthreadload == false) { // start the display timer_initialize(&tltimer); timer_set_periodic(&tltimer, 1000, &threadload, NULL); showthreadload = true; } else { timer_cancel(&tltimer); showthreadload = false; } return 0; }
static void timer_far_deadline(void) { event_t event; timer_t timer; event_init(&event, false, 0); timer_init(&timer); const Deadline deadline = Deadline::no_slack(ZX_TIME_INFINITE - 5); timer_set(&timer, deadline, timer_diag_cb, &event); zx_status_t st = event_wait_deadline(&event, current_time() + ZX_MSEC(100), false); if (st != ZX_ERR_TIMED_OUT) { printf("error: unexpected timer fired!\n"); } else { timer_cancel(&timer); } event_destroy(&event); }
static struct device_t * ledtrig_general_probe(struct driver_t * drv, struct dtnode_t * n) { struct ledtrig_general_pdata_t * pdat; struct ledtrig_t * ledtrig; struct device_t * dev; struct led_t * led; led = search_led(dt_read_string(n, "led-name", NULL)); if(!led) return NULL; pdat = malloc(sizeof(struct ledtrig_general_pdata_t)); if(!pdat) return NULL; ledtrig = malloc(sizeof(struct ledtrig_t)); if(!ledtrig) { free(pdat); return NULL; } timer_init(&pdat->timer, ledtrig_general_timer_function, ledtrig); pdat->led = led; pdat->activity = 0; pdat->last_activity = 0; ledtrig->name = alloc_device_name(dt_read_name(n), dt_read_id(n)); ledtrig->activity = ledtrig_general_activity; ledtrig->priv = pdat; if(!register_ledtrig(&dev, ledtrig)) { timer_cancel(&pdat->timer); free_device_name(ledtrig->name); free(ledtrig->priv); free(ledtrig); return NULL; } dev->driver = drv; return dev; }
STATIC bool RTADVSocketOpenSocket(RTADVSocketRef sock) { if (sock->fd_open) { return (TRUE); } timer_cancel(S_globals->timer_callout); S_globals->read_fd_refcount++; my_log(LOG_INFO, "RTADVSocketOpenSocket (%s): refcount %d", if_name(sock->if_p), S_globals->read_fd_refcount); sock->fd_open = TRUE; if (S_globals->read_fd_refcount > 1) { /* already open */ return (TRUE); } if (S_globals->read_fd != NULL) { my_log(LOG_INFO, "RTADVSocketOpenSocket(): socket is still open"); } else { int sockfd; sockfd = open_rtadv_socket(); if (sockfd < 0) { my_log(LOG_ERR, "RTADVSocketOpenSocket: socket() failed, %s", strerror(errno)); goto failed; } my_log(LOG_INFO, "RTADVSocketOpenSocket(): opened RTADV socket %d", sockfd); /* register as a reader */ S_globals->read_fd = FDCalloutCreate(sockfd, RTADVSocketRead, NULL, NULL); } return (TRUE); failed: RTADVSocketCloseSocket(sock); return (FALSE); }
static boolean_t DHCPv6SocketOpenSocket(DHCPv6SocketRef sock) { if (sock->fd_open) { return (TRUE); } timer_cancel(S_globals->timer_callout); S_globals->read_fd_refcount++; my_log(LOG_DEBUG, "DHCPv6SocketOpenSocket (%s): refcount %d", if_name(sock->if_p), S_globals->read_fd_refcount); sock->fd_open = TRUE; if (S_globals->read_fd_refcount > 1) { /* already open */ return (TRUE); } if (S_globals->read_fd != NULL) { my_log(LOG_DEBUG, "DHCPv6SocketOpenSocket(): socket is still open"); } else { int sockfd; sockfd = open_dhcpv6_socket(S_client_port); if (sockfd < 0) { my_log(LOG_ERR, "DHCPv6SocketOpenSocket: socket() failed, %s", strerror(errno)); goto failed; } my_log(LOG_DEBUG, "DHCPv6SocketOpenSocket(): opened DHCPv6 socket %d", sockfd); /* register as a reader */ S_globals->read_fd = FDCalloutCreate(sockfd, DHCPv6SocketRead, NULL, NULL); } return (TRUE); failed: DHCPv6SocketCloseSocket(sock); return (FALSE); }
void cmd_exit(struct CONSOLE *cons, int *fat) { struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct TASK *task = task_now(); struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4); struct FIFO32 *fifo = (struct FIFO32 *) *((int *) 0x0fec); if (cons->sht != 0) { timer_cancel(cons->timer); } memman_free_4k(memman, (int) fat, 4 * 2880); io_cli(); if (cons->sht != 0) { fifo32_put(fifo, cons->sht - shtctl->sheets0 + 768); /* 768〜1023 */ } else { fifo32_put(fifo, task - taskctl->tasks0 + 1024); /* 1024〜2023 */ } io_sti(); for (;;) { task_sleep(task); } }
static int cmd_threadload(int argc, const cmd_args * argv) { static bool showthreadload = false; static timer_t tltimer; enter_critical_section(); if (showthreadload == false) { // start the display timer_initialize(&tltimer); timer_set_oneshot(&tltimer, 1000, &threadload, NULL); showthreadload = true; } else { timer_cancel(&tltimer); showthreadload = false; } exit_critical_section(); return 0; }
static void buzzer_gpio_beep(struct buzzer_t * buzzer, int frequency, int millisecond) { struct buzzer_gpio_pdata_t * pdat = (struct buzzer_gpio_pdata_t *)buzzer->priv; struct beep_param_t * param; if((frequency == 0) && (millisecond == 0)) { timer_cancel(&pdat->timer); queue_clear(pdat->beep, iteration_beep_param); buzzer_gpio_set(buzzer, 0); return; } param = malloc(sizeof(struct beep_param_t)); if(!param) return; param->frequency = frequency; param->millisecond = millisecond; queue_push(pdat->beep, param); if(queue_avail(pdat->beep) == 1) timer_start_now(&pdat->timer, ms_to_ktime(1)); }
static bool_t buzzer_gpio_unregister_buzzer(struct resource_t * res) { struct buzzer_gpio_pdata_t * pdat; struct buzzer_t * buzzer; char name[64]; snprintf(name, sizeof(name), "%s.%d", res->name, res->id); buzzer = search_buzzer(name); if(!buzzer) return FALSE; pdat = (struct buzzer_gpio_pdata_t *)buzzer->priv; if(!unregister_buzzer(buzzer)) return FALSE; timer_cancel(&pdat->timer); queue_free(pdat->beep, iteration_beep_param); free(buzzer->priv); free(buzzer->name); free(buzzer); return TRUE; }
static rstatus_t call_reset_timer(struct context *ctx, struct call *call) { struct opt *opt = &ctx->opt; struct conn *conn = call->conn; if (opt->timeout == 0.0) { return MCP_OK; } ASSERT(conn->watchdog != NULL); timer_cancel(conn->watchdog); if (STAILQ_EMPTY(&conn->call_recvq)) { /* * Skip scheduling a timer as there are no outstanding calls * on this connection */ return MCP_OK; } return call_start_timer(ctx, STAILQ_FIRST(&conn->call_recvq)); }
void timer_settime(TIMER* timer, unsigned int timeout) { timer_cancel(timer); timer->timeout = timeout + timerctl.count; timer->flags = TIMER_FLAGS_RUNNING; int e = io_load_eflags(); io_cli(); TIMER* t = timerctl.t0, *s = NULL; if (timer->timeout <= t->timeout) { // Earliest timer. timerctl.t0 = timer; timer->next_timer = t; timerctl.next_time = timer->timeout; } else { for (;;) { s = t; t = t->next_timer; if (timer->timeout <= t->timeout) { s->next_timer = timer; timer->next_timer = t; break; } } } io_store_eflags(e); }