ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Async-Interrupt/Interrupt.xs
(Generate patch)

Comparing Async-Interrupt/Interrupt.xs (file contents):
Revision 1.6 by root, Sat Jul 11 22:16:50 2009 UTC vs.
Revision 1.7 by root, Tue Jul 14 14:18:10 2009 UTC

84typedef struct { 84typedef struct {
85 SV *cb; 85 SV *cb;
86 void (*c_cb)(pTHX_ void *c_arg, int value); 86 void (*c_cb)(pTHX_ void *c_arg, int value);
87 void *c_arg; 87 void *c_arg;
88 SV *fh_r, *fh_w; 88 SV *fh_r, *fh_w;
89 int blocked;
90 int signum; 89 int signum;
90 volatile int blocked;
91 91
92 int fd_r, fd_w; 92 int fd_r;
93 volatile int fd_w;
93 int fd_wlen; 94 int fd_wlen;
94 atomic_t fd_enable; 95 atomic_t fd_enable;
95 atomic_t value; 96 atomic_t value;
96 atomic_t pending; 97 atomic_t pending;
97} async_t; 98} async_t;
115 async->pending = 1; 116 async->pending = 1;
116 async_pending = 1; 117 async_pending = 1;
117 psig_pend [9] = 1; 118 psig_pend [9] = 1;
118 *sig_pending = 1; 119 *sig_pending = 1;
119 120
121 {
122 int fd_w = async->fd_w;
123 int fd_enable = async->fd_enable;
124
120 if (!pending && async->fd_w >= 0 && async->fd_enable) 125 if (!pending && fd_w >= 0 && fd_enable)
121 if (write (async->fd_w, pipedata, async->fd_wlen) < 0 && errno == EINVAL) 126 if (write (fd_w, pipedata, async->fd_wlen) < 0 && errno == EINVAL)
122 /* on EINVAL we assume it's an eventfd */ 127 /* on EINVAL we assume it's an eventfd */
123 write (async->fd_w, pipedata, (async->fd_wlen = 8)); 128 write (fd_w, pipedata, (async->fd_wlen = 8));
129 }
124} 130}
125 131
126static void 132static void
127handle_async (async_t *async) 133handle_async (async_t *async)
128{ 134{
226async_sigsend (int signum) 232async_sigsend (int signum)
227{ 233{
228 async_signal (sig_async [signum], 0); 234 async_signal (sig_async [signum], 0);
229} 235}
230 236
231static void 237#define block(async) ++(async)->blocked
232scope_block_cb (pTHX_ void *async_sv)
233{
234 async_t *async = SvASYNC_nrv ((SV *)async_sv);
235 238
239static void
240unblock (async_t *async)
241{
236 --async->blocked; 242 --async->blocked;
237 if (async->pending && !async->blocked) 243 if (async->pending && !async->blocked)
238 handle_async (async); 244 handle_async (async);
245}
239 246
247static void
248scope_block_cb (pTHX_ void *async_sv)
249{
250 async_t *async = SvASYNC_nrv ((SV *)async_sv);
251 unblock (async);
240 SvREFCNT_dec (async_sv); 252 SvREFCNT_dec (async_sv);
241} 253}
242 254
243MODULE = Async::Interrupt PACKAGE = Async::Interrupt 255MODULE = Async::Interrupt PACKAGE = Async::Interrupt
244 256
308 async_signal (async, value); 320 async_signal (async, value);
309 321
310void 322void
311block (async_t *async) 323block (async_t *async)
312 CODE: 324 CODE:
313 ++async->blocked; 325 block (async);
314 326
315void 327void
316unblock (async_t *async) 328unblock (async_t *async)
317 CODE: 329 CODE:
318 --async->blocked; 330 unblock (async);
319 if (async->pending && !async->blocked)
320 handle_async (async);
321 331
322void 332void
323scope_block (SV *self) 333scope_block (SV *self)
324 CODE: 334 CODE:
325{ 335{
326 SV *async_sv = SvRV (self); 336 SV *async_sv = SvRV (self);
327 async_t *async = SvASYNC_nrv (async_sv); 337 async_t *async = SvASYNC_nrv (async_sv);
328 ++async->blocked; 338 block (async);
329 339
330 LEAVE; /* unfortunately, perl sandwiches XS calls into ENTER/LEAVE */ 340 LEAVE; /* unfortunately, perl sandwiches XS calls into ENTER/LEAVE */
331 SAVEDESTRUCTOR_X (scope_block_cb, (void *)SvREFCNT_inc (async_sv)); 341 SAVEDESTRUCTOR_X (scope_block_cb, (void *)SvREFCNT_inc (async_sv));
332 ENTER; /* unfortunately, perl sandwiches XS calls into ENTER/LEAVE */ 342 ENTER; /* unfortunately, perl sandwiches XS calls into ENTER/LEAVE */
333} 343}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines