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.180 by root, Fri Feb 11 00:05:17 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
845 CODE: 903 CODE:
846 max_outstanding = maxreqs; 904 max_outstanding = maxreqs;
847 905
848void 906void
849aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 907aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
850 PROTOTYPE: $$$;$
851 PPCODE: 908 PPCODE:
852{ 909{
853 dREQ; 910 dREQ;
854 911
855 req->type = EIO_OPEN; 912 req->type = EIO_OPEN;
861 REQ_SEND; 918 REQ_SEND;
862} 919}
863 920
864void 921void
865aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 922aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
866 PROTOTYPE: $;$
867 ALIAS: 923 ALIAS:
868 aio_fsync = EIO_FSYNC 924 aio_fsync = EIO_FSYNC
869 aio_fdatasync = EIO_FDATASYNC 925 aio_fdatasync = EIO_FDATASYNC
870 PPCODE: 926 PPCODE:
871{ 927{
879 REQ_SEND (req); 935 REQ_SEND (req);
880} 936}
881 937
882void 938void
883aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) 939aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef)
884 PROTOTYPE: $$$$;$
885 PPCODE: 940 PPCODE:
886{ 941{
887 int fd = s_fileno_croak (fh, 0); 942 int fd = s_fileno_croak (fh, 0);
888 dREQ; 943 dREQ;
889 944
897 REQ_SEND (req); 952 REQ_SEND (req);
898} 953}
899 954
900void 955void
901aio_close (SV *fh, SV *callback=&PL_sv_undef) 956aio_close (SV *fh, SV *callback=&PL_sv_undef)
902 PROTOTYPE: $;$
903 PPCODE: 957 PPCODE:
904{ 958{
905 static int close_pipe = -1; /* dummy fd to close fds via dup2 */ 959 static int close_pipe = -1; /* dummy fd to close fds via dup2 */
906 int fd = s_fileno_croak (fh, 0); 960 int fd = s_fileno_croak (fh, 0);
907 dREQ; 961 dREQ;
929void 983void
930aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) 984aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef)
931 ALIAS: 985 ALIAS:
932 aio_read = EIO_READ 986 aio_read = EIO_READ
933 aio_write = EIO_WRITE 987 aio_write = EIO_WRITE
934 PROTOTYPE: $$$$$;$
935 PPCODE: 988 PPCODE:
936{ 989{
937 STRLEN svlen; 990 STRLEN svlen;
938 int fd = s_fileno_croak (fh, ix == EIO_WRITE); 991 int fd = s_fileno_croak (fh, ix == EIO_WRITE);
939 char *svptr = SvPVbyte (data, svlen); 992 char *svptr = SvPVbyte (data, svlen);
980 } 1033 }
981} 1034}
982 1035
983void 1036void
984aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1037aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
985 PROTOTYPE: $$;$
986 PPCODE: 1038 PPCODE:
987{ 1039{
988 SV *data; 1040 SV *data;
989 dREQ; 1041 dREQ;
990 1042
995 REQ_SEND; 1047 REQ_SEND;
996} 1048}
997 1049
998void 1050void
999aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) 1051aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef)
1000 PROTOTYPE: $$$$;$
1001 PPCODE: 1052 PPCODE:
1002{ 1053{
1003 int ifd = s_fileno_croak (in_fh , 0); 1054 int ifd = s_fileno_croak (in_fh , 0);
1004 int ofd = s_fileno_croak (out_fh, 1); 1055 int ofd = s_fileno_croak (out_fh, 1);
1005 dREQ; 1056 dREQ;
1015 REQ_SEND; 1066 REQ_SEND;
1016} 1067}
1017 1068
1018void 1069void
1019aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) 1070aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef)
1020 PROTOTYPE: $$$;$
1021 PPCODE: 1071 PPCODE:
1022{ 1072{
1023 int fd = s_fileno_croak (fh, 0); 1073 int fd = s_fileno_croak (fh, 0);
1024 dREQ; 1074 dREQ;
1025 1075
1056 } 1106 }
1057 1107
1058 REQ_SEND; 1108 REQ_SEND;
1059} 1109}
1060 1110
1111UV
1112major (UV dev)
1113 ALIAS:
1114 minor = 1
1115 CODE:
1116 RETVAL = ix ? major (dev) : minor (dev);
1117 OUTPUT:
1118 RETVAL
1119
1120UV
1121makedev (UV maj, UV min)
1122 CODE:
1123 RETVAL = makedev (maj, min);
1124 OUTPUT:
1125 RETVAL
1126
1061void 1127void
1062aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) 1128aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef)
1063 PPCODE: 1129 PPCODE:
1064{ 1130{
1065 dREQ; 1131 dREQ;
1226void 1292void
1227aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) 1293aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef)
1228 ALIAS: 1294 ALIAS:
1229 aio_mtouch = EIO_MTOUCH 1295 aio_mtouch = EIO_MTOUCH
1230 aio_msync = EIO_MSYNC 1296 aio_msync = EIO_MSYNC
1231 PROTOTYPE: $$$$;$
1232 PPCODE: 1297 PPCODE:
1233{ 1298{
1234 STRLEN svlen; 1299 STRLEN svlen;
1300 char *svptr = SvPVbyte (data, svlen);
1235 UV len = SvUV (length); 1301 UV len = SvUV (length);
1236 char *svptr = SvPVbyte (data, svlen);
1237 1302
1238 if (offset < 0) 1303 if (offset < 0)
1239 offset += svlen; 1304 offset += svlen;
1240 1305
1241 if (offset < 0 || offset > svlen) 1306 if (offset < 0 || offset > svlen)
1246 1311
1247 { 1312 {
1248 dREQ; 1313 dREQ;
1249 1314
1250 req->type = ix; 1315 req->type = ix;
1251 req->size = len;
1252 req->sv2 = SvREFCNT_inc (data); 1316 req->sv2 = SvREFCNT_inc (data);
1253 req->ptr2 = (char *)svptr + offset; 1317 req->ptr2 = (char *)svptr + offset;
1318 req->size = len;
1254 req->int1 = flags; 1319 req->int1 = flags;
1255 1320
1256 REQ_SEND; 1321 REQ_SEND;
1257 } 1322 }
1258} 1323}
1259 1324
1260void 1325void
1326aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef)
1327 PPCODE:
1328{
1329 STRLEN svlen;
1330 char *svptr = SvPVbyte (data, svlen);
1331 UV len = SvUV (length);
1332
1333 if (offset < 0)
1334 offset += svlen;
1335
1336 if (offset < 0 || offset > svlen)
1337 croak ("offset outside of scalar");
1338
1339 if (!SvOK (length) || len + offset > svlen)
1340 len = svlen - offset;
1341
1342 {
1343 dREQ;
1344
1345 req->type = EIO_MLOCK;
1346 req->sv2 = SvREFCNT_inc (data);
1347 req->ptr2 = (char *)svptr + offset;
1348 req->size = len;
1349
1350 REQ_SEND;
1351 }
1352}
1353
1354void
1355aio_mlockall (IV flags, SV *callback=&PL_sv_undef)
1356 PPCODE:
1357{
1358 dREQ;
1359
1360 req->type = EIO_MLOCKALL;
1361 req->int1 = flags;
1362
1363 REQ_SEND;
1364}
1365
1366void
1261aio_busy (double delay, SV *callback=&PL_sv_undef) 1367aio_busy (double delay, SV *callback=&PL_sv_undef)
1262 PPCODE: 1368 PPCODE:
1263{ 1369{
1264 dREQ; 1370 dREQ;
1265 1371
1269 REQ_SEND; 1375 REQ_SEND;
1270} 1376}
1271 1377
1272void 1378void
1273aio_group (SV *callback=&PL_sv_undef) 1379aio_group (SV *callback=&PL_sv_undef)
1274 PROTOTYPE: ;$
1275 PPCODE: 1380 PPCODE:
1276{ 1381{
1277 dREQ; 1382 dREQ;
1278 1383
1279 req->type = EIO_GROUP; 1384 req->type = EIO_GROUP;
1296 REQ_SEND; 1401 REQ_SEND;
1297} 1402}
1298 1403
1299int 1404int
1300aioreq_pri (int pri = 0) 1405aioreq_pri (int pri = 0)
1301 PROTOTYPE: ;$
1302 CODE: 1406 CODE:
1303 RETVAL = next_pri; 1407 RETVAL = next_pri;
1304 if (items > 0) 1408 if (items > 0)
1305 { 1409 {
1306 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; 1410 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN;
1318 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; 1422 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX;
1319 next_pri = nice; 1423 next_pri = nice;
1320 1424
1321void 1425void
1322flush () 1426flush ()
1323 PROTOTYPE:
1324 CODE: 1427 CODE:
1325 while (eio_nreqs ()) 1428 while (eio_nreqs ())
1326 { 1429 {
1327 poll_wait (); 1430 poll_wait ();
1328 poll_cb (); 1431 poll_cb ();
1329 } 1432 }
1330 1433
1331int 1434int
1332poll() 1435poll ()
1333 PROTOTYPE:
1334 CODE: 1436 CODE:
1335 poll_wait (); 1437 poll_wait ();
1336 RETVAL = poll_cb (); 1438 RETVAL = poll_cb ();
1337 OUTPUT: 1439 OUTPUT:
1338 RETVAL 1440 RETVAL
1339 1441
1340int 1442int
1341poll_fileno() 1443poll_fileno ()
1342 PROTOTYPE:
1343 CODE: 1444 CODE:
1344 RETVAL = s_epipe_fd (&respipe); 1445 RETVAL = s_epipe_fd (&respipe);
1345 OUTPUT: 1446 OUTPUT:
1346 RETVAL 1447 RETVAL
1347 1448
1348int 1449int
1349poll_cb(...) 1450poll_cb (...)
1350 PROTOTYPE: 1451 PROTOTYPE:
1351 CODE: 1452 CODE:
1352 RETVAL = poll_cb (); 1453 RETVAL = poll_cb ();
1353 OUTPUT: 1454 OUTPUT:
1354 RETVAL 1455 RETVAL
1355 1456
1356void 1457void
1357poll_wait() 1458poll_wait ()
1358 PROTOTYPE:
1359 CODE: 1459 CODE:
1360 poll_wait (); 1460 poll_wait ();
1361 1461
1362int 1462int
1363nreqs() 1463nreqs ()
1364 PROTOTYPE:
1365 CODE: 1464 CODE:
1366 RETVAL = eio_nreqs (); 1465 RETVAL = eio_nreqs ();
1367 OUTPUT: 1466 OUTPUT:
1368 RETVAL 1467 RETVAL
1369 1468
1370int 1469int
1371nready() 1470nready ()
1372 PROTOTYPE:
1373 CODE: 1471 CODE:
1374 RETVAL = eio_nready (); 1472 RETVAL = eio_nready ();
1375 OUTPUT: 1473 OUTPUT:
1376 RETVAL 1474 RETVAL
1377 1475
1378int 1476int
1379npending() 1477npending ()
1380 PROTOTYPE:
1381 CODE: 1478 CODE:
1382 RETVAL = eio_npending (); 1479 RETVAL = eio_npending ();
1383 OUTPUT: 1480 OUTPUT:
1384 RETVAL 1481 RETVAL
1385 1482
1386int 1483int
1387nthreads() 1484nthreads ()
1388 PROTOTYPE:
1389 CODE: 1485 CODE:
1390 RETVAL = eio_nthreads (); 1486 RETVAL = eio_nthreads ();
1391 OUTPUT: 1487 OUTPUT:
1392 RETVAL 1488 RETVAL
1393 1489
1394int 1490int
1395fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) 1491fadvise (aio_rfd fh, off_t offset, off_t length, IV advice)
1396 PROTOTYPE: $$$$
1397 CODE: 1492 CODE:
1398 RETVAL = posix_fadvise (fh, offset, length, advice); 1493 RETVAL = posix_fadvise (fh, offset, length, advice);
1399 OUTPUT: 1494 OUTPUT:
1400 RETVAL 1495 RETVAL
1401 1496
1402ssize_t 1497ssize_t
1403sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1498sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1404 PROTOTYPE: $$$$
1405 CODE: 1499 CODE:
1406 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1500 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1407 OUTPUT: 1501 OUTPUT:
1408 RETVAL 1502 RETVAL
1409 1503
1410void 1504void
1411mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) 1505mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0)
1412 PROTOTYPE: $$$$$;$
1413 PPCODE: 1506 PPCODE:
1414 sv_unmagic (scalar, MMAP_MAGIC); 1507 sv_unmagic (scalar, MMAP_MAGIC);
1415{ 1508{
1416 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; 1509 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1;
1417 void *addr = (void *)mmap (0, length, prot, flags, fd, offset); 1510 void *addr = (void *)mmap (0, length, prot, flags, fd, offset);
1440 XSRETURN_YES; 1533 XSRETURN_YES;
1441} 1534}
1442 1535
1443void 1536void
1444munmap (SV *scalar) 1537munmap (SV *scalar)
1445 PROTOTYPE: $
1446 CODE: 1538 CODE:
1447 sv_unmagic (scalar, MMAP_MAGIC); 1539 sv_unmagic (scalar, MMAP_MAGIC);
1448 1540
1449int 1541int
1450madvise (SV *scalar, off_t offset, off_t length, IV advice) 1542madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
1451 PROTOTYPE: $$$$ 1543 ALIAS:
1544 mprotect = 1
1452 CODE: 1545 CODE:
1453{ 1546{
1454 char *addr = SvPV_nolen (scalar) + offset; 1547 STRLEN svlen;
1548 void *addr = SvPVbyte (scalar, svlen);
1549 size_t len = SvUV (length);
1455 1550
1456 if (!SvOK (ST (2))) 1551 if (offset < 0)
1552 offset += svlen;
1553
1554 if (offset < 0 || offset > svlen)
1555 croak ("offset outside of scalar");
1556
1557 if (!SvOK (length) || len + offset > svlen)
1457 length = SvCUR (scalar) - offset; 1558 len = svlen - offset;
1458 1559
1459 if (addr >= SvEND (scalar) || length <= 0) 1560 addr = (void *)(((intptr_t)addr) + offset);
1460 XSRETURN_EMPTY; 1561 eio_page_align (&addr, &len);
1461 1562
1563 switch (ix)
1564 {
1462 RETVAL = posix_madvise (addr, length, advice); 1565 case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break;
1566 case 1: RETVAL = mprotect (addr, len, advice_or_prot); break;
1567 }
1463} 1568}
1464 OUTPUT: 1569 OUTPUT:
1465 RETVAL 1570 RETVAL
1466 1571
1467int 1572int
1468mlockall (int flags) 1573munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef)
1469 PROTOTYPE: $
1470 CODE: 1574 CODE:
1575{
1576 STRLEN svlen;
1577 void *addr = SvPVbyte (scalar, svlen);
1578 size_t len = SvUV (length);
1579
1580 if (offset < 0)
1581 offset += svlen;
1582
1583 if (offset < 0 || offset > svlen)
1584 croak ("offset outside of scalar");
1585
1586 if (!SvOK (length) || len + offset > svlen)
1587 len = svlen - offset;
1588
1589 addr = (void *)(((intptr_t)addr) + offset);
1590 eio_page_align (&addr, &len);
1471#if _POSIX_MEMLOCK 1591#if _POSIX_MEMLOCK_RANGE
1472#if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 1592 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 1593#else
1478 RETVAL = -1; 1594 RETVAL = ((errno = ENOSYS), -1);
1479 errno = ENOSYS;
1480#endif 1595#endif
1596}
1481 OUTPUT: 1597 OUTPUT:
1482 RETVAL 1598 RETVAL
1483 1599
1484int 1600int
1485munlockall () 1601munlockall ()
1486 PROTOTYPE:
1487 CODE: 1602 CODE:
1488#if _POSIX_MEMLOCK 1603#if _POSIX_MEMLOCK
1489 munlockall (); 1604 munlockall ();
1490#else 1605#else
1491 RETVAL = -1; 1606 RETVAL = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines