void RecvThread::run(void) { TestPushCallBackPtr cbPush = new TestPushCallBack(); _prx->tars_set_push_callback(cbPush); string buf("heartbeat"); while(!_bTerminate) { { try { TestPushCallBackPtr cb = new TestPushCallBack(); _prx->rpc_call_async(_prx->tars_gen_requestid(), "printResult", buf.c_str(), buf.length(), cb); } catch(TarsException& e) { cout << "TarsException: " << e.what() << endl; } catch(...) { cout << "unknown exception" << endl; } } { TC_ThreadLock::Lock sync(*this); timedWait(5000); } } }
void QueueTimeout::run() { while (!_terminate) { try { TC_ThreadLock::Lock lock(*this); timedWait(100); if(_terminate) break; handleQueueTimeout(); } catch (exception& e) { LOG->error() << "[TAF][QueueTimeout:run exception:" << e.what() << "]" << endl; } catch (...) { LOG->error() << "[TAF][QueueTimeout:run exception.]" << endl; } } }
bool LeaseEntry::wait_for_expire() const { if (status_ > LEASE_STATUS_RUNNING) return true; Time time_out = expire_time_ - tbutil::Time::now(); tbutil::Monitor<tbutil::Mutex>::Lock lock(*this); return timedWait(time_out); }
bool Condition::timedWaitSeconds(Mutex *tmutex, long seconds) { struct timeval tv; tv.tv_sec = seconds; tv.tv_usec = 0; return timedWait(tmutex, &tv); }
void YAC_LoggerThreadGroup::run() { while (!_bTerminate) { //100ms { Lock lock(*this); timedWait(100); } flush(); } }
void PropertyDimenReapThread::run() { string sDate,sFlag; LOG->info() << "PropertyDimenReapThread::run enter" << endl; int dbNumber = PropertyDimenDbManager::getInstance()->getDbNumber(); vector<map<PropDimenHead,PropBody > > mAllStatMsg(dbNumber); while (!_bTerminate) { try { vector<string> vFiles; TC_File::listDirectory(PropertyDimenServer::g_sClonePatch,vFiles,false); sort(vFiles.begin(),vFiles.end()); for(size_t i= 0; i< vFiles.size(); i++) { string sFileName = TC_File::extractFileName(TC_File::excludeFileExt(vFiles[i])); if(sFileName.length() != 12 || TC_Common::isdigit(sFileName) == false) { LOG->debug() << "file name invalid |" << vFiles[i] << endl; continue; } sDate = sFileName.substr(0,8); sFlag = sFileName.substr(8,4); getData(vFiles[i], mAllStatMsg); if( mAllStatMsg.size() > 0 ) { PropertyDimenDbManager::getInstance()->insert2MultiDbs( mAllStatMsg,sDate,sFlag); } TC_File::removeFile(vFiles[i],false); } } catch (exception& ex) { LOG->debug() << "PropertyDimenReapThread::run exception:"<< ex.what() << endl; } catch (... ) { LOG->debug() << "PropertyDimenReapThread::run PropertyDimenReapThread unkonw exception catched" << endl; } TC_ThreadLock::Lock lock(*this); timedWait(REAP_INTERVAL); } LOG->info() << "PropertyDimenReapThread::run exit" << endl; }
int timedGet(Buffer *b, int timeout) { int m, ret; enterMonitor(b->monitor); if (!b->full) { ret = timedWait(timeout); } if (ret) { m = b->message; b->full = 0; notifyAll(); } else { m = TIMEOUT; } exitMonitor(); return m; }
void TaskThread::Run() { NPT_LOG_FINEST_2("TaskThread %p [tid=%d] in", static_cast<NPT_Thread*>(this), GetCurrentThreadId()); Task *task = m_ic; if (task) { internalSetTask(task); task->exec(); internalSetTask(NULL); delete task; } while (!m_abortFlag) { { WriteLocker locker(m_pool->m_freeThreadListLock); m_sc = NULL; m_pool->m_freeThreadList.Add(this); } NPT_Result nr = timedWait(120 * 1000); task = NULL; { WriteLocker locker(m_pool->m_freeThreadListLock); TaskThread *th = this; NPT_List<TaskThread*>::Iterator it = m_pool->m_freeThreadList.Find(NPT_ObjectComparator<TaskThread*>(th)); if (it) { m_pool->m_freeThreadList.Erase(it); } task = m_sc; } if (task) { internalSetTask(task); task->exec(); internalSetTask(NULL); delete task; } if (nr == NPT_ERROR_TIMEOUT && !task) { break; } } NPT_LOG_FINEST_2("TaskThread %p [tid=%d] out", static_cast<NPT_Thread*>(this), GetCurrentThreadId()); }
bool Condition::wait(Mutex *tmutex) { return timedWait(tmutex, NULL); }