Double the system idle interval when running in client mode, make it adjustable from the config file.

git-svn-id: http://voip.null.ro/svn/yate@3163 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2010-03-31 09:36:58 +00:00
parent 3f634396d6
commit 42d4dded8f
4 changed files with 29 additions and 3 deletions

View File

@ -33,6 +33,11 @@
; of zero disables such warnings
;warntime=0
; idlemsec: int: System idle time in milliseconds
; Set to zero to use platform default
; If not set the platform default is doubled only in client mode
;idlemsec=
; wintimer: int: Requested timer resolution in milliseconds (Windows only, does
; not work on 9x and ME). The default resolution depends on hardware, Windows
; version and currently running programs

View File

@ -989,6 +989,7 @@ int Engine::run()
Debug(DebugWarn,"Timer resolution not set: %s",err.c_str());
}
#endif
Thread::idleMsec(s_cfg.getIntValue("general","idlemsec",(clientMode() ? 2 * Thread::idleMsec() : 0)));
SysUsage::init();
s_runid = Time::secNow();

View File

@ -51,6 +51,8 @@ static int pthread_attr_setinheritsched(pthread_attr_t *,int) { return 0; }
#ifndef THREAD_IDLE_MSEC
#define THREAD_IDLE_MSEC 5
#endif
#define THREAD_IDLE_MIN 1
#define THREAD_IDLE_MAX 20
namespace TelEngine {
@ -132,6 +134,7 @@ static TokenDict s_prio[] = {
{ 0, 0 }
};
static unsigned long s_idleMs = 1000 * THREAD_IDLE_MSEC;
static ObjList s_threads;
static Mutex s_tmutex(true,"Thread");
@ -659,7 +662,7 @@ void Thread::idle(bool exitCheck)
Debug(DebugMild,"Thread '%s' idling with %d mutex locks held [%p]",
t->name(),t->locks(),t);
#endif
msleep(THREAD_IDLE_MSEC,exitCheck);
msleep(s_idleMs,exitCheck);
}
void Thread::sleep(unsigned int sec, bool exitCheck)
@ -702,12 +705,23 @@ void Thread::usleep(unsigned long usec, bool exitCheck)
unsigned long Thread::idleUsec()
{
return THREAD_IDLE_MSEC * 1000;
return s_idleMs * 1000;
}
unsigned long Thread::idleMsec()
{
return THREAD_IDLE_MSEC;
return s_idleMs;
}
void Thread::idleMsec(unsigned long msec)
{
if (msec == 0)
msec = THREAD_IDLE_MSEC;
else if (msec < THREAD_IDLE_MIN)
msec = THREAD_IDLE_MIN;
else if (msec > THREAD_IDLE_MAX)
msec = THREAD_IDLE_MAX;
s_idleMs = msec;
}
Thread::Priority Thread::priority(const char* name, Thread::Priority defvalue)

View File

@ -4620,6 +4620,12 @@ public:
*/
static unsigned long idleMsec();
/**
* Set the idle sleep interval or reset to platform default
* @param msec Sleep interval in milliseconds, platform default if zero
*/
static void idleMsec(unsigned long msec);
/**
* Get a pointer to the currently running thread
* @return A pointer to the current thread or NULL for the main thread