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.120 by root, Sun May 11 19:17:09 2008 UTC vs.
Revision 1.125 by root, Thu Jun 19 09:05:43 2008 UTC

65# include <signal.h> 65# include <signal.h>
66# define EIO_STRUCT_DIRENT struct dirent 66# define EIO_STRUCT_DIRENT struct dirent
67 67
68#endif 68#endif
69 69
70/* perl stupidly overrides readdir and maybe others */
71/* with thread-unsafe versions, imagine that :( */
72#undef readdir
73#undef opendir
74#undef closedir
75
70#define EIO_STRUCT_STAT Stat_t 76#define EIO_STRUCT_STAT Stat_t
71 77
72/* use NV for 32 bit perls as it allows larger offsets */ 78/* use NV for 32 bit perls as it allows larger offsets */
73#if IVSIZE >= 8 79#if IVSIZE >= 8
74# define SvVAL64 SvIV 80# define SvVAL64 SvIV
80typedef SV SV8; /* byte-sv, used for argument-checking */ 86typedef SV SV8; /* byte-sv, used for argument-checking */
81 87
82#define AIO_REQ_KLASS "IO::AIO::REQ" 88#define AIO_REQ_KLASS "IO::AIO::REQ"
83#define AIO_GRP_KLASS "IO::AIO::GRP" 89#define AIO_GRP_KLASS "IO::AIO::GRP"
84 90
85#define EIO_COMMON \ 91#define EIO_REQ_MEMBERS \
86 SV *callback; \ 92 SV *callback; \
87 SV *sv1, *sv2; \ 93 SV *sv1, *sv2; \
88 STRLEN stroffset; \ 94 STRLEN stroffset; \
89 SV *self 95 SV *self;
96
97#define EIO_NO_WRAPPERS 1
90 98
91#include "libeio/eio.h" 99#include "libeio/eio.h"
92 100
93static int req_invoke (eio_req *req); 101static int req_invoke (eio_req *req);
94#define EIO_FINISH(req) req_invoke (req) 102#define EIO_FINISH(req) req_invoke (req)
105 113
106typedef eio_req *aio_req; 114typedef eio_req *aio_req;
107typedef eio_req *aio_req_ornot; 115typedef eio_req *aio_req_ornot;
108 116
109static SV *on_next_submit; 117static SV *on_next_submit;
110static int next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; 118static int next_pri = EIO_PRI_DEFAULT;
111static int max_outstanding; 119static int max_outstanding;
112 120
113static int respipe_osf [2], respipe [2] = { -1, -1 }; 121static int respipe_osf [2], respipe [2] = { -1, -1 };
114 122
115static void req_destroy (aio_req req); 123static void req_destroy (aio_req req);
410 X_UNLOCK (reslock); 418 X_UNLOCK (reslock);
411 419
412 if (size) 420 if (size)
413 return; 421 return;
414 422
415 maybe_start_thread (); 423 etp_maybe_start_thread ();
416 424
417 FD_ZERO (&rfd); 425 FD_ZERO (&rfd);
418 FD_SET (respipe [0], &rfd); 426 FD_SET (respipe [0], &rfd);
419 427
420 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); 428 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
421 } 429 }
422} 430}
423 431
424static int poll_cb (void) 432static int poll_cb (void)
425{ 433{
426 int res; 434 for (;;)
427
428 do
429 { 435 {
430 res = eio_poll (); 436 int res = eio_poll ();
431 437
432 if (res > 0) 438 if (res > 0)
433 croak (0); 439 croak (0);
440
441 if (!max_outstanding || max_outstanding > eio_nreqs ())
442 return res;
443
444 poll_wait ();
434 } 445 }
435 while (max_outstanding && max_outstanding <= eio_nreqs ());
436
437 return res;
438} 446}
439 447
440static void atfork_child (void) 448static void atfork_child (void)
441{ 449{
442 create_respipe (); 450 create_respipe ();
443} 451}
444 452
445#define dREQ \ 453#define dREQ \
446 aio_req req; \ 454 aio_req req; \
447 int req_pri = next_pri; \ 455 int req_pri = next_pri; \
448 next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; \ 456 next_pri = EIO_PRI_DEFAULT; \
449 \ 457 \
450 if (SvOK (callback) && !SvROK (callback)) \ 458 if (SvOK (callback) && !SvROK (callback)) \
451 croak ("callback must be undef or of reference type"); \ 459 croak ("callback must be undef or of reference type"); \
452 \ 460 \
453 Newz (0, req, 1, eio_req); \ 461 Newz (0, req, 1, eio_req); \
474 newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); 482 newCONSTSUB (stash, "EXDEV", newSViv (EXDEV));
475 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); 483 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY));
476 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); 484 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY));
477 newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); 485 newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT));
478 newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); 486 newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC));
479#ifdef _WIN32 487#ifndef _WIN32
480 X_MUTEX_CHECK (wrklock);
481 X_MUTEX_CHECK (reslock);
482 X_MUTEX_CHECK (reqlock);
483 X_MUTEX_CHECK (reqwait);
484 X_MUTEX_CHECK (preadwritelock);
485 X_MUTEX_CHECK (readdirlock);
486
487 X_COND_CHECK (reqwait);
488#else
489 newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); 488 newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO));
490#endif 489#endif
491 490
492 create_respipe (); 491 create_respipe ();
493 492
917 916
918int 917int
919aioreq_pri (int pri = 0) 918aioreq_pri (int pri = 0)
920 PROTOTYPE: ;$ 919 PROTOTYPE: ;$
921 CODE: 920 CODE:
922 RETVAL = next_pri - EIO_PRI_BIAS; 921 RETVAL = next_pri;
923 if (items > 0) 922 if (items > 0)
924 { 923 {
925 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; 924 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN;
926 if (pri > EIO_PRI_MAX) pri = EIO_PRI_MAX; 925 if (pri > EIO_PRI_MAX) pri = EIO_PRI_MAX;
927 next_pri = pri + EIO_PRI_BIAS; 926 next_pri = pri;
928 } 927 }
929 OUTPUT: 928 OUTPUT:
930 RETVAL 929 RETVAL
931 930
932void 931void
933aioreq_nice (int nice = 0) 932aioreq_nice (int nice = 0)
934 CODE: 933 CODE:
935 nice = next_pri - nice; 934 nice = next_pri - nice;
936 if (nice < EIO_PRI_MIN) nice = EIO_PRI_MIN; 935 if (nice < EIO_PRI_MIN) nice = EIO_PRI_MIN;
937 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; 936 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX;
938 next_pri = nice + EIO_PRI_BIAS; 937 next_pri = nice;
939 938
940void 939void
941flush () 940flush ()
942 PROTOTYPE: 941 PROTOTYPE:
943 CODE: 942 CODE:
1004 1003
1005int 1004int
1006nthreads() 1005nthreads()
1007 PROTOTYPE: 1006 PROTOTYPE:
1008 CODE: 1007 CODE:
1009 if (WORDACCESS_UNSAFE) X_LOCK (wrklock); 1008 RETVAL = eio_nthreads ();
1010 RETVAL = started;
1011 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock);
1012 OUTPUT: 1009 OUTPUT:
1013 RETVAL 1010 RETVAL
1014 1011
1015void _on_next_submit (SV *cb) 1012void _on_next_submit (SV *cb)
1016 CODE: 1013 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines