/** * Timer Process function. * It calls timer_loop(). * @param returns - whether on shutdown this function should return or exit * @returns if returns is set then on shutdown, else never and on shutdown it exits */ void timer_process(int returns) { LM_INFO("Timer process starting up...\n"); timer_loop(); LM_INFO("... Timer process finished\n"); if (!returns) { #ifdef CDP_FOR_SER #else #ifdef PKG_MALLOC #ifdef PKG_MALLOC LM_DBG("Timer Memory status (pkg):\n"); //pkg_status(); #ifdef pkg_sums pkg_sums(); #endif #endif #endif dp_del_pid(getpid()); #endif exit(0); } }
int main(int argc, char* argv[]) { setlocale (LC_ALL, ""); g_type_init(); g_set_application_name ("eyerest-daemon"); if (!config_init(argc, argv)) { g_critical("config_init failed!\n"); return -1; } if(!g_config.foreground) { daemon(0, 0); } if(!dbus_init()) { g_critical("dbus_init failed!\n"); } if (!notify_init()) { g_critical("notify_init failed!\n"); } if (!xfullscreen_init()) { g_critical("xfullscreen_init failed!\n"); return -1; } if (!xevent_init()) { g_critical("xevent_init failed!\n"); return -1; } xevent_run(); if(!state_init()) { g_critical("state_init failed\n"); return -1; } if (!timer_init()) { g_critical("timer_init failed!\n"); return -1; } timer_loop(); return 0; }
ActorTimer_::timer_handle ActorTimer_::timeout(unsigned long long us, const actor_handle& host) { if (!_strand) { _strand = _weakStrand.lock(); } assert(_strand->running_in_this_thread()); assert(us < 0x80000000LL * 1000); unsigned long long et = (get_tick_us() + us) & -256; timer_handle timerHandle; timerHandle._null = false; if (et >= _extMaxTick) { _extMaxTick = et; timerHandle._tableNode = _handlerTable.insert(_handlerTable.end(), make_pair(et, host)); } else { timerHandle._tableNode = _handlerTable.insert(make_pair(et, host)); } if (!_looping) {//定时器已经退出循环,重新启动定时器 _looping = true; assert(_handlerTable.size() == 1); _extFinishTime = et; timer_loop(us); } else if (et < _extFinishTime) {//定时期限前于当前定时器期限,取消后重新计时 boost::system::error_code ec; ((timer_type*)_timer)->cancel(ec); _timerCount++; _extFinishTime = et; timer_loop(us); } return timerHandle; }
int main(int argc,char *argv[]) { assert(argc >=3); rain_log_init(); rain_ctx_init(154); char *dir = malloc(1024); getcwd(dir,1024); strcat(dir,"/routine/"); //printf("dir:%s %s %s %s\n",dir,argv[0],argv[1],argv[2]); rain_moudle_init(dir); free(dir); rain_timer_init(); rainRpcInit(); rain_life_queue_init(); rain_message_queue_init(); sig_init(); struct rain_ctx * ctx = rain_ctx_new(0,argv[1],argv[2]); if(ctx == NULL){ exit(-1); } //routine_t rid = rain_ctx_getid(ctx); int len = 4; pthread_t threads[len]; int i; for(i=0; i<len; i++){ pthread_create(&threads[i],NULL,worker,NULL); } timer_loop(NULL); /* pthread_t thread_ev; pthread_create(&thread_ev,NULL,evloop,NULL); for(i=0; i<len; i++){ pthread_join(threads[i],NULL); } pthread_join(thread_ev,NULL);*/ exit(0); }
void ActorTimer_::timer_loop(unsigned long long us) { int tc = ++_timerCount; boost::system::error_code ec; ((timer_type*)_timer)->expires_from_now(boost::chrono::microseconds(us), ec); ((timer_type*)_timer)->async_wait(_strand->wrap_asio([this, tc](const boost::system::error_code&) { assert(_strand->running_in_this_thread()); if (tc == _timerCount) { _extFinishTime = 0; unsigned long long nt = get_tick_us(); while (!_handlerTable.empty()) { auto iter = _handlerTable.begin(); if (iter->first > nt + 500) { _extFinishTime = iter->first; timer_loop(iter->first - nt); return; } else { iter->second->timeout_handler(); _handlerTable.erase(iter); } } _looping = false; _strand.reset(); } else if (tc == _timerCount - 1) { _strand.reset(); } })); }