Skip to content

Commit

Permalink
Add SigSet::extend and SigSet::clear.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiveop committed Apr 22, 2016
1 parent 0210e30 commit 8698588
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,27 @@ impl SigSet {
Errno::result(res).map(drop)
}

pub fn clear(&mut self) -> Result<()> {
let res = unsafe { libc::sigemptyset(&mut self.sigset as *mut libc::sigset_t) };

Errno::result(res).map(drop)
}

pub fn remove(&mut self, signum: SigNum) -> Result<()> {
let res = unsafe { libc::sigdelset(&mut self.sigset as *mut libc::sigset_t, signum) };

Errno::result(res).map(drop)
}

pub fn extend(&mut self, other: &SigSet) -> Result<()> {
for i in 1..NSIG {
if try!(other.contains(i)) {
try!(self.add(i));
}
}
Ok(())
}

pub fn contains(&self, signum: SigNum) -> Result<bool> {
let res = unsafe { libc::sigismember(&self.sigset as *const libc::sigset_t, signum) };

Expand Down Expand Up @@ -260,6 +275,28 @@ mod tests {
assert_eq!(all.contains(SIGUSR2), Ok(true));
}

#[test]
fn test_clear() {
let mut set = SigSet::all();
set.clear().unwrap();
for i in 1..NSIG {
assert_eq!(set.contains(i), Ok(false));
}
}

#[test]
fn test_extend() {
let mut one_signal = SigSet::empty();
one_signal.add(SIGUSR1).unwrap();

let mut two_signals = SigSet::empty();
two_signals.add(SIGUSR2).unwrap();
two_signals.extend(&one_signal).unwrap();

assert_eq!(two_signals.contains(SIGUSR1), Ok(true));
assert_eq!(two_signals.contains(SIGUSR2), Ok(true));
}

#[test]
fn test_thread_signal_block() {
let mut mask = SigSet::empty();
Expand Down

0 comments on commit 8698588

Please sign in to comment.