2 +----------------------------------------------------------------------+
3 | Zend Signal Handling |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2008 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Lucas Nealan <lucas@php.net> |
16 | Arnaud Le Blanc <lbarnaud@php.net> |
17 +----------------------------------------------------------------------+
34 #ifndef ZEND_SIGNAL_QUEUE_SIZE
35 #define ZEND_SIGNAL_QUEUE_SIZE 32
39 typedef struct _zend_signal_entry_t
{
40 int flags
; /* sigaction style flags */
41 void* handler
; /* signal handler or context */
42 } zend_signal_entry_t
;
44 typedef struct _zend_signal_t
{
50 typedef struct _zend_signal_queue_t
{
51 zend_signal_t zend_signal
;
52 struct _zend_signal_queue_t
*next
;
53 } zend_signal_queue_t
;
56 typedef struct _zend_signal_globals_t
{
58 int blocked
; /* 0==TRUE, -1==FALSE */
59 int running
; /* in signal handler execution */
60 int active
; /* internal signal handling is enabled */
61 int initialized
; /* memory initialized */
62 zend_bool check
; /* check for replaced handlers on shutdown */
63 zend_signal_entry_t handlers
[NSIG
];
64 zend_signal_queue_t pstorage
[ZEND_SIGNAL_QUEUE_SIZE
], *phead
, *ptail
, *pavail
; /* pending queue */
65 } zend_signal_globals_t
;
68 # define SIGG(v) TSRMG(zend_signal_globals_id, zend_signal_globals_t *, v)
70 ZEND_API
extern int zend_signal_globals_id
;
72 # define ZEND_SIGNAL_BLOCK_INTERRUPUTIONS() if (EXPECTED(zend_signal_globals_id)) { SIGG(depth)++; }
73 # define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() if (EXPECTED(zend_signal_globals_id) && UNEXPECTED((--SIGG(depth))==SIGG(blocked))) { zend_signal_handler_unblock(TSRMLS_C); }
75 # define SIGG(v) (zend_signal_globals.v)
76 extern ZEND_API zend_signal_globals_t zend_signal_globals
;
77 # define ZEND_SIGNAL_BLOCK_INTERRUPUTIONS() SIGG(depth)++;
78 # define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() if (UNEXPECTED((--SIGG(depth))==SIGG(blocked))) { zend_signal_handler_unblock(TSRMLS_C); }
81 # define SIGNAL_BEGIN_CRITICAL() sigset_t oldmask; \
82 zend_sigprocmask(SIG_BLOCK, &global_sigmask, &oldmask);
83 # define SIGNAL_END_CRITICAL() zend_sigprocmask(SIG_SETMASK, &oldmask, NULL);
85 void zend_signal_handler_defer(int signo
, siginfo_t
*siginfo
, void *context
);
86 ZEND_API
void zend_signal_handler_unblock();
87 void zend_signal_activate(TSRMLS_D
);
88 void zend_signal_deactivate(TSRMLS_D
);
89 void zend_signal_startup();
90 void zend_signal_shutdown(TSRMLS_D
);
91 ZEND_API
int zend_signal(int signo
, void (*handler
)(int) TSRMLS_DC
);
92 ZEND_API
int zend_sigaction(int signo
, const struct sigaction
*act
, struct sigaction
*oldact TSRMLS_DC
);
95 #define zend_sigprocmask(signo, set, oldset) tsrm_sigmask((signo), (set), (oldset))
97 #define zend_sigprocmask(signo, set, oldset) sigprocmask((signo), (set), (oldset))
100 #endif /* ZEND_SIGNAL_H */
106 * indent-tabs-mode: t