mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
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:
parent
d826ffff63
commit
a456517b42
1 changed files with 11 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue