Example #1
0
File: core.c Project: Maxence/node
static void uv__timer_cb(EV_P_ ev_timer* w, int revents) {
  uv_timer_t* timer = container_of(w, uv_timer_t, timer_watcher);

  assert(uv__timer_active(timer));

  assert(uv__timer_active(timer));

  if (!uv__timer_repeating(timer)) {
    timer->flags &= ~UV_TIMER_ACTIVE;
    ev_ref(EV_A);
  }

  if (timer->timer_cb) {
    timer->timer_cb(timer, 0);
  }
}
Example #2
0
File: core.c Project: Maxence/node
int uv_timer_again(uv_timer_t* timer) {
  if (!uv__timer_active(timer)) {
    uv__set_sys_error(timer->loop, EINVAL);
    return -1;
  }

  assert(uv__timer_repeating(timer));
  ev_timer_again(timer->loop->ev, &timer->timer_watcher);
  return 0;
}
Example #3
0
File: core.c Project: Maxence/node
int uv_timer_stop(uv_timer_t* timer) {
  if (uv__timer_active(timer)) {
    ev_ref(timer->loop->ev);
  }

  timer->flags &= ~(UV_TIMER_ACTIVE | UV_TIMER_REPEAT);
  ev_timer_stop(timer->loop->ev, &timer->timer_watcher);

  return 0;
}
Example #4
0
static void uv__timer_cb(EV_P_ ev_timer* w, int revents) {
  uv_timer_t* timer = w->data;

  assert(uv__timer_active(timer));

  if (!uv__timer_repeating(timer)) {
    timer->flags &= ~UV_TIMER_ACTIVE;
    ev_ref(EV_A);
  }

  if (timer->timer_cb) {
    timer->timer_cb(timer, 0);
  }
}
Example #5
0
File: core.c Project: Maxence/node
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout,
    int64_t repeat) {
  if (uv__timer_active(timer)) {
    return -1;
  }

  timer->timer_cb = cb;
  timer->flags |= UV_TIMER_ACTIVE;

  if (repeat)
    timer->flags |= UV_TIMER_REPEAT;
  else
    timer->flags &= ~UV_TIMER_REPEAT;

  ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0);
  ev_timer_start(timer->loop->ev, &timer->timer_watcher);
  ev_unref(timer->loop->ev);

  return 0;
}