static void timer_update(struct timer *T) { // try to dispatch timeout 0 (rare condition) timer_execute(T); // shift time first, and then dispatch timer message timer_shift(T); timer_execute(T); }
static void timer_update(struct timer *T) { while (__sync_lock_test_and_set(&T->lock,1)) {}; // try to dispatch timeout 0 (rare condition) timer_execute(T); // shift time first, and then dispatch timer message timer_shift(T); timer_execute(T); __sync_lock_release(&T->lock); }
static void timer_update_tick(struct timer *T) { LOCK(T); // try to dispatch timeout 0 (rare condition) timer_execute(T); // shift time first, and then dispatch timer message timer_shift(T); //check agin timer_execute(T); UNLOCK(T); }
/* 更新当前时间并分发所有已经到期的定时事件. 此函数是线程安全的. */ static void timer_update(struct timer *T) { SPIN_LOCK(T); /* 第一件做的事情是分发当前时间未更新的情况下到期的定时事件, 这些事件 是在上次分发运行中添加进来而未检查到的. 如果不这样做, 它们将永远丢失. */ // try to dispatch timeout 0 (rare condition) timer_execute(T); /* 然后才是更新当前时间, 重新安排层级列表集中的定时触发事件, 并分发此时到期的定时事件 */ // shift time first, and then dispatch timer message timer_shift(T); timer_execute(T); SPIN_UNLOCK(T); }
void skynet_updatetime(void) { uint32_t ct = _gettime(); if (ct > TI->current) { int diff = ct-TI->current; TI->current = ct; int i; for (i=0;i<diff;i++) { timer_execute(TI); } } }
void * timer_server_task(void *arg) { int ret; int socket, acpt_socket; struct timeval timeout; struct timeval *time_ptr = NULL; pthread_detach(pthread_self()); snprintf(socket_file, sizeof(socket_file), TIMER_SOCKET_FILE, getpid()); /* Init socket */ ret = unix_domain_socket_init(&socket, socket_file); if (ret != 0) { fprintf(std_err, "cmsvc_init() failed."); goto out; } pthread_mutex_lock(&timeout_mutex); beInitialed = 1; pthread_cond_signal(&timeout_cond); pthread_mutex_unlock(&timeout_mutex); /* select socket, proccess when got a message. */ while (1) { ret = unix_domain_accept_req(socket, &acpt_socket, time_ptr); if (ret == 0) {//timeout timer_execute(); goto check; } else if (ret < 0) { goto check; } ret = handle_proc_req(acpt_socket); if (ret != 0) { fprintf(std_err, "handle_proc_req() failed.\n"); } check: if (get_rest_time(&timeout) < 0 ) { time_ptr = NULL; } else { time_ptr = &timeout; } } out: unix_domain_socket_clean(socket, socket_file); return (void *)0; }
static void timer_tick(struct core_timer* timer, struct core_poller* io) { timer_execute(timer,io); timer_shift(timer); timer_execute(timer, io); }