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.161 by root, Sun Jan 10 20:28:43 2010 UTC vs.
Revision 1.172 by root, Sun Sep 12 03:36:27 2010 UTC

16#include <sys/statvfs.h> 16#include <sys/statvfs.h>
17#include <limits.h> 17#include <limits.h>
18#include <fcntl.h> 18#include <fcntl.h>
19#include <sched.h> 19#include <sched.h>
20 20
21#if _POSIX_MEMLOCK 21#if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES
22# include <sys/mman.h> 22# include <sys/mman.h>
23#endif 23#endif
24 24
25/* perl namespace pollution */ 25/* perl namespace pollution */
26#undef VERSION 26#undef VERSION
140#endif 140#endif
141#ifndef POSIX_FADV_DONTNEED 141#ifndef POSIX_FADV_DONTNEED
142# define POSIX_FADV_DONTNEED 0 142# define POSIX_FADV_DONTNEED 0
143#endif 143#endif
144 144
145#if _XOPEN_SOURCE < 600 || NO_FADVISE
146# define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */
147#endif
148
149#ifndef POSIX_MADV_NORMAL
150# define POSIX_MADV_NORMAL 0
151# define NO_MADVISE 1
152#endif
153#ifndef POSIX_MADV_SEQUENTIAL
154# define POSIX_MADV_SEQUENTIAL 0
155#endif
156#ifndef POSIX_MADV_RANDOM
157# define POSIX_MADV_RANDOM 0
158#endif
159#ifndef POSIX_MADV_WILLNEED
160# define POSIX_MADV_WILLNEED 0
161#endif
162#ifndef POSIX_MADV_DONTNEED
163# define POSIX_MADV_DONTNEED 0
164#endif
165
166#if _XOPEN_SOURCE < 600 || NO_MADVISE
167# define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */
168#endif
169
170#ifndef PROT_NONE
171# define PROT_NONE 0
172#endif
173#ifndef PROT_READ
174# define PROT_READ 0
175#endif
176#ifndef PROT_WRITE
177# define PROT_READ 0
178#endif
179#ifndef PROT_EXEC
180# define PROT_EXEC 0
181#endif
182
145#ifndef ST_NODEV 183#ifndef ST_NODEV
146# define ST_NODEV 0 184# define ST_NODEV 0
147#endif 185#endif
148#ifndef ST_NOEXEC 186#ifndef ST_NOEXEC
149# define ST_NOEXEC 0 187# define ST_NOEXEC 0
171#endif 209#endif
172#ifndef ST_RELATIME 210#ifndef ST_RELATIME
173# define ST_RELATIME 0 211# define ST_RELATIME 0
174#endif 212#endif
175 213
176#ifndef MCL_CURRENT 214#ifndef MAP_ANONYMOUS
177# define MCL_CURRENT 0 215# ifdef MAP_ANON
216# define MAP_ANONYMOUS MAP_ANON
217# else
218# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
178#endif 219# endif
179#ifndef MCL_FUTURE 220#endif
180# define MCL_FUTURE 0 221#ifndef MAP_HUGETLB
222# define MAP_HUGETLB 0
223#endif
224#ifndef MAP_LOCKED
225# define MAP_LOCKED 0
226#endif
227#ifndef MAP_NORESERVE
228# define MAP_NORESERVE 0
229#endif
230#ifndef MAP_POPULATE
231# define MAP_POPULATE 0
232#endif
233#ifndef MAP_NONBLOCK
234# define MAP_NONBLOCK 0
235#endif
236
237#ifndef PAGESIZE
238# define PAGESIZE sysconf (_SC_PAGESIZE)
181#endif 239#endif
182 240
183static int req_invoke (eio_req *req); 241static int req_invoke (eio_req *req);
184#define EIO_FINISH(req) req_invoke (req) 242#define EIO_FINISH(req) req_invoke (req)
185static void req_destroy (eio_req *grp); 243static void req_destroy (eio_req *grp);
277 } 335 }
278} 336}
279 337
280static int req_invoke (eio_req *req) 338static int req_invoke (eio_req *req)
281{ 339{
282 dSP;
283
284 if (req->flags & FLAG_SV2_RO_OFF) 340 if (req->flags & FLAG_SV2_RO_OFF)
285 SvREADONLY_off (req->sv2); 341 SvREADONLY_off (req->sv2);
286 342
287 if (!EIO_CANCELLED (req) && req->callback) 343 if (!EIO_CANCELLED (req) && req->callback)
288 { 344 {
345 dSP;
346 static SV *sv_result_cache; /* caches the result integer SV */
347 SV *sv_result;
348
289 ENTER; 349 ENTER;
290 SAVETMPS; 350 SAVETMPS;
291 PUSHMARK (SP); 351 PUSHMARK (SP);
292 EXTEND (SP, 1); 352 EXTEND (SP, 1);
353
354 /* do not recreate the result IV from scratch each time */
355 if (expect_true (sv_result_cache))
356 {
357 sv_result = sv_result_cache; sv_result_cache = 0;
358 SvIV_set (sv_result, req->result);
359 }
360 else
361 {
362 sv_result = newSViv (req->result);
363 SvREADONLY_on (sv_result);
364 }
293 365
294 switch (req->type) 366 switch (req->type)
295 { 367 {
296 case EIO_READDIR: 368 case EIO_READDIR:
297 { 369 {
442 case EIO_LSTAT: 514 case EIO_LSTAT:
443 case EIO_FSTAT: 515 case EIO_FSTAT:
444 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; 516 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
445 PL_laststatval = req->result; 517 PL_laststatval = req->result;
446 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); 518 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
447 PUSHs (sv_2mortal (newSViv (req->result))); 519 PUSHs (sv_result);
448 break; 520 break;
449 521
450 case EIO_READ: 522 case EIO_READ:
451 { 523 {
452 SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); 524 SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0));
453 *SvEND (req->sv2) = 0; 525 *SvEND (req->sv2) = 0;
454 SvPOK_only (req->sv2); 526 SvPOK_only (req->sv2);
455 SvSETMAGIC (req->sv2); 527 SvSETMAGIC (req->sv2);
456 PUSHs (sv_2mortal (newSViv (req->result))); 528 PUSHs (sv_result);
457 } 529 }
458 break; 530 break;
459 531
460 case EIO_DUP2: 532 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */
461 if (req->result > 0) 533 if (req->result > 0)
462 req->result = 0; 534 SvIV_set (sv_result, 0);
463 /* FALLTHROUGH */ 535 /* FALLTHROUGH */
464 536
465 default: 537 default:
466 PUSHs (sv_2mortal (newSViv (req->result))); 538 PUSHs (sv_result);
467 break; 539 break;
468 } 540 }
469 541
470 errno = req->errorno; 542 errno = req->errorno;
471 543
472 PUTBACK; 544 PUTBACK;
473 call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); 545 call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD);
474 SPAGAIN; 546 SPAGAIN;
547
548 if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache))
549 SvREFCNT_dec (sv_result);
550 else
551 sv_result_cache = sv_result;
475 552
476 FREETMPS; 553 FREETMPS;
477 LEAVE; 554 LEAVE;
478 555
479 PUTBACK; 556 PUTBACK;
554 631
555static void atfork_child (void) 632static void atfork_child (void)
556{ 633{
557 create_respipe (); 634 create_respipe ();
558} 635}
636
637/*****************************************************************************/
638
639#if !_POSIX_MAPPED_FILES
640# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1)
641# define munmap(addr,length) (errno = ENOSYS, -1)
642# define mprotect(addr,len,prot) (errno = ENOSYS, -1)
643#endif
644
645#define MMAP_MAGIC PERL_MAGIC_ext
646
647static int
648mmap_free (pTHX_ SV *sv, MAGIC *mg)
649{
650 int old_errno = errno;
651 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
652 errno = old_errno;
653
654 mg->mg_obj = 0; /* just in case */
655
656 SvREADONLY_off (sv);
657
658 if (SvPVX (sv) != mg->mg_ptr)
659 croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected");
660
661 SvCUR_set (sv, 0);
662 SvPVX (sv) = 0;
663 SvOK_off (sv);
664
665 return 0;
666}
667
668static MGVTBL mmap_vtbl = {
669 0, 0, 0, 0, mmap_free
670};
671
672/*****************************************************************************/
559 673
560static SV * 674static SV *
561get_cb (SV *cb_sv) 675get_cb (SV *cb_sv)
562{ 676{
563 SvGETMAGIC (cb_sv); 677 SvGETMAGIC (cb_sv);
595{ 709{
596 static const struct { 710 static const struct {
597 const char *name; 711 const char *name;
598 IV iv; 712 IV iv;
599 } *civ, const_iv[] = { 713 } *civ, const_iv[] = {
600# define const_iv(name, value) { # name, (IV) value }, 714# define const_niv(name, value) { # name, (IV) value },
715# define const_iv(name) { # name, (IV) name },
601# define const_eio(name) { # name, (IV) EIO_ ## name }, 716# define const_eio(name) { # name, (IV) EIO_ ## name },
602 const_iv (EXDEV , EXDEV) 717 const_iv (EXDEV)
603 const_iv (ENOSYS , ENOSYS) 718 const_iv (ENOSYS)
604 const_iv (O_RDONLY, O_RDONLY) 719 const_iv (O_RDONLY)
605 const_iv (O_WRONLY, O_WRONLY) 720 const_iv (O_WRONLY)
721 const_iv (O_RDWR)
606 const_iv (O_CREAT , O_CREAT) 722 const_iv (O_CREAT)
607 const_iv (O_TRUNC , O_TRUNC) 723 const_iv (O_TRUNC)
724 const_iv (O_EXCL)
725 const_iv (O_APPEND)
608#ifndef _WIN32 726#ifndef _WIN32
609 const_iv (S_IFIFO , S_IFIFO) 727 const_iv (S_IFIFO)
610#endif 728#endif
611 const_iv (FADV_NORMAL , POSIX_FADV_NORMAL) 729 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL)
612 const_iv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) 730 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL)
613 const_iv (FADV_RANDOM , POSIX_FADV_RANDOM) 731 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM)
614 const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE) 732 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE)
615 const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED) 733 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED)
616 const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED) 734 const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED)
617 735
618 const_iv (ST_RDONLY , ST_RDONLY) 736 const_niv (MADV_NORMAL , POSIX_MADV_NORMAL)
619 const_iv (ST_NOSUID , ST_NOSUID) 737 const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL)
620 const_iv (ST_NODEV , ST_NODEV) 738 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
621 const_iv (ST_NOEXEC , ST_NOEXEC) 739 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
740 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
741
742 const_iv (ST_RDONLY)
743 const_iv (ST_NOSUID)
744 const_iv (ST_NODEV)
745 const_iv (ST_NOEXEC)
622 const_iv (ST_SYNCHRONOUS , ST_SYNCHRONOUS) 746 const_iv (ST_SYNCHRONOUS)
623 const_iv (ST_MANDLOCK , ST_MANDLOCK) 747 const_iv (ST_MANDLOCK)
624 const_iv (ST_WRITE , ST_WRITE) 748 const_iv (ST_WRITE)
625 const_iv (ST_APPEND , ST_APPEND) 749 const_iv (ST_APPEND)
626 const_iv (ST_IMMUTABLE , ST_IMMUTABLE) 750 const_iv (ST_IMMUTABLE)
627 const_iv (ST_NOATIME , ST_NOATIME) 751 const_iv (ST_NOATIME)
628 const_iv (ST_NODIRATIME , ST_NODIRATIME) 752 const_iv (ST_NODIRATIME)
629 const_iv (ST_RELATIME , ST_RELATIME) 753 const_iv (ST_RELATIME)
630 754
631 const_iv (MCL_FUTURE , MCL_FUTURE) 755 const_iv (PROT_NONE)
632 const_iv (MCL_CURRENT , MCL_CURRENT) 756 const_iv (PROT_EXEC)
757 const_iv (PROT_READ)
758 const_iv (PROT_WRITE)
759
760 /*const_iv (MAP_FIXED)*/
761 const_iv (MAP_PRIVATE)
762 const_iv (MAP_SHARED)
763 const_iv (MAP_ANONYMOUS)
764
765 /* linuxish */
766 const_iv (MAP_HUGETLB)
767 const_iv (MAP_LOCKED)
768 const_iv (MAP_NORESERVE)
769 const_iv (MAP_POPULATE)
770 const_iv (MAP_NONBLOCK)
771
772 const_eio (MCL_FUTURE)
773 const_eio (MCL_CURRENT)
633 774
634 const_eio (MS_ASYNC) 775 const_eio (MS_ASYNC)
635 const_eio (MS_INVALIDATE) 776 const_eio (MS_INVALIDATE)
636 const_eio (MS_SYNC) 777 const_eio (MS_SYNC)
637 778
662 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); 803 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1);
663 804
664 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 805 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
665 newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); 806 newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv));
666 807
808 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
809
667 create_respipe (); 810 create_respipe ();
668 811
669 if (eio_init (want_poll, done_poll) < 0) 812 if (eio_init (want_poll, done_poll) < 0)
670 croak ("IO::AIO: unable to initialise eio library"); 813 croak ("IO::AIO: unable to initialise eio library");
671 814
709 CODE: 852 CODE:
710 max_outstanding = maxreqs; 853 max_outstanding = maxreqs;
711 854
712void 855void
713aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 856aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
714 PROTOTYPE: $$$;$
715 PPCODE: 857 PPCODE:
716{ 858{
717 dREQ; 859 dREQ;
718 860
719 req->type = EIO_OPEN; 861 req->type = EIO_OPEN;
725 REQ_SEND; 867 REQ_SEND;
726} 868}
727 869
728void 870void
729aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 871aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
730 PROTOTYPE: $;$
731 ALIAS: 872 ALIAS:
732 aio_fsync = EIO_FSYNC 873 aio_fsync = EIO_FSYNC
733 aio_fdatasync = EIO_FDATASYNC 874 aio_fdatasync = EIO_FDATASYNC
734 PPCODE: 875 PPCODE:
735{ 876{
743 REQ_SEND (req); 884 REQ_SEND (req);
744} 885}
745 886
746void 887void
747aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) 888aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef)
748 PROTOTYPE: $$$$;$
749 PPCODE: 889 PPCODE:
750{ 890{
751 int fd = s_fileno_croak (fh, 0); 891 int fd = s_fileno_croak (fh, 0);
752 dREQ; 892 dREQ;
753 893
761 REQ_SEND (req); 901 REQ_SEND (req);
762} 902}
763 903
764void 904void
765aio_close (SV *fh, SV *callback=&PL_sv_undef) 905aio_close (SV *fh, SV *callback=&PL_sv_undef)
766 PROTOTYPE: $;$
767 PPCODE: 906 PPCODE:
768{ 907{
769 static int close_pipe = -1; /* dummy fd to close fds via dup2 */ 908 static int close_pipe = -1; /* dummy fd to close fds via dup2 */
770 int fd = s_fileno_croak (fh, 0); 909 int fd = s_fileno_croak (fh, 0);
771 dREQ; 910 dREQ;
793void 932void
794aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) 933aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef)
795 ALIAS: 934 ALIAS:
796 aio_read = EIO_READ 935 aio_read = EIO_READ
797 aio_write = EIO_WRITE 936 aio_write = EIO_WRITE
798 PROTOTYPE: $$$$$;$
799 PPCODE: 937 PPCODE:
800{ 938{
801 STRLEN svlen; 939 STRLEN svlen;
802 int fd = s_fileno_croak (fh, ix == EIO_WRITE); 940 int fd = s_fileno_croak (fh, ix == EIO_WRITE);
803 char *svptr = SvPVbyte (data, svlen); 941 char *svptr = SvPVbyte (data, svlen);
844 } 982 }
845} 983}
846 984
847void 985void
848aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 986aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
849 PROTOTYPE: $$;$
850 PPCODE: 987 PPCODE:
851{ 988{
852 SV *data; 989 SV *data;
853 dREQ; 990 dREQ;
854 991
859 REQ_SEND; 996 REQ_SEND;
860} 997}
861 998
862void 999void
863aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) 1000aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef)
864 PROTOTYPE: $$$$;$
865 PPCODE: 1001 PPCODE:
866{ 1002{
867 int ifd = s_fileno_croak (in_fh , 0); 1003 int ifd = s_fileno_croak (in_fh , 0);
868 int ofd = s_fileno_croak (out_fh, 1); 1004 int ofd = s_fileno_croak (out_fh, 1);
869 dREQ; 1005 dREQ;
879 REQ_SEND; 1015 REQ_SEND;
880} 1016}
881 1017
882void 1018void
883aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) 1019aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef)
884 PROTOTYPE: $$$;$
885 PPCODE: 1020 PPCODE:
886{ 1021{
887 int fd = s_fileno_croak (fh, 0); 1022 int fd = s_fileno_croak (fh, 0);
888 dREQ; 1023 dREQ;
889 1024
1090void 1225void
1091aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) 1226aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef)
1092 ALIAS: 1227 ALIAS:
1093 aio_mtouch = EIO_MTOUCH 1228 aio_mtouch = EIO_MTOUCH
1094 aio_msync = EIO_MSYNC 1229 aio_msync = EIO_MSYNC
1095 PROTOTYPE: $$$$;$
1096 PPCODE: 1230 PPCODE:
1097{ 1231{
1098 STRLEN svlen; 1232 STRLEN svlen;
1233 char *svptr = SvPVbyte (data, svlen);
1099 UV len = SvUV (length); 1234 UV len = SvUV (length);
1100 char *svptr = SvPVbyte (data, svlen);
1101 1235
1102 if (offset < 0) 1236 if (offset < 0)
1103 offset += svlen; 1237 offset += svlen;
1104 1238
1105 if (offset < 0 || offset > svlen) 1239 if (offset < 0 || offset > svlen)
1110 1244
1111 { 1245 {
1112 dREQ; 1246 dREQ;
1113 1247
1114 req->type = ix; 1248 req->type = ix;
1115 req->size = len;
1116 req->sv2 = SvREFCNT_inc (data); 1249 req->sv2 = SvREFCNT_inc (data);
1117 req->ptr2 = (char *)svptr + offset; 1250 req->ptr2 = (char *)svptr + offset;
1251 req->size = len;
1118 req->int1 = flags; 1252 req->int1 = flags;
1119 1253
1120 REQ_SEND; 1254 REQ_SEND;
1121 } 1255 }
1122} 1256}
1123 1257
1124void 1258void
1259aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef)
1260 PPCODE:
1261{
1262
1263 STRLEN svlen;
1264 char *svptr = SvPVbyte (data, svlen);
1265 UV len = SvUV (length);
1266
1267 if (offset < 0)
1268 offset += svlen;
1269
1270 if (offset < 0 || offset > svlen)
1271 croak ("offset outside of scalar");
1272
1273 if (!SvOK (length) || len + offset > svlen)
1274 len = svlen - offset;
1275
1276 {
1277 dREQ;
1278
1279 req->type = EIO_MLOCK;
1280 req->sv2 = SvREFCNT_inc (data);
1281 req->ptr2 = (char *)svptr + offset;
1282 req->size = len;
1283
1284 REQ_SEND;
1285 }
1286}
1287
1288void
1289aio_mlockall (IV flags, SV *callback=&PL_sv_undef)
1290 PPCODE:
1291{
1292 dREQ;
1293
1294 req->type = EIO_MLOCKALL;
1295 req->int1 = flags;
1296
1297 REQ_SEND;
1298}
1299
1300void
1125aio_busy (double delay, SV *callback=&PL_sv_undef) 1301aio_busy (double delay, SV *callback=&PL_sv_undef)
1126 PPCODE: 1302 PPCODE:
1127{ 1303{
1128 dREQ; 1304 dREQ;
1129 1305
1133 REQ_SEND; 1309 REQ_SEND;
1134} 1310}
1135 1311
1136void 1312void
1137aio_group (SV *callback=&PL_sv_undef) 1313aio_group (SV *callback=&PL_sv_undef)
1138 PROTOTYPE: ;$
1139 PPCODE: 1314 PPCODE:
1140{ 1315{
1141 dREQ; 1316 dREQ;
1142 1317
1143 req->type = EIO_GROUP; 1318 req->type = EIO_GROUP;
1160 REQ_SEND; 1335 REQ_SEND;
1161} 1336}
1162 1337
1163int 1338int
1164aioreq_pri (int pri = 0) 1339aioreq_pri (int pri = 0)
1165 PROTOTYPE: ;$
1166 CODE: 1340 CODE:
1167 RETVAL = next_pri; 1341 RETVAL = next_pri;
1168 if (items > 0) 1342 if (items > 0)
1169 { 1343 {
1170 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; 1344 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN;
1182 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; 1356 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX;
1183 next_pri = nice; 1357 next_pri = nice;
1184 1358
1185void 1359void
1186flush () 1360flush ()
1187 PROTOTYPE:
1188 CODE: 1361 CODE:
1189 while (eio_nreqs ()) 1362 while (eio_nreqs ())
1190 { 1363 {
1191 poll_wait (); 1364 poll_wait ();
1192 poll_cb (); 1365 poll_cb ();
1193 } 1366 }
1194 1367
1195int 1368int
1196poll() 1369poll ()
1197 PROTOTYPE:
1198 CODE: 1370 CODE:
1199 poll_wait (); 1371 poll_wait ();
1200 RETVAL = poll_cb (); 1372 RETVAL = poll_cb ();
1201 OUTPUT: 1373 OUTPUT:
1202 RETVAL 1374 RETVAL
1203 1375
1204int 1376int
1205poll_fileno() 1377poll_fileno ()
1206 PROTOTYPE:
1207 CODE: 1378 CODE:
1208 RETVAL = s_epipe_fd (&respipe); 1379 RETVAL = s_epipe_fd (&respipe);
1209 OUTPUT: 1380 OUTPUT:
1210 RETVAL 1381 RETVAL
1211 1382
1212int 1383int
1213poll_cb(...) 1384poll_cb (...)
1214 PROTOTYPE: 1385 PROTOTYPE:
1215 CODE: 1386 CODE:
1216 RETVAL = poll_cb (); 1387 RETVAL = poll_cb ();
1217 OUTPUT: 1388 OUTPUT:
1218 RETVAL 1389 RETVAL
1219 1390
1220void 1391void
1221poll_wait() 1392poll_wait ()
1222 PROTOTYPE:
1223 CODE: 1393 CODE:
1224 poll_wait (); 1394 poll_wait ();
1225 1395
1226int 1396int
1227nreqs() 1397nreqs ()
1228 PROTOTYPE:
1229 CODE: 1398 CODE:
1230 RETVAL = eio_nreqs (); 1399 RETVAL = eio_nreqs ();
1231 OUTPUT: 1400 OUTPUT:
1232 RETVAL 1401 RETVAL
1233 1402
1234int 1403int
1235nready() 1404nready ()
1236 PROTOTYPE:
1237 CODE: 1405 CODE:
1238 RETVAL = eio_nready (); 1406 RETVAL = eio_nready ();
1239 OUTPUT: 1407 OUTPUT:
1240 RETVAL 1408 RETVAL
1241 1409
1242int 1410int
1243npending() 1411npending ()
1244 PROTOTYPE:
1245 CODE: 1412 CODE:
1246 RETVAL = eio_npending (); 1413 RETVAL = eio_npending ();
1247 OUTPUT: 1414 OUTPUT:
1248 RETVAL 1415 RETVAL
1249 1416
1250int 1417int
1251nthreads() 1418nthreads ()
1252 PROTOTYPE:
1253 CODE: 1419 CODE:
1254 RETVAL = eio_nthreads (); 1420 RETVAL = eio_nthreads ();
1255 OUTPUT: 1421 OUTPUT:
1256 RETVAL 1422 RETVAL
1257 1423
1258int 1424int
1259fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) 1425fadvise (aio_rfd fh, off_t offset, off_t length, IV advice)
1260 PROTOTYPE: $$$$
1261 CODE: 1426 CODE:
1262#if _XOPEN_SOURCE >= 600 && !NO_FADVISE
1263 RETVAL = posix_fadvise (fh, offset, length, advice); 1427 RETVAL = posix_fadvise (fh, offset, length, advice);
1264#else
1265 RETVAL = errno = ENOSYS;
1266#endif
1267 OUTPUT: 1428 OUTPUT:
1268 RETVAL 1429 RETVAL
1269 1430
1270ssize_t 1431ssize_t
1271sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1432sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1272 PROTOTYPE: $$$$
1273 CODE: 1433 CODE:
1274 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1434 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1275 OUTPUT: 1435 OUTPUT:
1276 RETVAL 1436 RETVAL
1277 1437
1438void
1439mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0)
1440 PPCODE:
1441 sv_unmagic (scalar, MMAP_MAGIC);
1442{
1443 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1;
1444 void *addr = (void *)mmap (0, length, prot, flags, fd, offset);
1445 if (addr == (void *)-1)
1446 XSRETURN_NO;
1447
1448 sv_force_normal (scalar);
1449
1450 /* we store the length in mg_obj, as namlen is I32 :/ */
1451 sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0)
1452 ->mg_obj = (SV *)length;
1453
1454 SvUPGRADE (scalar, SVt_PV); /* nop... */
1455
1456 if (!(prot & PROT_WRITE))
1457 SvREADONLY_on (scalar);
1458
1459 if (SvLEN (scalar))
1460 Safefree (SvPVX (scalar));
1461
1462 SvPVX (scalar) = (char *)addr;
1463 SvCUR_set (scalar, length);
1464 SvLEN_set (scalar, 0);
1465 SvPOK_only (scalar);
1466
1467 XSRETURN_YES;
1468}
1469
1470void
1471munmap (SV *scalar)
1472 CODE:
1473 sv_unmagic (scalar, MMAP_MAGIC);
1474
1278int 1475int
1279mlockall (int flags) 1476madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
1280 PROTOTYPE: $ 1477 ALIAS:
1478 mprotect = 1
1281 CODE: 1479 CODE:
1480{
1481 STRLEN svlen;
1482 void *addr = SvPVbyte (scalar, svlen);
1483 size_t len = SvUV (length);
1484
1485 if (offset < 0)
1486 offset += svlen;
1487
1488 if (offset < 0 || offset > svlen)
1489 croak ("offset outside of scalar");
1490
1491 if (!SvOK (length) || len + offset > svlen)
1492 len = svlen - offset;
1493
1494 addr = (void *)(((intptr_t)addr) + offset);
1495 eio_page_align (&addr, &len);
1496
1497 switch (ix)
1498 {
1499 case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break;
1500 case 1: RETVAL = mprotect (addr, len, advice_or_prot); break;
1501 }
1502}
1503 OUTPUT:
1504 RETVAL
1505
1506int
1507munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef)
1508 CODE:
1509{
1510 STRLEN svlen;
1511 void *addr = SvPVbyte (scalar, svlen);
1512 size_t len = SvUV (length);
1513
1514 if (offset < 0)
1515 offset += svlen;
1516
1517 if (offset < 0 || offset > svlen)
1518 croak ("offset outside of scalar");
1519
1520 if (!SvOK (length) || len + offset > svlen)
1521 len = svlen - offset;
1522
1523 addr = (void *)(((intptr_t)addr) + offset);
1524 eio_page_align (&addr, &len);
1282#if _POSIX_MEMLOCK 1525#if _POSIX_MEMLOCK
1283#if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 1526 RETVAL = munlock (addr, len);
1284 extern int mallopt (int, int);
1285 mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */
1286#endif
1287 mlockall (flags);
1288#else 1527#else
1289 RETVAL =-1; 1528 RETVAL = ((errno = ENOSYS), -1);
1290 errno = ENOSYS;
1291#endif 1529#endif
1530}
1292 OUTPUT: 1531 OUTPUT:
1293 RETVAL 1532 RETVAL
1294 1533
1295int 1534int
1296munlockall () 1535munlockall ()
1297 PROTOTYPE:
1298 CODE: 1536 CODE:
1299#if _POSIX_MEMLOCK 1537#if _POSIX_MEMLOCK
1300 munlockall (); 1538 munlockall ();
1301#else 1539#else
1302 RETVAL -1; 1540 RETVAL = -1;
1303 errno = ENOSYS; 1541 errno = ENOSYS;
1304#endif 1542#endif
1305 OUTPUT: 1543 OUTPUT:
1306 RETVAL 1544 RETVAL
1307 1545

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines