PROXY_API void PMC_API uninit_proxy() { g_InitLock.Lock(); g_iInitCount--; if(g_iInitCount){ g_InitLock.UnLock(); return; } if(g_Worker){ if(g_Worker->stop(3000)){ delete g_Worker; } g_Worker = 0; } stop_dispatcher(); uninit_network(); uninit_rtdb(); unhook_rtdb_events(&g_DBDispatchTable); g_iInitFlag = 0; g_InitLock.UnLock(); delete _g_InitLock; _g_InitLock = 0; }
void dispatcher_core(void *inisock) { int sockval; signal(&dispatcher_sigusr1, SIGUSR1); openlog ("IRCDISPATCHER", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL3); if (!daemon_on && initiate_dispatcher(*inisock) == ERR) { syslog(LOG_ERR, "Error intiating dispatcher."); pthread_exit(ERR); } while (has_next(_connections)) { if (extract_connection(_connections, &sockval) == ERR) { syslog(LOG_ERR, "Error extrayendo conexión"); return; } syslog(LOG_INFO, "Escuchando conexión %d", sockval); listen_connection(sockval); } stop_dispatcher(); }
bool Scheduler::remove_timer(size_t timer_id) { Auto_Mutex auto_lock(_lock); for (List_Elem* p = _list.head; p; p = p->next) { Timer* timer = (Timer*)p; if (timer->id == timer_id) { // Found! _list.remove(p); _id_pool.put(timer->id); delete timer; if (_auto_dispatch && _list.empty()) stop_dispatcher(); return true; } } // Not found! return false; }
void Scheduler::dispatch() { // We will spend no more than this duration in this dispatch() function. // Currently 100 milliseconds const uint64 MAX_TIME_INSIDE_DISPATCH_USEC = 1000 * 1000; _lock.lock(); // if list empty exit without any other processing. If we are using // continuous threads, execute timer before exiting. if (_list.empty()) { _lock.unlock(); if (_auto_dispatch) stop_dispatcher(); else Time::sleep(MAX_TIME_INSIDE_DISPATCH_USEC); return; } // Sleep until the closest deadline uint64 now = Time::now(); uint64 closest_deadline = ((Timer*)_list.head)->deadline; if (now < closest_deadline) { uint64 diff = closest_deadline - now; if (diff > MAX_TIME_INSIDE_DISPATCH_USEC) { _lock.unlock(); Time::sleep(MAX_TIME_INSIDE_DISPATCH_USEC); return; } _lock.unlock(); Time::sleep(diff); _lock.lock(); now = closest_deadline; } // Dispatch expired timers (there will be at least one). for (;;) { Timer* timer = (Timer*)_list.head; // if current timer not expired, terminate loop if (!timer || now < timer->deadline) break; _list.remove(timer); // Call the function to be executed for this timer. _lock.unlock(); uint64 new_timeout = timer->proc(timer->arg); _lock.lock(); // if the function returns zero, delete this timer // else reinsert the timer with the returned timeout. // if (new_timeout == 0) delete timer; else { if (!_auto_dispatch) { timer->deadline = Time::now() + new_timeout; _insert_timer(_list, timer); } else // if autothreading { if (_dispatcher_thread_running) { timer->deadline = Time::now() + new_timeout; _insert_timer(_list, timer); } else delete timer; } } } if (_auto_dispatch && _list.empty()) stop_dispatcher(); _lock.unlock(); }