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

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.152 by root, Tue Jul 14 00:32:27 2009 UTC vs.
Revision 1.153 by root, Wed Jul 15 01:36:04 2009 UTC

160 160
161static SV *on_next_submit; 161static SV *on_next_submit;
162static int next_pri = EIO_PRI_DEFAULT; 162static int next_pri = EIO_PRI_DEFAULT;
163static int max_outstanding; 163static int max_outstanding;
164 164
165static int respipe_osf [2], respipe [2] = { -1, -1 }; 165static int respipe_osf [2];
166static s_epipe respipe;
166 167
167static void req_destroy (aio_req req); 168static void req_destroy (aio_req req);
168static void req_cancel (aio_req req); 169static void req_cancel (aio_req req);
169 170
170static void want_poll (void) 171static void want_poll (void)
171{ 172{
172 /* write a dummy byte to the pipe so fh becomes ready */ 173 /* write a dummy byte to the pipe so fh becomes ready */
173 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); 174 s_epipe_signal (&respipe);
174} 175}
175 176
176static void done_poll (void) 177static void done_poll (void)
177{ 178{
178 /* read any signals sent by the worker threads */ 179 /* read any signals sent by the worker threads */
179 char buf [4]; 180 s_epipe_drain (&respipe);
180 while (respipe_read (respipe [0], buf, 4) == 4)
181 ;
182} 181}
183 182
184/* must be called at most once */ 183/* must be called at most once */
185static SV *req_sv (aio_req req, const char *klass) 184static SV *req_sv (aio_req req, const char *klass)
186{ 185{
441 grp->sv2 = 0; 440 grp->sv2 = 0;
442 441
443 eio_grp_cancel (grp); 442 eio_grp_cancel (grp);
444} 443}
445 444
446#ifdef USE_SOCKETS_AS_HANDLES
447# define TO_SOCKET(x) (win32_get_osfhandle (x))
448#else
449# define TO_SOCKET(x) (x)
450#endif
451
452static void 445static void
453create_respipe (void) 446create_respipe (void)
454{ 447{
455 int old_readfd = respipe [0];
456
457 if (respipe [1] >= 0)
458 respipe_close (TO_SOCKET (respipe [1]));
459
460#ifdef _WIN32
461 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
462#else
463 if (pipe (respipe)) 448 if (s_epipe_renew (&respipe))
464#endif
465 croak ("unable to initialize result pipe"); 449 croak ("unable to initialize result pipe");
466 450
467 if (old_readfd >= 0)
468 {
469 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
470 croak ("unable to initialize result pipe(2)");
471
472 respipe_close (respipe [0]);
473 respipe [0] = old_readfd;
474 }
475
476#ifdef _WIN32
477 int arg = 1;
478 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
479 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
480#else
481 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
482 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
483#endif
484 croak ("unable to initialize result pipe(3)");
485
486 respipe_osf [0] = TO_SOCKET (respipe [0]); 451 respipe_osf [0] = S_TO_SOCKET (respipe.fd [0]);
487 respipe_osf [1] = TO_SOCKET (respipe [1]); 452 respipe_osf [1] = S_TO_SOCKET (respipe.fd [1]);
488} 453}
489 454
490static void poll_wait (void) 455static void poll_wait (void)
491{ 456{
492 fd_set rfd;
493
494 while (eio_nreqs ()) 457 while (eio_nreqs ())
495 { 458 {
496 int size; 459 int size;
497 460
498 X_LOCK (reslock); 461 X_LOCK (reslock);
502 if (size) 465 if (size)
503 return; 466 return;
504 467
505 etp_maybe_start_thread (); 468 etp_maybe_start_thread ();
506 469
507 FD_ZERO (&rfd); 470 s_epipe_wait (&respipe);
508 FD_SET (respipe [0], &rfd);
509
510 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
511 } 471 }
512} 472}
513 473
514static int poll_cb (void) 474static int poll_cb (void)
515{ 475{
1119 1079
1120int 1080int
1121poll_fileno() 1081poll_fileno()
1122 PROTOTYPE: 1082 PROTOTYPE:
1123 CODE: 1083 CODE:
1124 RETVAL = respipe [0]; 1084 RETVAL = s_epipe_fd (&respipe);
1125 OUTPUT: 1085 OUTPUT:
1126 RETVAL 1086 RETVAL
1127 1087
1128int 1088int
1129poll_cb(...) 1089poll_cb(...)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines