… | |
… | |
5 | typedef volatile sig_atomic_t atomic_t; |
5 | typedef volatile sig_atomic_t atomic_t; |
6 | |
6 | |
7 | static int *sig_pending, *psig_pend; /* make local copies because of missing THX */ |
7 | static int *sig_pending, *psig_pend; /* make local copies because of missing THX */ |
8 | static Sighandler_t old_sighandler; |
8 | static Sighandler_t old_sighandler; |
9 | static atomic_t async_pending; |
9 | static atomic_t async_pending; |
|
|
10 | |
|
|
11 | #define PERL_VERSION_ATLEAST(a,b,c) \ |
|
|
12 | (PERL_REVISION > (a) \ |
|
|
13 | || (PERL_REVISION == (a) \ |
|
|
14 | && (PERL_VERSION > (b) \ |
|
|
15 | || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c))))) |
|
|
16 | |
|
|
17 | #if defined(HAS_SIGACTION) && defined(SA_SIGINFO) |
|
|
18 | # define HAS_SA_SIGINFO 1 |
|
|
19 | #endif |
|
|
20 | |
|
|
21 | #if !PERL_VERSION_ATLEAST(5,10,0) |
|
|
22 | # undef HAS_SA_SIGINFO |
|
|
23 | #endif |
10 | |
24 | |
11 | static int |
25 | static int |
12 | extract_fd (SV *fh, int wr) |
26 | extract_fd (SV *fh, int wr) |
13 | { |
27 | { |
14 | int fd = PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh))); |
28 | int fd = PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh))); |
… | |
… | |
147 | if (async->pending && !async->blocked) |
161 | if (async->pending && !async->blocked) |
148 | handle_async (async); |
162 | handle_async (async); |
149 | } |
163 | } |
150 | } |
164 | } |
151 | |
165 | |
152 | #if defined(HAS_SIGACTION) && defined(SA_SIGINFO) |
166 | #if HAS_SA_SIGINFO |
153 | static Signal_t async_sighandler (int signum, siginfo_t *si, void *sarg) |
167 | static Signal_t async_sighandler (int signum, siginfo_t *si, void *sarg) |
154 | { |
168 | { |
155 | if (signum == 9) |
169 | if (signum == 9) |
156 | handle_asyncs (); |
170 | handle_asyncs (); |
157 | else |
171 | else |
… | |
… | |
193 | |
207 | |
194 | SV * |
208 | SV * |
195 | _alloc (SV *cb, void *c_cb, void *c_arg, SV *fh_r, SV *fh_w) |
209 | _alloc (SV *cb, void *c_cb, void *c_arg, SV *fh_r, SV *fh_w) |
196 | CODE: |
210 | CODE: |
197 | { |
211 | { |
198 | SV *cv = SvOK (cb) ? SvREFCNT_inc_NN (get_cb (cb)) : 0; |
212 | SV *cv = SvOK (cb) ? SvREFCNT_inc (get_cb (cb)) : 0; |
199 | int fd_r = SvOK (fh_r) ? extract_fd (fh_r, 0) : -1; |
213 | int fd_r = SvOK (fh_r) ? extract_fd (fh_r, 0) : -1; |
200 | int fd_w = SvOK (fh_w) ? extract_fd (fh_w, 1) : -1; |
214 | int fd_w = SvOK (fh_w) ? extract_fd (fh_w, 1) : -1; |
201 | struct async *async; |
215 | struct async *async; |
202 | |
216 | |
203 | Newz (0, async, 1, struct async); |
217 | Newz (0, async, 1, struct async); |