From 45ec8fc2eea2a49e618f8febdae68df07f98d68d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 6 May 2019 20:53:42 -0700 Subject: 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. --- src/sched.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/sched.rs') 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, -- cgit v1.2.3