Yield if asked to sleep

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28636 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-09-08 17:56:58 +00:00
parent d826ffff63
commit a456517b42

View file

@ -145,6 +145,8 @@ static NSNotificationCenter *nc = nil;
* to avoid objc messaging and object allocation/deallocation (NSDate)
* overheads.<br />
* Used to implement [NSThread+sleepUntilDate:]
* If the date is in the past, this function simply allows other threads
* (if any) to run.
*/
void
GSSleepUntilIntervalSinceReferenceDate(NSTimeInterval when)
@ -154,6 +156,11 @@ GSSleepUntilIntervalSinceReferenceDate(NSTimeInterval when)
// delay is always the number of seconds we still need to wait
delay = when - GSTimeNow();
if (delay <= 0)
{
sched_yield();
return;
}
#ifdef HAVE_NANOSLEEP
// Avoid any possibility of overflow by sleeping in chunks.
@ -556,6 +563,10 @@ static NSThread *defaultThread;
GSSleepUntilIntervalSinceReferenceDate(
[NSDate timeIntervalSinceReferenceDate] + ti);
}
else
{
sched_yield();
}
}
/**