/* : set sw=8 ai fdm=marker fmr={,} :*/ #include #include #include #include #include #include "poll_thread.h" #include "memcheck.h" #include "poller.h" #include "myepoll.h" #include "log.h" #include #include "timemanager.h" volatile extern int stop; CPollThread::CPollThread (const char *name) : CThread(name, CThread::ThreadTypeAsync), CPollerUnit(1000), pollTimeout(2000) { } CPollThread::~CPollThread () { } int CPollThread::Initialize(void) { if(CThread::g_autoconf != NULL) { int mp0 = GetMaxPollers(); int mp1; mp1 = g_autoconf->GetIntVal("MaxIncomingPollers", Name(), mp0); log_debug("autoconf thread %s MaxIncomingPollers %d", taskname, mp1); if(mp1 > mp0) { SetMaxPollers(mp1); } } if(InitializePollerUnit() < 0) return -1; return 0; } void * CPollThread::Process (void) { while (!Stopping()) { // if previous event loop has no events, // don't allow zero epoll wait time int timeout = ExpireMicroSeconds(pollTimeout, nrEvents==0); int interrupted = WaitPollerEvents(timeout); UpdateNowTime(timeout, interrupted); TimeManager::Instance().AdjustDay(); if (Stopping()) break; ProcessPollerEvents(); CheckExpired(GetNowTime()); CTimerUnit::CheckReady(); CReadyUnit::CheckReady(GetNowTime()); DelayApplyEvents(); } return 0; }