summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-05-18 06:56:24 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-05-18 06:56:24 +0000
commit1135b648299846dc901e8d53ba2d080bf09aeb3f (patch)
tree40a52ba4eb704110d50dec689c568bee1fd55756
parent0a7adb1a1e64821ac4b203a7bd9dc6abd910a17c (diff)
parent45ec8fc2eea2a49e618f8febdae68df07f98d68d (diff)
downloadnix-1135b648299846dc901e8d53ba2d080bf09aeb3f.zip
Merge #1050
1050: Implement `sched_yield`. r=asomers a=sunfishcode 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. Co-authored-by: Dan Gohman <sunfish@mozilla.com>
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/sched.rs11
2 files changed, 13 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ff67fde0..2ba1a469 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#1045](https://github.com/nix-rust/nix/pull/1045))
- Add `forkpty`
([#1042](https://github.com/nix-rust/nix/pull/1042))
+- Add `sched_yield`
+ ([#1050](https://github.com/nix-rust/nix/pull/1050))
### Changed
- `PollFd` event flags renamed to `PollFlags` ([#1024](https://github.com/nix-rust/nix/pull/1024/))
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,