Added an unified Thread::idle method, use it instead of arbitrary

sleeps.


git-svn-id: http://voip.null.ro/svn/yate@2737 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2009-06-24 16:47:29 +00:00
parent 7d87860a33
commit 17bd631324
13 changed files with 38 additions and 22 deletions

View File

@ -1586,7 +1586,7 @@ bool DefaultLogic::handleUiAction(Message& msg, bool& stopLogic)
// block until client finishes initialization
while (!Client::self()->initialized())
Thread::msleep(10);
Thread::idle();
// call the appropiate function for the given action
Window* wnd = Client::getWindow(msg.getValue("window"));
if (*action == "set_status")
@ -1674,7 +1674,7 @@ bool DefaultLogic::handleCallCdr(Message& msg, bool& stopLogic)
// block until client finishes initialization
while (!Client::self()->initialized())
Thread::msleep(10);
Thread::idle();
// Update UI/history
callLogUpdate(msg,true,true);
@ -1709,7 +1709,7 @@ bool DefaultLogic::handleUserNotify(Message& msg, bool& stopLogic)
// block until client finishes initialization
while (!Client::self()->initialized())
Thread::msleep(10);
Thread::idle();
// Update interface
NamedList p("");

View File

@ -520,7 +520,7 @@ void EnginePrivate::run()
for (;;) {
s_makeworker = false;
Engine::self()->m_dispatcher.dequeue();
msleep(5,true);
Thread::idle(true);
}
}

View File

@ -48,6 +48,10 @@ static int pthread_attr_setinheritsched(pthread_attr_t *,int) { return 0; }
#endif
#endif
#ifndef THREAD_IDLE_MSEC
#define THREAD_IDLE_MSEC 5
#endif
namespace TelEngine {
class ThreadPrivate : public GenObject {
@ -287,7 +291,7 @@ void ThreadPrivate::pubdestroy()
s_tmutex.unlock();
if (done)
return;
Thread::msleep(5,false);
Thread::idle(false);
}
if (m_cancel && !cancel(true))
Debug(DebugWarn,"ThreadPrivate::pubdestroy() %p '%s' failed cancel [%p]",m_thread,m_name,this);
@ -629,6 +633,11 @@ void Thread::yield(bool exitCheck)
check();
}
void Thread::idle(bool exitCheck)
{
msleep(THREAD_IDLE_MSEC,exitCheck);
}
void Thread::sleep(unsigned int sec, bool exitCheck)
{
#ifdef _WINDOWS

View File

@ -257,7 +257,7 @@ void IAXEngine::runGetEvents()
{
while (1) {
if (!process()) {
Thread::msleep(2,true);
Thread::idle(true);
continue;
}
}

View File

@ -457,7 +457,7 @@ void MGCPEngine::runReceive()
while (true)
if (!receive(m_recvBuf,addr))
Thread::msleep(2,true);
Thread::idle(true);
else
Thread::check(true);
}
@ -467,7 +467,7 @@ void MGCPEngine::runProcess()
{
while (true)
if (!process())
Thread::msleep(2,true);
Thread::idle(true);
else
Thread::check(true);
}

View File

@ -304,7 +304,7 @@ void AsyncFFT::run()
DDebug(&__plugin,DebugAll,"AsyncFFT::run() [%p]",this);
while (!m_stop) {
while (!m_start) {
Thread::msleep(5);
Thread::idle();
if (m_stop)
return;
}

View File

@ -1077,7 +1077,7 @@ void ExtModReceiver::run()
Lock mylock(this);
if (m_in && m_in->canRetry()) {
mylock.drop();
Thread::msleep(5);
Thread::idle();
continue;
}
Debug("ExtModule",DebugWarn,"Read error %d on %p [%p]",errno,m_in,this);
@ -1676,7 +1676,7 @@ void ExtListener::run()
{
SocketAddr addr;
for (;;) {
Thread::msleep(5,true);
Thread::idle(true);
Socket* skt = m_socket.accept(addr);
if (!skt) {
if (m_socket.canRetry())

View File

@ -210,7 +210,7 @@ void RManagerThread::run()
{
for (;;)
{
Thread::msleep(10,true);
Thread::idle(true);
SocketAddr sa;
Socket* as = s_sock.accept(sa);
if (!as) {

View File

@ -481,7 +481,7 @@ void RudpThread::run()
if (m_rudp->readData())
Thread::check(true);
else
Thread::msleep(10,true);
Thread::idle(true);
}
}

View File

@ -579,13 +579,13 @@ RefPointer<MGCPMessage> MGCPWrapper::sendSync(MGCPMessage* mm, const SocketAddr&
while (m_msg) {
if (Thread::check(false))
return 0;
Thread::msleep(10);
Thread::idle();
}
MGCPTransaction* tr = s_engine->sendCommand(mm,address);
tr->userData(static_cast<GenObject*>(this));
m_tr = tr;
while (m_tr == tr)
Thread::msleep(10);
Thread::idle();
RefPointer<MGCPMessage> tmp = m_msg;
m_msg = 0;
if (tmp)
@ -1257,13 +1257,13 @@ RefPointer<MGCPMessage> MGCPCircuit::sendSync(MGCPMessage* mm)
while (m_msg) {
if (Thread::check(false))
return 0;
Thread::msleep(10);
Thread::idle();
}
MGCPTransaction* tr = s_engine->sendCommand(mm,ep->address);
tr->userData(static_cast<GenObject*>(this));
m_tr = tr;
while (m_tr == tr)
Thread::msleep(10);
Thread::idle();
RefPointer<MGCPMessage> tmp = m_msg;
m_msg = 0;
if (tmp)

View File

@ -294,7 +294,7 @@ void MyConn::runQueries()
Thread::yield(true);
}
else
Thread::msleep(10,true);
Thread::idle(true);
}
}

View File

@ -3254,7 +3254,7 @@ void YSocksWrapperWorker::run()
// NOTE: The SOCKS protocol is negotiated by the engine
bool waitStart = !m_wrapper->autoStart();
while (!invalid() && m_wrapper->state() != YSocksWrapper::Running) {
Thread::msleep(20,false);
Thread::msleep(20);
if (waitStart && m_wrapper->state() == YSocksWrapper::WaitStart) {
waitStart = false;
m_wrapper->notify("established");
@ -3266,13 +3266,13 @@ void YSocksWrapperWorker::run()
// Read data
while (!invalid()) {
if (!m_wrapper->canRecv()) {
Thread::msleep(20,false);
Thread::idle();
continue;
}
if (m_wrapper->recvData())
Thread::yield(false);
Thread::yield();
else
Thread::msleep(2,false);
Thread::idle();
}
break;
}

View File

@ -3896,6 +3896,13 @@ public:
*/
static void yield(bool exitCheck = false);
/**
* Sleep for a system dependent period adequate for an idle thread.
* On most operating systems this is a 5 msec sleep.
* @param exitCheck Terminate the thread if asked so
*/
static void idle(bool exitCheck = false);
/**
* Sleep for a number of seconds
* @param sec Number of seconds to sleep