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.169 by root, Wed Aug 4 16:06:54 2010 UTC vs.
Revision 1.179 by root, Fri Jan 7 21:47:15 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 !HAVE_POSIX_FADVISE
146# define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */
147#endif
148
145#ifndef POSIX_MADV_NORMAL 149#ifndef POSIX_MADV_NORMAL
146# define POSIX_MADV_NORMAL 0 150# define POSIX_MADV_NORMAL 0
147# define NO_MADVISE 1
148#endif 151#endif
149#ifndef POSIX_MADV_SEQUENTIAL 152#ifndef POSIX_MADV_SEQUENTIAL
150# define POSIX_MADV_SEQUENTIAL 0 153# define POSIX_MADV_SEQUENTIAL 0
151#endif 154#endif
152#ifndef POSIX_MADV_RANDOM 155#ifndef POSIX_MADV_RANDOM
157#endif 160#endif
158#ifndef POSIX_MADV_DONTNEED 161#ifndef POSIX_MADV_DONTNEED
159# define POSIX_MADV_DONTNEED 0 162# define POSIX_MADV_DONTNEED 0
160#endif 163#endif
161 164
165#if !HAVE_POSIX_MADVISE
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
180#endif
181
162#ifndef ST_NODEV 182#ifndef ST_NODEV
163# define ST_NODEV 0 183# define ST_NODEV 0
164#endif 184#endif
165#ifndef ST_NOEXEC 185#ifndef ST_NOEXEC
166# define ST_NOEXEC 0 186# define ST_NOEXEC 0
186#ifndef ST_NODIRATIME 206#ifndef ST_NODIRATIME
187# define ST_NODIRATIME 0 207# define ST_NODIRATIME 0
188#endif 208#endif
189#ifndef ST_RELATIME 209#ifndef ST_RELATIME
190# define ST_RELATIME 0 210# define ST_RELATIME 0
191#endif
192
193#ifndef MCL_CURRENT
194# define MCL_CURRENT 0
195#endif
196#ifndef MCL_FUTURE
197# define MCL_FUTURE 0
198#endif 211#endif
199 212
200#ifndef MAP_ANONYMOUS 213#ifndef MAP_ANONYMOUS
201# ifdef MAP_ANON 214# ifdef MAP_ANON
202# define MAP_ANONYMOUS MAP_ANON 215# define MAP_ANONYMOUS MAP_ANON
340 /* do not recreate the result IV from scratch each time */ 353 /* do not recreate the result IV from scratch each time */
341 if (expect_true (sv_result_cache)) 354 if (expect_true (sv_result_cache))
342 { 355 {
343 sv_result = sv_result_cache; sv_result_cache = 0; 356 sv_result = sv_result_cache; sv_result_cache = 0;
344 SvIV_set (sv_result, req->result); 357 SvIV_set (sv_result, req->result);
358 SvIOK_only (sv_result);
345 } 359 }
346 else 360 else
347 { 361 {
348 sv_result = newSViv (req->result); 362 sv_result = newSViv (req->result);
349 SvREADONLY_on (sv_result); 363 SvREADONLY_on (sv_result);
513 SvSETMAGIC (req->sv2); 527 SvSETMAGIC (req->sv2);
514 PUSHs (sv_result); 528 PUSHs (sv_result);
515 } 529 }
516 break; 530 break;
517 531
518 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ 532 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */
519 if (req->result > 0) 533 if (req->result > 0)
520 SvIV_set (sv_result, 0); 534 SvIV_set (sv_result, 0);
521 /* FALLTHROUGH */ 535 /* FALLTHROUGH */
522 536
523 default: 537 default:
623/*****************************************************************************/ 637/*****************************************************************************/
624 638
625#if !_POSIX_MAPPED_FILES 639#if !_POSIX_MAPPED_FILES
626# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) 640# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1)
627# define munmap(addr,length) (errno = ENOSYS, -1) 641# define munmap(addr,length) (errno = ENOSYS, -1)
642#endif
643
644#if !_POSIX_MEMORY_PROTECTION
645# define mprotect(addr,len,prot) (errno = ENOSYS, -1)
646# define PROT_NONE 0
647# define PROT_WRITE 0
648# define MAP_PRIVATE 0
649# define MAP_SHARED 0
650# define MAP_FIXED 0
628#endif 651#endif
629 652
630#define MMAP_MAGIC PERL_MAGIC_ext 653#define MMAP_MAGIC PERL_MAGIC_ext
631 654
632static int 655static int
735 const_iv (ST_IMMUTABLE) 758 const_iv (ST_IMMUTABLE)
736 const_iv (ST_NOATIME) 759 const_iv (ST_NOATIME)
737 const_iv (ST_NODIRATIME) 760 const_iv (ST_NODIRATIME)
738 const_iv (ST_RELATIME) 761 const_iv (ST_RELATIME)
739 762
763 const_iv (PROT_NONE)
740 const_iv (PROT_EXEC) 764 const_iv (PROT_EXEC)
741 const_iv (PROT_NONE)
742 const_iv (PROT_READ) 765 const_iv (PROT_READ)
743 const_iv (PROT_WRITE) 766 const_iv (PROT_WRITE)
744 767
745 /*const_iv (MAP_FIXED)*/ 768 /*const_iv (MAP_FIXED)*/
746 const_iv (MAP_PRIVATE) 769 const_iv (MAP_PRIVATE)
752 const_iv (MAP_LOCKED) 775 const_iv (MAP_LOCKED)
753 const_iv (MAP_NORESERVE) 776 const_iv (MAP_NORESERVE)
754 const_iv (MAP_POPULATE) 777 const_iv (MAP_POPULATE)
755 const_iv (MAP_NONBLOCK) 778 const_iv (MAP_NONBLOCK)
756 779
757 const_iv (MCL_FUTURE) 780 const_eio (MCL_FUTURE)
758 const_iv (MCL_CURRENT) 781 const_eio (MCL_CURRENT)
759 782
760 const_eio (MS_ASYNC) 783 const_eio (MS_ASYNC)
761 const_eio (MS_INVALIDATE) 784 const_eio (MS_INVALIDATE)
762 const_eio (MS_SYNC) 785 const_eio (MS_SYNC)
763 786
837 CODE: 860 CODE:
838 max_outstanding = maxreqs; 861 max_outstanding = maxreqs;
839 862
840void 863void
841aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 864aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
842 PROTOTYPE: $$$;$
843 PPCODE: 865 PPCODE:
844{ 866{
845 dREQ; 867 dREQ;
846 868
847 req->type = EIO_OPEN; 869 req->type = EIO_OPEN;
853 REQ_SEND; 875 REQ_SEND;
854} 876}
855 877
856void 878void
857aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 879aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
858 PROTOTYPE: $;$
859 ALIAS: 880 ALIAS:
860 aio_fsync = EIO_FSYNC 881 aio_fsync = EIO_FSYNC
861 aio_fdatasync = EIO_FDATASYNC 882 aio_fdatasync = EIO_FDATASYNC
862 PPCODE: 883 PPCODE:
863{ 884{
871 REQ_SEND (req); 892 REQ_SEND (req);
872} 893}
873 894
874void 895void
875aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) 896aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef)
876 PROTOTYPE: $$$$;$
877 PPCODE: 897 PPCODE:
878{ 898{
879 int fd = s_fileno_croak (fh, 0); 899 int fd = s_fileno_croak (fh, 0);
880 dREQ; 900 dREQ;
881 901
889 REQ_SEND (req); 909 REQ_SEND (req);
890} 910}
891 911
892void 912void
893aio_close (SV *fh, SV *callback=&PL_sv_undef) 913aio_close (SV *fh, SV *callback=&PL_sv_undef)
894 PROTOTYPE: $;$
895 PPCODE: 914 PPCODE:
896{ 915{
897 static int close_pipe = -1; /* dummy fd to close fds via dup2 */ 916 static int close_pipe = -1; /* dummy fd to close fds via dup2 */
898 int fd = s_fileno_croak (fh, 0); 917 int fd = s_fileno_croak (fh, 0);
899 dREQ; 918 dREQ;
921void 940void
922aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) 941aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef)
923 ALIAS: 942 ALIAS:
924 aio_read = EIO_READ 943 aio_read = EIO_READ
925 aio_write = EIO_WRITE 944 aio_write = EIO_WRITE
926 PROTOTYPE: $$$$$;$
927 PPCODE: 945 PPCODE:
928{ 946{
929 STRLEN svlen; 947 STRLEN svlen;
930 int fd = s_fileno_croak (fh, ix == EIO_WRITE); 948 int fd = s_fileno_croak (fh, ix == EIO_WRITE);
931 char *svptr = SvPVbyte (data, svlen); 949 char *svptr = SvPVbyte (data, svlen);
972 } 990 }
973} 991}
974 992
975void 993void
976aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 994aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
977 PROTOTYPE: $$;$
978 PPCODE: 995 PPCODE:
979{ 996{
980 SV *data; 997 SV *data;
981 dREQ; 998 dREQ;
982 999
987 REQ_SEND; 1004 REQ_SEND;
988} 1005}
989 1006
990void 1007void
991aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) 1008aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef)
992 PROTOTYPE: $$$$;$
993 PPCODE: 1009 PPCODE:
994{ 1010{
995 int ifd = s_fileno_croak (in_fh , 0); 1011 int ifd = s_fileno_croak (in_fh , 0);
996 int ofd = s_fileno_croak (out_fh, 1); 1012 int ofd = s_fileno_croak (out_fh, 1);
997 dREQ; 1013 dREQ;
1007 REQ_SEND; 1023 REQ_SEND;
1008} 1024}
1009 1025
1010void 1026void
1011aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) 1027aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef)
1012 PROTOTYPE: $$$;$
1013 PPCODE: 1028 PPCODE:
1014{ 1029{
1015 int fd = s_fileno_croak (fh, 0); 1030 int fd = s_fileno_croak (fh, 0);
1016 dREQ; 1031 dREQ;
1017 1032
1218void 1233void
1219aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) 1234aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef)
1220 ALIAS: 1235 ALIAS:
1221 aio_mtouch = EIO_MTOUCH 1236 aio_mtouch = EIO_MTOUCH
1222 aio_msync = EIO_MSYNC 1237 aio_msync = EIO_MSYNC
1223 PROTOTYPE: $$$$;$
1224 PPCODE: 1238 PPCODE:
1225{ 1239{
1226 STRLEN svlen; 1240 STRLEN svlen;
1241 char *svptr = SvPVbyte (data, svlen);
1227 UV len = SvUV (length); 1242 UV len = SvUV (length);
1228 char *svptr = SvPVbyte (data, svlen);
1229 1243
1230 if (offset < 0) 1244 if (offset < 0)
1231 offset += svlen; 1245 offset += svlen;
1232 1246
1233 if (offset < 0 || offset > svlen) 1247 if (offset < 0 || offset > svlen)
1238 1252
1239 { 1253 {
1240 dREQ; 1254 dREQ;
1241 1255
1242 req->type = ix; 1256 req->type = ix;
1243 req->size = len;
1244 req->sv2 = SvREFCNT_inc (data); 1257 req->sv2 = SvREFCNT_inc (data);
1245 req->ptr2 = (char *)svptr + offset; 1258 req->ptr2 = (char *)svptr + offset;
1259 req->size = len;
1246 req->int1 = flags; 1260 req->int1 = flags;
1247 1261
1248 REQ_SEND; 1262 REQ_SEND;
1249 } 1263 }
1250} 1264}
1251 1265
1252void 1266void
1267aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef)
1268 PPCODE:
1269{
1270 STRLEN svlen;
1271 char *svptr = SvPVbyte (data, svlen);
1272 UV len = SvUV (length);
1273
1274 if (offset < 0)
1275 offset += svlen;
1276
1277 if (offset < 0 || offset > svlen)
1278 croak ("offset outside of scalar");
1279
1280 if (!SvOK (length) || len + offset > svlen)
1281 len = svlen - offset;
1282
1283 {
1284 dREQ;
1285
1286 req->type = EIO_MLOCK;
1287 req->sv2 = SvREFCNT_inc (data);
1288 req->ptr2 = (char *)svptr + offset;
1289 req->size = len;
1290
1291 REQ_SEND;
1292 }
1293}
1294
1295void
1296aio_mlockall (IV flags, SV *callback=&PL_sv_undef)
1297 PPCODE:
1298{
1299 dREQ;
1300
1301 req->type = EIO_MLOCKALL;
1302 req->int1 = flags;
1303
1304 REQ_SEND;
1305}
1306
1307void
1253aio_busy (double delay, SV *callback=&PL_sv_undef) 1308aio_busy (double delay, SV *callback=&PL_sv_undef)
1254 PPCODE: 1309 PPCODE:
1255{ 1310{
1256 dREQ; 1311 dREQ;
1257 1312
1261 REQ_SEND; 1316 REQ_SEND;
1262} 1317}
1263 1318
1264void 1319void
1265aio_group (SV *callback=&PL_sv_undef) 1320aio_group (SV *callback=&PL_sv_undef)
1266 PROTOTYPE: ;$
1267 PPCODE: 1321 PPCODE:
1268{ 1322{
1269 dREQ; 1323 dREQ;
1270 1324
1271 req->type = EIO_GROUP; 1325 req->type = EIO_GROUP;
1288 REQ_SEND; 1342 REQ_SEND;
1289} 1343}
1290 1344
1291int 1345int
1292aioreq_pri (int pri = 0) 1346aioreq_pri (int pri = 0)
1293 PROTOTYPE: ;$
1294 CODE: 1347 CODE:
1295 RETVAL = next_pri; 1348 RETVAL = next_pri;
1296 if (items > 0) 1349 if (items > 0)
1297 { 1350 {
1298 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; 1351 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN;
1310 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; 1363 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX;
1311 next_pri = nice; 1364 next_pri = nice;
1312 1365
1313void 1366void
1314flush () 1367flush ()
1315 PROTOTYPE:
1316 CODE: 1368 CODE:
1317 while (eio_nreqs ()) 1369 while (eio_nreqs ())
1318 { 1370 {
1319 poll_wait (); 1371 poll_wait ();
1320 poll_cb (); 1372 poll_cb ();
1321 } 1373 }
1322 1374
1323int 1375int
1324poll() 1376poll ()
1325 PROTOTYPE:
1326 CODE: 1377 CODE:
1327 poll_wait (); 1378 poll_wait ();
1328 RETVAL = poll_cb (); 1379 RETVAL = poll_cb ();
1329 OUTPUT: 1380 OUTPUT:
1330 RETVAL 1381 RETVAL
1331 1382
1332int 1383int
1333poll_fileno() 1384poll_fileno ()
1334 PROTOTYPE:
1335 CODE: 1385 CODE:
1336 RETVAL = s_epipe_fd (&respipe); 1386 RETVAL = s_epipe_fd (&respipe);
1337 OUTPUT: 1387 OUTPUT:
1338 RETVAL 1388 RETVAL
1339 1389
1340int 1390int
1341poll_cb(...) 1391poll_cb (...)
1342 PROTOTYPE: 1392 PROTOTYPE:
1343 CODE: 1393 CODE:
1344 RETVAL = poll_cb (); 1394 RETVAL = poll_cb ();
1345 OUTPUT: 1395 OUTPUT:
1346 RETVAL 1396 RETVAL
1347 1397
1348void 1398void
1349poll_wait() 1399poll_wait ()
1350 PROTOTYPE:
1351 CODE: 1400 CODE:
1352 poll_wait (); 1401 poll_wait ();
1353 1402
1354int 1403int
1355nreqs() 1404nreqs ()
1356 PROTOTYPE:
1357 CODE: 1405 CODE:
1358 RETVAL = eio_nreqs (); 1406 RETVAL = eio_nreqs ();
1359 OUTPUT: 1407 OUTPUT:
1360 RETVAL 1408 RETVAL
1361 1409
1362int 1410int
1363nready() 1411nready ()
1364 PROTOTYPE:
1365 CODE: 1412 CODE:
1366 RETVAL = eio_nready (); 1413 RETVAL = eio_nready ();
1367 OUTPUT: 1414 OUTPUT:
1368 RETVAL 1415 RETVAL
1369 1416
1370int 1417int
1371npending() 1418npending ()
1372 PROTOTYPE:
1373 CODE: 1419 CODE:
1374 RETVAL = eio_npending (); 1420 RETVAL = eio_npending ();
1375 OUTPUT: 1421 OUTPUT:
1376 RETVAL 1422 RETVAL
1377 1423
1378int 1424int
1379nthreads() 1425nthreads ()
1380 PROTOTYPE:
1381 CODE: 1426 CODE:
1382 RETVAL = eio_nthreads (); 1427 RETVAL = eio_nthreads ();
1383 OUTPUT: 1428 OUTPUT:
1384 RETVAL 1429 RETVAL
1385 1430
1386int 1431int
1387fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) 1432fadvise (aio_rfd fh, off_t offset, off_t length, IV advice)
1388 PROTOTYPE: $$$$
1389 CODE: 1433 CODE:
1390#if _XOPEN_SOURCE >= 600 && !NO_FADVISE
1391 RETVAL = posix_fadvise (fh, offset, length, advice); 1434 RETVAL = posix_fadvise (fh, offset, length, advice);
1392#else
1393 RETVAL = errno = ENOSYS; /* yes, this is actually correct */
1394#endif
1395 OUTPUT: 1435 OUTPUT:
1396 RETVAL 1436 RETVAL
1397 1437
1398ssize_t 1438ssize_t
1399sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1439sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1400 PROTOTYPE: $$$$
1401 CODE: 1440 CODE:
1402 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1441 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1403 OUTPUT: 1442 OUTPUT:
1404 RETVAL 1443 RETVAL
1405 1444
1406void 1445void
1407mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) 1446mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0)
1408 PROTOTYPE: $$$$$;$
1409 PPCODE: 1447 PPCODE:
1410 sv_unmagic (scalar, MMAP_MAGIC); 1448 sv_unmagic (scalar, MMAP_MAGIC);
1411{ 1449{
1412 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; 1450 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1;
1413 void *addr = (void *)mmap (0, length, prot, flags, fd, offset); 1451 void *addr = (void *)mmap (0, length, prot, flags, fd, offset);
1436 XSRETURN_YES; 1474 XSRETURN_YES;
1437} 1475}
1438 1476
1439void 1477void
1440munmap (SV *scalar) 1478munmap (SV *scalar)
1441 PROTOTYPE: $
1442 CODE: 1479 CODE:
1443 sv_unmagic (scalar, MMAP_MAGIC); 1480 sv_unmagic (scalar, MMAP_MAGIC);
1444 1481
1445int 1482int
1446madvise (SV *scalar, off_t offset, off_t length, IV advice) 1483madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
1447 PROTOTYPE: $$$$ 1484 ALIAS:
1485 mprotect = 1
1448 CODE: 1486 CODE:
1449{ 1487{
1450 char *addr = SvPV_nolen (scalar) + offset; 1488 STRLEN svlen;
1489 void *addr = SvPVbyte (scalar, svlen);
1490 size_t len = SvUV (length);
1451 1491
1452 if (!SvOK (ST (2))) 1492 if (offset < 0)
1493 offset += svlen;
1494
1495 if (offset < 0 || offset > svlen)
1496 croak ("offset outside of scalar");
1497
1498 if (!SvOK (length) || len + offset > svlen)
1453 length = SvCUR (scalar) - offset; 1499 len = svlen - offset;
1454 1500
1455 if (addr >= SvEND (scalar) || length <= 0) 1501 addr = (void *)(((intptr_t)addr) + offset);
1456 XSRETURN_EMPTY; 1502 eio_page_align (&addr, &len);
1457 1503
1458 #if _XOPEN_SOURCE >= 600 && !NO_MADVISE 1504 switch (ix)
1505 {
1459 RETVAL = posix_madvise (addr, length, advice); 1506 case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break;
1460 #else 1507 case 1: RETVAL = mprotect (addr, len, advice_or_prot); break;
1461 RETVAL = errno = ENOSYS; /* yes, this is actually correct */ 1508 }
1462 #endif
1463} 1509}
1464 OUTPUT: 1510 OUTPUT:
1465 RETVAL 1511 RETVAL
1466 1512
1467int 1513int
1468mlockall (int flags) 1514munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef)
1469 PROTOTYPE: $
1470 CODE: 1515 CODE:
1516{
1517 STRLEN svlen;
1518 void *addr = SvPVbyte (scalar, svlen);
1519 size_t len = SvUV (length);
1520
1521 if (offset < 0)
1522 offset += svlen;
1523
1524 if (offset < 0 || offset > svlen)
1525 croak ("offset outside of scalar");
1526
1527 if (!SvOK (length) || len + offset > svlen)
1528 len = svlen - offset;
1529
1530 addr = (void *)(((intptr_t)addr) + offset);
1531 eio_page_align (&addr, &len);
1471#if _POSIX_MEMLOCK 1532#if _POSIX_MEMLOCK_RANGE
1472#if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 1533 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 1534#else
1478 RETVAL = -1; 1535 RETVAL = ((errno = ENOSYS), -1);
1479 errno = ENOSYS;
1480#endif 1536#endif
1537}
1481 OUTPUT: 1538 OUTPUT:
1482 RETVAL 1539 RETVAL
1483 1540
1484int 1541int
1485munlockall () 1542munlockall ()
1486 PROTOTYPE:
1487 CODE: 1543 CODE:
1488#if _POSIX_MEMLOCK 1544#if _POSIX_MEMLOCK
1489 munlockall (); 1545 munlockall ();
1490#else 1546#else
1491 RETVAL = -1; 1547 RETVAL = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines