"""
This module is for masking and unmasking unix signals for the Python process.
This is very useful as a tool in building safe multi-threaded and multi-process
applications, in addition to being an important component in running
subprocesses safely.
"""

import _signal_mask

def mask_all():
  oldmask = _signal_mask.ffi.new('sigset_t *')
  newmask = _signal_mask.ffi.new('sigset_t *')
  _signal_mask.lib.sigfillset(newmask)
  _signal_mask.lib.pthread_sigmask(_signal_mask.lib.SIG_SETMASK, newmask, oldmask);
  return oldmask;

def reset_all():
  _signal_mask.lib.reset_signals();

def unmask_all(oldmask):
  _signal_mask.lib.pthread_sigmask(_signal_mask.lib.SIG_SETMASK, oldmask, _signal_mask.ffi.NULL);
