Skip to content

Commit

Permalink
Implement sched_yield.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sunfishcode committed May 17, 2019
1 parent 434b866 commit 45ec8fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/))
Expand Down
11 changes: 11 additions & 0 deletions src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 45ec8fc

Please sign in to comment.