diff options
author | Dan Gohman <sunfish@mozilla.com> | 2019-05-06 20:53:42 -0700 |
---|---|---|
committer | Dan Gohman <sunfish@mozilla.com> | 2019-05-17 15:23:14 -0700 |
commit | 45ec8fc2eea2a49e618f8febdae68df07f98d68d (patch) | |
tree | ac604c8d49c502d1b1c85a3d99e546823bb72cfe /src/sched.rs | |
parent | 434b8669a11eed573968781c6732d9eccd24b765 (diff) | |
download | nix-45ec8fc2eea2a49e618f8febdae68df07f98d68d.zip |
Implement `sched_yield`.
This adds the `sched_yield` function, which is part of POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_yield.html
and widely implemented on Unix-family platforms.
Diffstat (limited to 'src/sched.rs')
-rw-r--r-- | src/sched.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/sched.rs b/src/sched.rs index f8f3a68a..d381cbb5 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -85,6 +85,17 @@ pub fn sched_setaffinity(pid: Pid, cpuset: &CpuSet) -> Result<()> { Errno::result(res).map(drop) } +/// Explicitly yield the processor to other threads. +/// +/// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_yield.html) +pub fn sched_yield() -> Result<()> { + let res = unsafe { + libc::sched_yield() + }; + + Errno::result(res).map(drop) +} + pub fn clone(mut cb: CloneCb, stack: &mut [u8], flags: CloneFlags, |