summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZhe Wang <0x1998@gmail.com>2016-02-26 18:17:18 +0800
committerZhe Wang <0x1998@gmail.com>2016-02-27 01:53:19 +0800
commite850dc8c45636826ebac016d266a326c96d05fc9 (patch)
tree752787b10b966b55cba522ec5a61ff62daf5d791 /src
parent5aa0cc219d4500a13ea70876127dcdd019cbcc31 (diff)
downloadnix-e850dc8c45636826ebac016d266a326c96d05fc9.zip
Add sigwait
Diffstat (limited to 'src')
-rw-r--r--src/sys/signal.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index b21a0a96..3822d391 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -295,6 +295,8 @@ mod ffi {
pub fn kill(pid: pid_t, signum: c_int) -> c_int;
pub fn raise(signum: c_int) -> c_int;
+
+ pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int;
}
}
@@ -370,6 +372,15 @@ impl SigSet {
try!(pthread_sigmask(how, Some(self), Some(&mut oldmask)));
Ok(oldmask)
}
+
+ /// Suspends execution of the calling thread until one of the signals in the
+ /// signal mask becomes pending, and returns the accepted signal.
+ pub fn wait(&self) -> Result<SigNum> {
+ let mut signum: SigNum = unsafe { mem::uninitialized() };
+ let res = unsafe { ffi::sigwait(&self.sigset as *const sigset_t, &mut signum) };
+
+ Errno::result(res).map(|_| signum)
+ }
}
impl AsRef<sigset_t> for SigSet {
@@ -512,4 +523,15 @@ mod tests {
assert!(oldmask.contains(SIGUSR1).unwrap());
assert!(!oldmask.contains(SIGUSR2).unwrap());
}
+
+ #[test]
+ fn test_sigwait() {
+ let mut mask = SigSet::empty();
+ mask.add(SIGUSR1).unwrap();
+ mask.add(SIGUSR2).unwrap();
+ mask.thread_block().unwrap();
+
+ raise(SIGUSR1).unwrap();
+ assert_eq!(mask.wait().unwrap(), SIGUSR1);
+ }
}