Cygwin: sched_setscheduler: allow changes of the priority
[newlib-cygwin.git] / winsup / cygwin / local_includes / sigproc.h
blob46e26db19cc207fb58f7d95bcd60fd55a987b634
1 /* sigproc.h
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
9 #pragma once
10 #include <signal.h>
11 #include "sync.h"
13 #ifdef _NSIG
14 enum
16 __SIGFLUSH = -(_NSIG + 1),
17 __SIGSTRACE = -(_NSIG + 2),
18 __SIGCOMMUNE = -(_NSIG + 3),
19 __SIGPENDING = -(_NSIG + 4),
20 __SIGDELETE = -(_NSIG + 5), /* Not currently used */
21 __SIGFLUSHFAST = -(_NSIG + 6),
22 __SIGHOLD = -(_NSIG + 7),
23 __SIGNOHOLD = -(_NSIG + 8),
24 __SIGSETPGRP = -(_NSIG + 9),
25 __SIGTHREADEXIT = -(_NSIG + 10),
26 __SIGPENDINGALL = -(_NSIG + 11),
28 #endif
30 #define SIG_BAD_MASK (1 << (SIGKILL - 1))
32 enum procstuff
34 PROC_ADD_CHILD = 1, // set up a new child
35 PROC_ATTACH_CHILD = 2, // attach child or reattach after exec
36 PROC_EXEC_CLEANUP = 3, // cleanup waiting children after exec
37 PROC_CLEARWAIT = 4, // clear all waits - signal arrived
38 PROC_WAIT = 5, // setup for wait() for subproc
39 PROC_EXECING = 6, // used to get a lock when execing
40 PROC_NOTHING = 7 // nothing, really
43 struct sigpacket
45 siginfo_t si;
46 pid_t pid;
47 class _cygtls *sigtls;
48 sigset_t *mask;
49 union
51 HANDLE wakeup;
52 HANDLE thread_handle;
53 struct sigpacket *next;
55 int process ();
56 int setup_handler (void *, struct sigaction&, _cygtls *);
59 void sig_dispatch_pending (bool fast = false);
60 void set_signal_mask (sigset_t&, sigset_t);
61 int handle_sigprocmask (int sig, const sigset_t *set,
62 sigset_t *oldset, sigset_t& opmask);
64 void sig_clear (int);
65 void sig_set_pending (int);
66 int handle_sigsuspend (sigset_t);
68 int proc_subproc (DWORD, uintptr_t);
70 class _pinfo;
71 void proc_terminate ();
72 void sigproc_init ();
73 bool pid_exists (pid_t);
74 sigset_t sig_send (_pinfo *, siginfo_t&, class _cygtls * = NULL);
75 sigset_t sig_send (_pinfo *, int, class _cygtls * = NULL);
76 void signal_fixup_after_exec ();
77 void sigalloc ();
79 int kill_pgrp (pid_t, siginfo_t&);
80 void exit_thread (DWORD) __attribute__ ((noreturn));
81 void setup_signal_exit (int);
82 int sigwait_common (const sigset_t *, siginfo_t *, PLARGE_INTEGER);
84 class no_thread_exit_protect
86 static bool flag;
87 bool modify;
88 public:
89 no_thread_exit_protect (int) {flag = true; modify = true;}
90 ~no_thread_exit_protect ()
92 if (modify)
93 flag = false;
95 no_thread_exit_protect () {modify = false;}
96 operator int () {return flag;}
100 extern "C" void sigdelayed ();
102 extern char myself_nowait_dummy[];
104 extern struct sigaction *global_sigs;
106 class lock_signals
108 bool worked;
109 public:
110 lock_signals ()
112 worked = (bool) sig_send (NULL, __SIGHOLD) == 0;
114 operator int () const
116 return worked;
118 void dont_bother ()
120 worked = false;
122 ~lock_signals ()
124 if (worked)
125 sig_send (NULL, __SIGNOHOLD);
129 class lock_pthread
131 bool bother;
132 public:
133 lock_pthread (): bother (1)
135 pthread::atforkprepare ();
137 void dont_bother ()
139 bother = false;
141 ~lock_pthread ()
143 if (bother)
144 pthread::atforkparent ();
148 class hold_everything
150 bool& ischild;
151 /* Note the order of the locks below. It is important,
152 to avoid races, that the lock order be preserved.
154 pthread is first because it serves as a master lock
155 against other forks being attempted while this one is active.
157 signals is next to stop signal processing for the duration
158 of the fork.
160 process is last. If it is put before signals, then a deadlock
161 could be introduced if the process attempts to exit due to a signal. */
162 lock_pthread pthread;
163 lock_signals signals;
164 lock_process process;
166 public:
167 hold_everything (bool& x): ischild (x) {}
168 operator int () const {return signals;}
170 ~hold_everything()
172 if (ischild)
174 pthread.dont_bother ();
175 process.dont_bother ();
176 signals.dont_bother ();
182 #define myself_nowait ((_pinfo *) myself_nowait_dummy)