xref: /unit/src/nxt_signal.h (revision 0:a63ceefd6ab0)
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #ifndef _NXT_UNIX_SIGNAL_H_INCLUDED_
8 #define _NXT_UNIX_SIGNAL_H_INCLUDED_
9 
10 
11 typedef struct nxt_event_sig_s  nxt_event_sig_t;
12 
13 struct nxt_event_sig_s {
14     int                         signo;
15     nxt_work_handler_t          handler;
16     const char                  *name;
17 };
18 
19 #define nxt_event_signal(sig, handler)                                        \
20     { sig, handler, #sig }
21 
22 #define nxt_event_signal_end                                                  \
23     { 0, NULL, NULL }
24 
25 
26 typedef struct {
27     /* Used by epoll and eventport. */
28     nxt_work_handler_t          handler;
29 
30     const nxt_event_sig_t       *sigev;
31     sigset_t                    sigmask;
32 
33 #if (NXT_THREADS)
34     /* Used by the signal thread. */
35     nxt_pid_t                   process;
36     nxt_thread_handle_t         thread;
37 #endif
38 } nxt_event_signals_t;
39 
40 
41 nxt_event_signals_t *nxt_event_engine_signals(const nxt_event_sig_t *sigev);
42 
43 #if (NXT_THREADS)
44 
45 #define                                                                       \
46 nxt_event_engine_signals_start(engine)                                        \
47     nxt_signal_thread_start(engine)
48 
49 #define                                                                       \
50 nxt_event_engine_signals_stop(engine)                                         \
51     nxt_signal_thread_stop(engine)
52 
53 
54 NXT_EXPORT nxt_int_t nxt_signal_thread_start(nxt_event_engine_t *engine);
55 NXT_EXPORT void nxt_signal_thread_stop(nxt_event_engine_t *engine);
56 
57 #else /* !(NXT_THREADS) */
58 
59 #define                                                                       \
60 nxt_event_engine_signals_start(engine)                                        \
61     nxt_signal_handlers_start(engine)
62 
63 #define                                                                       \
64 nxt_event_engine_signals_stop(engine)                                         \
65     nxt_signal_handlers_stop(engine)
66 
67 
68 NXT_EXPORT nxt_int_t nxt_signal_handlers_start(nxt_event_engine_t *engine);
69 NXT_EXPORT void nxt_signal_handlers_stop(nxt_event_engine_t *engine);
70 
71 #endif
72 
73 
74 #endif /* _NXT_UNIX_SIGNAL_H_INCLUDED_ */
75