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.170 by root, Wed Aug 4 16:09:36 2010 UTC vs.
Revision 1.181 by root, Tue Feb 15 03:21:41 2011 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 || _POSIX_MAPPED_FILES 21#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _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
118 STRLEN stroffset; \ 118 STRLEN stroffset; \
119 SV *self; 119 SV *self;
120 120
121#define EIO_NO_WRAPPERS 1 121#define EIO_NO_WRAPPERS 1
122 122
123#include "libeio/config.h"
123#include "libeio/eio.h" 124#include "libeio/eio.h"
124 125
125#ifndef POSIX_FADV_NORMAL 126#ifndef POSIX_FADV_NORMAL
126# define POSIX_FADV_NORMAL 0 127# define POSIX_FADV_NORMAL 0
127# define NO_FADVISE 1
128#endif 128#endif
129#ifndef POSIX_FADV_SEQUENTIAL 129#ifndef POSIX_FADV_SEQUENTIAL
130# define POSIX_FADV_SEQUENTIAL 0 130# define POSIX_FADV_SEQUENTIAL 0
131#endif 131#endif
132#ifndef POSIX_FADV_RANDOM 132#ifndef POSIX_FADV_RANDOM
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 145#if !HAVE_POSIX_FADVISE
146# define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ 146# define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */
147#endif 147#endif
148 148
149#ifndef POSIX_MADV_NORMAL 149#ifndef POSIX_MADV_NORMAL
150# define POSIX_MADV_NORMAL 0 150# define POSIX_MADV_NORMAL 0
151# define NO_MADVISE 1
152#endif 151#endif
153#ifndef POSIX_MADV_SEQUENTIAL 152#ifndef POSIX_MADV_SEQUENTIAL
154# define POSIX_MADV_SEQUENTIAL 0 153# define POSIX_MADV_SEQUENTIAL 0
155#endif 154#endif
156#ifndef POSIX_MADV_RANDOM 155#ifndef POSIX_MADV_RANDOM
161#endif 160#endif
162#ifndef POSIX_MADV_DONTNEED 161#ifndef POSIX_MADV_DONTNEED
163# define POSIX_MADV_DONTNEED 0 162# define POSIX_MADV_DONTNEED 0
164#endif 163#endif
165 164
166#if _XOPEN_SOURCE < 600 || NO_MADVISE 165#if !HAVE_POSIX_MADVISE
167# define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ 166# define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */
167#endif
168
169#ifndef PROT_NONE
170# define PROT_NONE 0
171#endif
172#ifndef PROT_READ
173# define PROT_READ 0
174#endif
175#ifndef PROT_WRITE
176# define PROT_READ 0
177#endif
178#ifndef PROT_EXEC
179# define PROT_EXEC 0
168#endif 180#endif
169 181
170#ifndef ST_NODEV 182#ifndef ST_NODEV
171# define ST_NODEV 0 183# define ST_NODEV 0
172#endif 184#endif
196#endif 208#endif
197#ifndef ST_RELATIME 209#ifndef ST_RELATIME
198# define ST_RELATIME 0 210# define ST_RELATIME 0
199#endif 211#endif
200 212
201#ifndef MCL_CURRENT 213#ifndef S_IFIFO
202# define MCL_CURRENT 0 214# define S_IFIFO 0
203#endif 215#endif
204#ifndef MCL_FUTURE 216#ifndef S_IFCHR
205# define MCL_FUTURE 0 217# define S_IFCHR 0
218#endif
219#ifndef S_IFBLK
220# define S_IFBLK 0
221#endif
222#ifndef S_IFLNK
223# define S_IFLNK 0
224#endif
225#ifndef S_IFREG
226# define S_IFREG 0
227#endif
228#ifndef S_IFDIR
229# define S_IFDIR 0
230#endif
231#ifndef S_IFWHT
232# define S_IFWHT 0
233#endif
234#ifndef S_IFSOCK
235# define S_IFSOCK 0
206#endif 236#endif
207 237
208#ifndef MAP_ANONYMOUS 238#ifndef MAP_ANONYMOUS
209# ifdef MAP_ANON 239# ifdef MAP_ANON
210# define MAP_ANONYMOUS MAP_ANON 240# define MAP_ANONYMOUS MAP_ANON
224#ifndef MAP_POPULATE 254#ifndef MAP_POPULATE
225# define MAP_POPULATE 0 255# define MAP_POPULATE 0
226#endif 256#endif
227#ifndef MAP_NONBLOCK 257#ifndef MAP_NONBLOCK
228# define MAP_NONBLOCK 0 258# define MAP_NONBLOCK 0
259#endif
260
261#ifndef makedev
262# define makedev(maj,min) (((maj) << 8) | (min))
263#endif
264#ifndef major
265# define major(dev) ((dev) >> 8)
266#endif
267#ifndef minor
268# define minor(dev) ((dev) & 0xff)
229#endif 269#endif
230 270
231#ifndef PAGESIZE 271#ifndef PAGESIZE
232# define PAGESIZE sysconf (_SC_PAGESIZE) 272# define PAGESIZE sysconf (_SC_PAGESIZE)
233#endif 273#endif
348 /* do not recreate the result IV from scratch each time */ 388 /* do not recreate the result IV from scratch each time */
349 if (expect_true (sv_result_cache)) 389 if (expect_true (sv_result_cache))
350 { 390 {
351 sv_result = sv_result_cache; sv_result_cache = 0; 391 sv_result = sv_result_cache; sv_result_cache = 0;
352 SvIV_set (sv_result, req->result); 392 SvIV_set (sv_result, req->result);
393 SvIOK_only (sv_result);
353 } 394 }
354 else 395 else
355 { 396 {
356 sv_result = newSViv (req->result); 397 sv_result = newSViv (req->result);
357 SvREADONLY_on (sv_result); 398 SvREADONLY_on (sv_result);
521 SvSETMAGIC (req->sv2); 562 SvSETMAGIC (req->sv2);
522 PUSHs (sv_result); 563 PUSHs (sv_result);
523 } 564 }
524 break; 565 break;
525 566
526 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ 567 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */
527 if (req->result > 0) 568 if (req->result > 0)
528 SvIV_set (sv_result, 0); 569 SvIV_set (sv_result, 0);
529 /* FALLTHROUGH */ 570 /* FALLTHROUGH */
530 571
531 default: 572 default:
631/*****************************************************************************/ 672/*****************************************************************************/
632 673
633#if !_POSIX_MAPPED_FILES 674#if !_POSIX_MAPPED_FILES
634# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) 675# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1)
635# define munmap(addr,length) (errno = ENOSYS, -1) 676# define munmap(addr,length) (errno = ENOSYS, -1)
677#endif
678
679#if !_POSIX_MEMORY_PROTECTION
680# define mprotect(addr,len,prot) (errno = ENOSYS, -1)
681# define PROT_NONE 0
682# define PROT_WRITE 0
683# define MAP_PRIVATE 0
684# define MAP_SHARED 0
685# define MAP_FIXED 0
636#endif 686#endif
637 687
638#define MMAP_MAGIC PERL_MAGIC_ext 688#define MMAP_MAGIC PERL_MAGIC_ext
639 689
640static int 690static int
714 const_iv (O_RDWR) 764 const_iv (O_RDWR)
715 const_iv (O_CREAT) 765 const_iv (O_CREAT)
716 const_iv (O_TRUNC) 766 const_iv (O_TRUNC)
717 const_iv (O_EXCL) 767 const_iv (O_EXCL)
718 const_iv (O_APPEND) 768 const_iv (O_APPEND)
719#ifndef _WIN32 769
720 const_iv (S_IFIFO) 770 const_iv (S_IFIFO)
721#endif 771 const_iv (S_IFCHR)
772 const_iv (S_IFBLK)
773 const_iv (S_IFLNK)
774 const_iv (S_IFREG)
775 const_iv (S_IFDIR)
776 const_iv (S_IFWHT)
777 const_iv (S_IFSOCK)
778 const_iv (S_IFMT)
779
722 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) 780 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL)
723 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) 781 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL)
724 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) 782 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM)
725 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) 783 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE)
726 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) 784 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED)
743 const_iv (ST_IMMUTABLE) 801 const_iv (ST_IMMUTABLE)
744 const_iv (ST_NOATIME) 802 const_iv (ST_NOATIME)
745 const_iv (ST_NODIRATIME) 803 const_iv (ST_NODIRATIME)
746 const_iv (ST_RELATIME) 804 const_iv (ST_RELATIME)
747 805
806 const_iv (PROT_NONE)
748 const_iv (PROT_EXEC) 807 const_iv (PROT_EXEC)
749 const_iv (PROT_NONE)
750 const_iv (PROT_READ) 808 const_iv (PROT_READ)
751 const_iv (PROT_WRITE) 809 const_iv (PROT_WRITE)
752 810
753 /*const_iv (MAP_FIXED)*/ 811 /*const_iv (MAP_FIXED)*/
754 const_iv (MAP_PRIVATE) 812 const_iv (MAP_PRIVATE)
760 const_iv (MAP_LOCKED) 818 const_iv (MAP_LOCKED)
761 const_iv (MAP_NORESERVE) 819 const_iv (MAP_NORESERVE)
762 const_iv (MAP_POPULATE) 820 const_iv (MAP_POPULATE)
763 const_iv (MAP_NONBLOCK) 821 const_iv (MAP_NONBLOCK)
764 822
765 const_iv (MCL_FUTURE) 823 const_eio (MCL_FUTURE)
766 const_iv (MCL_CURRENT) 824 const_eio (MCL_CURRENT)
767 825
768 const_eio (MS_ASYNC) 826 const_eio (MS_ASYNC)
769 const_eio (MS_INVALIDATE) 827 const_eio (MS_INVALIDATE)
770 const_eio (MS_SYNC) 828 const_eio (MS_SYNC)
771 829
808 /* atfork child called in fifo order, so before eio's handler */ 866 /* atfork child called in fifo order, so before eio's handler */
809 X_THREAD_ATFORK (0, 0, atfork_child); 867 X_THREAD_ATFORK (0, 0, atfork_child);
810} 868}
811 869
812void 870void
813max_poll_reqs (int nreqs) 871max_poll_reqs (unsigned int nreqs)
814 PROTOTYPE: $ 872 PROTOTYPE: $
815 CODE: 873 CODE:
816 eio_set_max_poll_reqs (nreqs); 874 eio_set_max_poll_reqs (nreqs);
817 875
818void 876void
820 PROTOTYPE: $ 878 PROTOTYPE: $
821 CODE: 879 CODE:
822 eio_set_max_poll_time (nseconds); 880 eio_set_max_poll_time (nseconds);
823 881
824void 882void
825min_parallel (int nthreads) 883min_parallel (unsigned int nthreads)
826 PROTOTYPE: $ 884 PROTOTYPE: $
827 CODE: 885 CODE:
828 eio_set_min_parallel (nthreads); 886 eio_set_min_parallel (nthreads);
829 887
830void 888void
831max_parallel (int nthreads) 889max_parallel (unsigned int nthreads)
832 PROTOTYPE: $ 890 PROTOTYPE: $
833 CODE: 891 CODE:
834 eio_set_max_parallel (nthreads); 892 eio_set_max_parallel (nthreads);
835 893
836void 894void
837max_idle (int nthreads) 895max_idle (unsigned int nthreads)
838 PROTOTYPE: $ 896 PROTOTYPE: $
839 CODE: 897 CODE:
840 eio_set_max_idle (nthreads); 898 eio_set_max_idle (nthreads);
841 899
842void 900void
901idle_timeout (unsigned int seconds)
902 PROTOTYPE: $
903 CODE:
904 eio_set_idle_timeout (seconds);
905
906void
843max_outstanding (int maxreqs) 907max_outstanding (unsigned int maxreqs)
844 PROTOTYPE: $ 908 PROTOTYPE: $
845 CODE: 909 CODE:
846 max_outstanding = maxreqs; 910 max_outstanding = maxreqs;
847 911
848void 912void
849aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 913aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
850 PROTOTYPE: $$$;$
851 PPCODE: 914 PPCODE:
852{ 915{
853 dREQ; 916 dREQ;
854 917
855 req->type = EIO_OPEN; 918 req->type = EIO_OPEN;
861 REQ_SEND; 924 REQ_SEND;
862} 925}
863 926
864void 927void
865aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 928aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
866 PROTOTYPE: $;$
867 ALIAS: 929 ALIAS:
868 aio_fsync = EIO_FSYNC 930 aio_fsync = EIO_FSYNC
869 aio_fdatasync = EIO_FDATASYNC 931 aio_fdatasync = EIO_FDATASYNC
870 PPCODE: 932 PPCODE:
871{ 933{
879 REQ_SEND (req); 941 REQ_SEND (req);
880} 942}
881 943
882void 944void
883aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) 945aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef)
884 PROTOTYPE: $$$$;$
885 PPCODE: 946 PPCODE:
886{ 947{
887 int fd = s_fileno_croak (fh, 0); 948 int fd = s_fileno_croak (fh, 0);
888 dREQ; 949 dREQ;
889 950
897 REQ_SEND (req); 958 REQ_SEND (req);
898} 959}
899 960
900void 961void
901aio_close (SV *fh, SV *callback=&PL_sv_undef) 962aio_close (SV *fh, SV *callback=&PL_sv_undef)
902 PROTOTYPE: $;$
903 PPCODE: 963 PPCODE:
904{ 964{
905 static int close_pipe = -1; /* dummy fd to close fds via dup2 */ 965 static int close_pipe = -1; /* dummy fd to close fds via dup2 */
906 int fd = s_fileno_croak (fh, 0); 966 int fd = s_fileno_croak (fh, 0);
907 dREQ; 967 dREQ;
929void 989void
930aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) 990aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef)
931 ALIAS: 991 ALIAS:
932 aio_read = EIO_READ 992 aio_read = EIO_READ
933 aio_write = EIO_WRITE 993 aio_write = EIO_WRITE
934 PROTOTYPE: $$$$$;$
935 PPCODE: 994 PPCODE:
936{ 995{
937 STRLEN svlen; 996 STRLEN svlen;
938 int fd = s_fileno_croak (fh, ix == EIO_WRITE); 997 int fd = s_fileno_croak (fh, ix == EIO_WRITE);
939 char *svptr = SvPVbyte (data, svlen); 998 char *svptr = SvPVbyte (data, svlen);
980 } 1039 }
981} 1040}
982 1041
983void 1042void
984aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1043aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
985 PROTOTYPE: $$;$
986 PPCODE: 1044 PPCODE:
987{ 1045{
988 SV *data; 1046 SV *data;
989 dREQ; 1047 dREQ;
990 1048
995 REQ_SEND; 1053 REQ_SEND;
996} 1054}
997 1055
998void 1056void
999aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) 1057aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef)
1000 PROTOTYPE: $$$$;$
1001 PPCODE: 1058 PPCODE:
1002{ 1059{
1003 int ifd = s_fileno_croak (in_fh , 0); 1060 int ifd = s_fileno_croak (in_fh , 0);
1004 int ofd = s_fileno_croak (out_fh, 1); 1061 int ofd = s_fileno_croak (out_fh, 1);
1005 dREQ; 1062 dREQ;
1015 REQ_SEND; 1072 REQ_SEND;
1016} 1073}
1017 1074
1018void 1075void
1019aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) 1076aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef)
1020 PROTOTYPE: $$$;$
1021 PPCODE: 1077 PPCODE:
1022{ 1078{
1023 int fd = s_fileno_croak (fh, 0); 1079 int fd = s_fileno_croak (fh, 0);
1024 dREQ; 1080 dREQ;
1025 1081
1056 } 1112 }
1057 1113
1058 REQ_SEND; 1114 REQ_SEND;
1059} 1115}
1060 1116
1117UV
1118major (UV dev)
1119 ALIAS:
1120 minor = 1
1121 CODE:
1122 RETVAL = ix ? major (dev) : minor (dev);
1123 OUTPUT:
1124 RETVAL
1125
1126UV
1127makedev (UV maj, UV min)
1128 CODE:
1129 RETVAL = makedev (maj, min);
1130 OUTPUT:
1131 RETVAL
1132
1061void 1133void
1062aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) 1134aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef)
1063 PPCODE: 1135 PPCODE:
1064{ 1136{
1065 dREQ; 1137 dREQ;
1226void 1298void
1227aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) 1299aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef)
1228 ALIAS: 1300 ALIAS:
1229 aio_mtouch = EIO_MTOUCH 1301 aio_mtouch = EIO_MTOUCH
1230 aio_msync = EIO_MSYNC 1302 aio_msync = EIO_MSYNC
1231 PROTOTYPE: $$$$;$
1232 PPCODE: 1303 PPCODE:
1233{ 1304{
1234 STRLEN svlen; 1305 STRLEN svlen;
1306 char *svptr = SvPVbyte (data, svlen);
1235 UV len = SvUV (length); 1307 UV len = SvUV (length);
1236 char *svptr = SvPVbyte (data, svlen);
1237 1308
1238 if (offset < 0) 1309 if (offset < 0)
1239 offset += svlen; 1310 offset += svlen;
1240 1311
1241 if (offset < 0 || offset > svlen) 1312 if (offset < 0 || offset > svlen)
1246 1317
1247 { 1318 {
1248 dREQ; 1319 dREQ;
1249 1320
1250 req->type = ix; 1321 req->type = ix;
1251 req->size = len;
1252 req->sv2 = SvREFCNT_inc (data); 1322 req->sv2 = SvREFCNT_inc (data);
1253 req->ptr2 = (char *)svptr + offset; 1323 req->ptr2 = (char *)svptr + offset;
1324 req->size = len;
1254 req->int1 = flags; 1325 req->int1 = flags;
1255 1326
1256 REQ_SEND; 1327 REQ_SEND;
1257 } 1328 }
1258} 1329}
1259 1330
1260void 1331void
1332aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef)
1333 PPCODE:
1334{
1335 STRLEN svlen;
1336 char *svptr = SvPVbyte (data, svlen);
1337 UV len = SvUV (length);
1338
1339 if (offset < 0)
1340 offset += svlen;
1341
1342 if (offset < 0 || offset > svlen)
1343 croak ("offset outside of scalar");
1344
1345 if (!SvOK (length) || len + offset > svlen)
1346 len = svlen - offset;
1347
1348 {
1349 dREQ;
1350
1351 req->type = EIO_MLOCK;
1352 req->sv2 = SvREFCNT_inc (data);
1353 req->ptr2 = (char *)svptr + offset;
1354 req->size = len;
1355
1356 REQ_SEND;
1357 }
1358}
1359
1360void
1361aio_mlockall (IV flags, SV *callback=&PL_sv_undef)
1362 PPCODE:
1363{
1364 dREQ;
1365
1366 req->type = EIO_MLOCKALL;
1367 req->int1 = flags;
1368
1369 REQ_SEND;
1370}
1371
1372void
1261aio_busy (double delay, SV *callback=&PL_sv_undef) 1373aio_busy (double delay, SV *callback=&PL_sv_undef)
1262 PPCODE: 1374 PPCODE:
1263{ 1375{
1264 dREQ; 1376 dREQ;
1265 1377
1269 REQ_SEND; 1381 REQ_SEND;
1270} 1382}
1271 1383
1272void 1384void
1273aio_group (SV *callback=&PL_sv_undef) 1385aio_group (SV *callback=&PL_sv_undef)
1274 PROTOTYPE: ;$
1275 PPCODE: 1386 PPCODE:
1276{ 1387{
1277 dREQ; 1388 dREQ;
1278 1389
1279 req->type = EIO_GROUP; 1390 req->type = EIO_GROUP;
1296 REQ_SEND; 1407 REQ_SEND;
1297} 1408}
1298 1409
1299int 1410int
1300aioreq_pri (int pri = 0) 1411aioreq_pri (int pri = 0)
1301 PROTOTYPE: ;$
1302 CODE: 1412 CODE:
1303 RETVAL = next_pri; 1413 RETVAL = next_pri;
1304 if (items > 0) 1414 if (items > 0)
1305 { 1415 {
1306 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; 1416 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN;
1318 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; 1428 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX;
1319 next_pri = nice; 1429 next_pri = nice;
1320 1430
1321void 1431void
1322flush () 1432flush ()
1323 PROTOTYPE:
1324 CODE: 1433 CODE:
1325 while (eio_nreqs ()) 1434 while (eio_nreqs ())
1326 { 1435 {
1327 poll_wait (); 1436 poll_wait ();
1328 poll_cb (); 1437 poll_cb ();
1329 } 1438 }
1330 1439
1331int 1440int
1332poll() 1441poll ()
1333 PROTOTYPE:
1334 CODE: 1442 CODE:
1335 poll_wait (); 1443 poll_wait ();
1336 RETVAL = poll_cb (); 1444 RETVAL = poll_cb ();
1337 OUTPUT: 1445 OUTPUT:
1338 RETVAL 1446 RETVAL
1339 1447
1340int 1448int
1341poll_fileno() 1449poll_fileno ()
1342 PROTOTYPE:
1343 CODE: 1450 CODE:
1344 RETVAL = s_epipe_fd (&respipe); 1451 RETVAL = s_epipe_fd (&respipe);
1345 OUTPUT: 1452 OUTPUT:
1346 RETVAL 1453 RETVAL
1347 1454
1348int 1455int
1349poll_cb(...) 1456poll_cb (...)
1350 PROTOTYPE: 1457 PROTOTYPE:
1351 CODE: 1458 CODE:
1352 RETVAL = poll_cb (); 1459 RETVAL = poll_cb ();
1353 OUTPUT: 1460 OUTPUT:
1354 RETVAL 1461 RETVAL
1355 1462
1356void 1463void
1357poll_wait() 1464poll_wait ()
1358 PROTOTYPE:
1359 CODE: 1465 CODE:
1360 poll_wait (); 1466 poll_wait ();
1361 1467
1362int 1468int
1363nreqs() 1469nreqs ()
1364 PROTOTYPE:
1365 CODE: 1470 CODE:
1366 RETVAL = eio_nreqs (); 1471 RETVAL = eio_nreqs ();
1367 OUTPUT: 1472 OUTPUT:
1368 RETVAL 1473 RETVAL
1369 1474
1370int 1475int
1371nready() 1476nready ()
1372 PROTOTYPE:
1373 CODE: 1477 CODE:
1374 RETVAL = eio_nready (); 1478 RETVAL = eio_nready ();
1375 OUTPUT: 1479 OUTPUT:
1376 RETVAL 1480 RETVAL
1377 1481
1378int 1482int
1379npending() 1483npending ()
1380 PROTOTYPE:
1381 CODE: 1484 CODE:
1382 RETVAL = eio_npending (); 1485 RETVAL = eio_npending ();
1383 OUTPUT: 1486 OUTPUT:
1384 RETVAL 1487 RETVAL
1385 1488
1386int 1489int
1387nthreads() 1490nthreads ()
1388 PROTOTYPE:
1389 CODE: 1491 CODE:
1390 RETVAL = eio_nthreads (); 1492 RETVAL = eio_nthreads ();
1391 OUTPUT: 1493 OUTPUT:
1392 RETVAL 1494 RETVAL
1393 1495
1394int 1496int
1395fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) 1497fadvise (aio_rfd fh, off_t offset, off_t length, IV advice)
1396 PROTOTYPE: $$$$
1397 CODE: 1498 CODE:
1398 RETVAL = posix_fadvise (fh, offset, length, advice); 1499 RETVAL = posix_fadvise (fh, offset, length, advice);
1399 OUTPUT: 1500 OUTPUT:
1400 RETVAL 1501 RETVAL
1401 1502
1402ssize_t 1503ssize_t
1403sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1504sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1404 PROTOTYPE: $$$$
1405 CODE: 1505 CODE:
1406 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1506 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1407 OUTPUT: 1507 OUTPUT:
1408 RETVAL 1508 RETVAL
1409 1509
1410void 1510void
1411mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) 1511mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0)
1412 PROTOTYPE: $$$$$;$
1413 PPCODE: 1512 PPCODE:
1414 sv_unmagic (scalar, MMAP_MAGIC); 1513 sv_unmagic (scalar, MMAP_MAGIC);
1415{ 1514{
1416 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; 1515 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1;
1417 void *addr = (void *)mmap (0, length, prot, flags, fd, offset); 1516 void *addr = (void *)mmap (0, length, prot, flags, fd, offset);
1440 XSRETURN_YES; 1539 XSRETURN_YES;
1441} 1540}
1442 1541
1443void 1542void
1444munmap (SV *scalar) 1543munmap (SV *scalar)
1445 PROTOTYPE: $
1446 CODE: 1544 CODE:
1447 sv_unmagic (scalar, MMAP_MAGIC); 1545 sv_unmagic (scalar, MMAP_MAGIC);
1448 1546
1449int 1547int
1450madvise (SV *scalar, off_t offset, off_t length, IV advice) 1548madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
1451 PROTOTYPE: $$$$ 1549 ALIAS:
1550 mprotect = 1
1452 CODE: 1551 CODE:
1453{ 1552{
1454 char *addr = SvPV_nolen (scalar) + offset; 1553 STRLEN svlen;
1554 void *addr = SvPVbyte (scalar, svlen);
1555 size_t len = SvUV (length);
1455 1556
1456 if (!SvOK (ST (2))) 1557 if (offset < 0)
1558 offset += svlen;
1559
1560 if (offset < 0 || offset > svlen)
1561 croak ("offset outside of scalar");
1562
1563 if (!SvOK (length) || len + offset > svlen)
1457 length = SvCUR (scalar) - offset; 1564 len = svlen - offset;
1458 1565
1459 if (addr >= SvEND (scalar) || length <= 0) 1566 addr = (void *)(((intptr_t)addr) + offset);
1460 XSRETURN_EMPTY; 1567 eio_page_align (&addr, &len);
1461 1568
1569 switch (ix)
1570 {
1462 RETVAL = posix_madvise (addr, length, advice); 1571 case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break;
1572 case 1: RETVAL = mprotect (addr, len, advice_or_prot); break;
1573 }
1463} 1574}
1464 OUTPUT: 1575 OUTPUT:
1465 RETVAL 1576 RETVAL
1466 1577
1467int 1578int
1468mlockall (int flags) 1579munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef)
1469 PROTOTYPE: $
1470 CODE: 1580 CODE:
1581{
1582 STRLEN svlen;
1583 void *addr = SvPVbyte (scalar, svlen);
1584 size_t len = SvUV (length);
1585
1586 if (offset < 0)
1587 offset += svlen;
1588
1589 if (offset < 0 || offset > svlen)
1590 croak ("offset outside of scalar");
1591
1592 if (!SvOK (length) || len + offset > svlen)
1593 len = svlen - offset;
1594
1595 addr = (void *)(((intptr_t)addr) + offset);
1596 eio_page_align (&addr, &len);
1471#if _POSIX_MEMLOCK 1597#if _POSIX_MEMLOCK_RANGE
1472#if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 1598 RETVAL = munlock (addr, len);
1473 extern int mallopt (int, int);
1474 mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */
1475#endif
1476 mlockall (flags);
1477#else 1599#else
1478 RETVAL = -1; 1600 RETVAL = ((errno = ENOSYS), -1);
1479 errno = ENOSYS;
1480#endif 1601#endif
1602}
1481 OUTPUT: 1603 OUTPUT:
1482 RETVAL 1604 RETVAL
1483 1605
1484int 1606int
1485munlockall () 1607munlockall ()
1486 PROTOTYPE:
1487 CODE: 1608 CODE:
1488#if _POSIX_MEMLOCK 1609#if _POSIX_MEMLOCK
1489 munlockall (); 1610 munlockall ();
1490#else 1611#else
1491 RETVAL = -1; 1612 RETVAL = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines