diff options
Diffstat (limited to 'winsup/cygwin/sigproc.h')
-rw-r--r-- | winsup/cygwin/sigproc.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/winsup/cygwin/sigproc.h b/winsup/cygwin/sigproc.h index 2900da4cc..ffe75a8d3 100644 --- a/winsup/cygwin/sigproc.h +++ b/winsup/cygwin/sigproc.h @@ -11,6 +11,7 @@ details. */ #pragma once #include <signal.h> +#include "sync.h" #ifdef NSIG enum @@ -121,4 +122,81 @@ extern char myself_nowait_dummy[]; extern struct sigaction *global_sigs; +class lock_signals +{ + bool worked; +public: + lock_signals () + { + worked = sig_send (NULL, __SIGHOLD) == 0; + } + operator int () const + { + return worked; + } + void dont_bother () + { + worked = false; + } + ~lock_signals () + { + if (worked) + sig_send (NULL, __SIGNOHOLD); + } +}; + +class lock_pthread +{ + bool bother; +public: + lock_pthread (): bother (1) + { + pthread::atforkprepare (); + } + void dont_bother () + { + bother = false; + } + ~lock_pthread () + { + if (bother) + pthread::atforkparent (); + } +}; + +class hold_everything +{ +public: /* DELETEME*/ + bool ischild; + /* Note the order of the locks below. It is important, + to avoid races, that the lock order be preserved. + + pthread is first because it serves as a master lock + against other forks being attempted while this one is active. + + signals is next to stop signal processing for the duration + of the fork. + + process is last. If it is put before signals, then a deadlock + could be introduced if the process attempts to exit due to a signal. */ + lock_pthread pthread; + lock_signals signals; + lock_process process; + +public: + hold_everything (bool x = false): ischild (x) {} + operator int () const {return signals;} + + ~hold_everything() + { + if (ischild) + { + pthread.dont_bother (); + process.dont_bother (); + signals.dont_bother (); + } + } + +}; + #define myself_nowait ((_pinfo *) myself_nowait_dummy) |