示例#1
0
文件: timer.c 项目: Zeex/sampgdk
static void _sampgdk_timer_fire(int timerid, int64_t elapsed) {
  struct _sampgdk_timer_info *timer;
  int64_t now = _sampgdk_timer_now();
  int64_t started;

  assert(timerid > 0 && timerid <= _sampgdk_timers.count);
  timer = (struct _sampgdk_timer_info *)sampgdk_array_get(&_sampgdk_timers, timerid - 1);

  assert(timer->is_set);
  started = timer->started;

  sampgdk_log_debug("Firing timer %d, now = %" PRId64 ", elapsed = %" PRId64,
      timerid, now, elapsed);
  ((sampgdk_timer_callback)timer->callback)(timerid, timer->param);

  /* We don't want to kill the same timer twice, so make sure it's not
   * been killed inside the timer callback.
   */
  if (timer->is_set && timer->started == started) {
    if (timer->repeat) {
      timer->started = now - (elapsed - timer->interval);
    } else {
      sampgdk_timer_kill(timerid);
    }
  }
}
示例#2
0
文件: timer.c 项目: Pupak/sampgdk
static void fire_timer(int timerid, long elapsed) {
  struct sampgdk_timer *timer;

  assert(timerid > 0 && timerid <= timers.count);

  timer = sampgdk_array_get(&timers, timerid - 1);
  if (!timer->is_set) {
    return;
  }

  (timer->callback)(timerid, timer->param);

  /* At this point the could be killed by the timer callback,
   * so the timer pointer may be no longer valid.
   */
  if (timer->is_set) {
    if (timer->repeat) {
      timer->started = sampgdk_timer_clock() - (elapsed - timer->interval);
    } else {
      sampgdk_timer_kill(timerid);
    }
  }
}