NetBSD support: revise CThread::sleep() (3)
migrate sleep()/usleep() to nanosleep() this can remove #ifdef __NetBSD__. and fixed bug that too sleep when ms >= 1000.
This commit is contained in:
parent
d16d57a8c9
commit
4fa676deb5
17
Thread.cpp
17
Thread.cpp
|
@ -95,21 +95,12 @@ void* CThread::helper(void* arg)
|
|||
|
||||
void CThread::sleep(unsigned int ms)
|
||||
{
|
||||
#if defined(__NetBSD__)
|
||||
unsigned int s = ms / 1000;
|
||||
useconds_t us = ms * 1000;
|
||||
struct timespec ts;
|
||||
|
||||
/* value for usleep() should be less than 1,000,000 */
|
||||
if (s)
|
||||
::sleep(s);
|
||||
if (us)
|
||||
::usleep(us);
|
||||
#else
|
||||
ts.tv_sec = ms / 1000;
|
||||
ts.tv_nsec = (ms % 1000) * 1000000;
|
||||
|
||||
/* other systems can accept larger value */
|
||||
::usleep(ms * 1000);
|
||||
|
||||
#endif
|
||||
::nanosleep(&ts, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue