mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +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
47c0de95f0
commit
3263c76ab3
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)
|
* to avoid objc messaging and object allocation/deallocation (NSDate)
|
||||||
* overheads.<br />
|
* overheads.<br />
|
||||||
* Used to implement [NSThread+sleepUntilDate:]
|
* Used to implement [NSThread+sleepUntilDate:]
|
||||||
|
* If the date is in the past, this function simply allows other threads
|
||||||
|
* (if any) to run.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
GSSleepUntilIntervalSinceReferenceDate(NSTimeInterval when)
|
GSSleepUntilIntervalSinceReferenceDate(NSTimeInterval when)
|
||||||
|
@ -154,6 +156,11 @@ GSSleepUntilIntervalSinceReferenceDate(NSTimeInterval when)
|
||||||
|
|
||||||
// delay is always the number of seconds we still need to wait
|
// delay is always the number of seconds we still need to wait
|
||||||
delay = when - GSTimeNow();
|
delay = when - GSTimeNow();
|
||||||
|
if (delay <= 0)
|
||||||
|
{
|
||||||
|
sched_yield();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_NANOSLEEP
|
#ifdef HAVE_NANOSLEEP
|
||||||
// Avoid any possibility of overflow by sleeping in chunks.
|
// Avoid any possibility of overflow by sleeping in chunks.
|
||||||
|
@ -556,6 +563,10 @@ static NSThread *defaultThread;
|
||||||
GSSleepUntilIntervalSinceReferenceDate(
|
GSSleepUntilIntervalSinceReferenceDate(
|
||||||
[NSDate timeIntervalSinceReferenceDate] + ti);
|
[NSDate timeIntervalSinceReferenceDate] + ti);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sched_yield();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue