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.172 by root, Sun Sep 12 03:36:27 2010 UTC

165 165
166#if _XOPEN_SOURCE < 600 || NO_MADVISE 166#if _XOPEN_SOURCE < 600 || NO_MADVISE
167# define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ 167# define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */
168#endif 168#endif
169 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
170#ifndef ST_NODEV 183#ifndef ST_NODEV
171# define ST_NODEV 0 184# define ST_NODEV 0
172#endif 185#endif
173#ifndef ST_NOEXEC 186#ifndef ST_NOEXEC
174# define ST_NOEXEC 0 187# define ST_NOEXEC 0
194#ifndef ST_NODIRATIME 207#ifndef ST_NODIRATIME
195# define ST_NODIRATIME 0 208# define ST_NODIRATIME 0
196#endif 209#endif
197#ifndef ST_RELATIME 210#ifndef ST_RELATIME
198# define ST_RELATIME 0 211# define ST_RELATIME 0
199#endif
200
201#ifndef MCL_CURRENT
202# define MCL_CURRENT 0
203#endif
204#ifndef MCL_FUTURE
205# define MCL_FUTURE 0
206#endif 212#endif
207 213
208#ifndef MAP_ANONYMOUS 214#ifndef MAP_ANONYMOUS
209# ifdef MAP_ANON 215# ifdef MAP_ANON
210# define MAP_ANONYMOUS MAP_ANON 216# define MAP_ANONYMOUS MAP_ANON
631/*****************************************************************************/ 637/*****************************************************************************/
632 638
633#if !_POSIX_MAPPED_FILES 639#if !_POSIX_MAPPED_FILES
634# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) 640# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1)
635# define munmap(addr,length) (errno = ENOSYS, -1) 641# define munmap(addr,length) (errno = ENOSYS, -1)
642# define mprotect(addr,len,prot) (errno = ENOSYS, -1)
636#endif 643#endif
637 644
638#define MMAP_MAGIC PERL_MAGIC_ext 645#define MMAP_MAGIC PERL_MAGIC_ext
639 646
640static int 647static int
743 const_iv (ST_IMMUTABLE) 750 const_iv (ST_IMMUTABLE)
744 const_iv (ST_NOATIME) 751 const_iv (ST_NOATIME)
745 const_iv (ST_NODIRATIME) 752 const_iv (ST_NODIRATIME)
746 const_iv (ST_RELATIME) 753 const_iv (ST_RELATIME)
747 754
755 const_iv (PROT_NONE)
748 const_iv (PROT_EXEC) 756 const_iv (PROT_EXEC)
749 const_iv (PROT_NONE)
750 const_iv (PROT_READ) 757 const_iv (PROT_READ)
751 const_iv (PROT_WRITE) 758 const_iv (PROT_WRITE)
752 759
753 /*const_iv (MAP_FIXED)*/ 760 /*const_iv (MAP_FIXED)*/
754 const_iv (MAP_PRIVATE) 761 const_iv (MAP_PRIVATE)
760 const_iv (MAP_LOCKED) 767 const_iv (MAP_LOCKED)
761 const_iv (MAP_NORESERVE) 768 const_iv (MAP_NORESERVE)
762 const_iv (MAP_POPULATE) 769 const_iv (MAP_POPULATE)
763 const_iv (MAP_NONBLOCK) 770 const_iv (MAP_NONBLOCK)
764 771
765 const_iv (MCL_FUTURE) 772 const_eio (MCL_FUTURE)
766 const_iv (MCL_CURRENT) 773 const_eio (MCL_CURRENT)
767 774
768 const_eio (MS_ASYNC) 775 const_eio (MS_ASYNC)
769 const_eio (MS_INVALIDATE) 776 const_eio (MS_INVALIDATE)
770 const_eio (MS_SYNC) 777 const_eio (MS_SYNC)
771 778
845 CODE: 852 CODE:
846 max_outstanding = maxreqs; 853 max_outstanding = maxreqs;
847 854
848void 855void
849aio_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)
850 PROTOTYPE: $$$;$
851 PPCODE: 857 PPCODE:
852{ 858{
853 dREQ; 859 dREQ;
854 860
855 req->type = EIO_OPEN; 861 req->type = EIO_OPEN;
861 REQ_SEND; 867 REQ_SEND;
862} 868}
863 869
864void 870void
865aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 871aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
866 PROTOTYPE: $;$
867 ALIAS: 872 ALIAS:
868 aio_fsync = EIO_FSYNC 873 aio_fsync = EIO_FSYNC
869 aio_fdatasync = EIO_FDATASYNC 874 aio_fdatasync = EIO_FDATASYNC
870 PPCODE: 875 PPCODE:
871{ 876{
879 REQ_SEND (req); 884 REQ_SEND (req);
880} 885}
881 886
882void 887void
883aio_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)
884 PROTOTYPE: $$$$;$
885 PPCODE: 889 PPCODE:
886{ 890{
887 int fd = s_fileno_croak (fh, 0); 891 int fd = s_fileno_croak (fh, 0);
888 dREQ; 892 dREQ;
889 893
897 REQ_SEND (req); 901 REQ_SEND (req);
898} 902}
899 903
900void 904void
901aio_close (SV *fh, SV *callback=&PL_sv_undef) 905aio_close (SV *fh, SV *callback=&PL_sv_undef)
902 PROTOTYPE: $;$
903 PPCODE: 906 PPCODE:
904{ 907{
905 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 */
906 int fd = s_fileno_croak (fh, 0); 909 int fd = s_fileno_croak (fh, 0);
907 dREQ; 910 dREQ;
929void 932void
930aio_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)
931 ALIAS: 934 ALIAS:
932 aio_read = EIO_READ 935 aio_read = EIO_READ
933 aio_write = EIO_WRITE 936 aio_write = EIO_WRITE
934 PROTOTYPE: $$$$$;$
935 PPCODE: 937 PPCODE:
936{ 938{
937 STRLEN svlen; 939 STRLEN svlen;
938 int fd = s_fileno_croak (fh, ix == EIO_WRITE); 940 int fd = s_fileno_croak (fh, ix == EIO_WRITE);
939 char *svptr = SvPVbyte (data, svlen); 941 char *svptr = SvPVbyte (data, svlen);
980 } 982 }
981} 983}
982 984
983void 985void
984aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 986aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
985 PROTOTYPE: $$;$
986 PPCODE: 987 PPCODE:
987{ 988{
988 SV *data; 989 SV *data;
989 dREQ; 990 dREQ;
990 991
995 REQ_SEND; 996 REQ_SEND;
996} 997}
997 998
998void 999void
999aio_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)
1000 PROTOTYPE: $$$$;$
1001 PPCODE: 1001 PPCODE:
1002{ 1002{
1003 int ifd = s_fileno_croak (in_fh , 0); 1003 int ifd = s_fileno_croak (in_fh , 0);
1004 int ofd = s_fileno_croak (out_fh, 1); 1004 int ofd = s_fileno_croak (out_fh, 1);
1005 dREQ; 1005 dREQ;
1015 REQ_SEND; 1015 REQ_SEND;
1016} 1016}
1017 1017
1018void 1018void
1019aio_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)
1020 PROTOTYPE: $$$;$
1021 PPCODE: 1020 PPCODE:
1022{ 1021{
1023 int fd = s_fileno_croak (fh, 0); 1022 int fd = s_fileno_croak (fh, 0);
1024 dREQ; 1023 dREQ;
1025 1024
1226void 1225void
1227aio_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)
1228 ALIAS: 1227 ALIAS:
1229 aio_mtouch = EIO_MTOUCH 1228 aio_mtouch = EIO_MTOUCH
1230 aio_msync = EIO_MSYNC 1229 aio_msync = EIO_MSYNC
1231 PROTOTYPE: $$$$;$
1232 PPCODE: 1230 PPCODE:
1233{ 1231{
1234 STRLEN svlen; 1232 STRLEN svlen;
1233 char *svptr = SvPVbyte (data, svlen);
1235 UV len = SvUV (length); 1234 UV len = SvUV (length);
1236 char *svptr = SvPVbyte (data, svlen);
1237 1235
1238 if (offset < 0) 1236 if (offset < 0)
1239 offset += svlen; 1237 offset += svlen;
1240 1238
1241 if (offset < 0 || offset > svlen) 1239 if (offset < 0 || offset > svlen)
1246 1244
1247 { 1245 {
1248 dREQ; 1246 dREQ;
1249 1247
1250 req->type = ix; 1248 req->type = ix;
1251 req->size = len;
1252 req->sv2 = SvREFCNT_inc (data); 1249 req->sv2 = SvREFCNT_inc (data);
1253 req->ptr2 = (char *)svptr + offset; 1250 req->ptr2 = (char *)svptr + offset;
1251 req->size = len;
1254 req->int1 = flags; 1252 req->int1 = flags;
1255 1253
1256 REQ_SEND; 1254 REQ_SEND;
1257 } 1255 }
1258} 1256}
1259 1257
1260void 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
1261aio_busy (double delay, SV *callback=&PL_sv_undef) 1301aio_busy (double delay, SV *callback=&PL_sv_undef)
1262 PPCODE: 1302 PPCODE:
1263{ 1303{
1264 dREQ; 1304 dREQ;
1265 1305
1269 REQ_SEND; 1309 REQ_SEND;
1270} 1310}
1271 1311
1272void 1312void
1273aio_group (SV *callback=&PL_sv_undef) 1313aio_group (SV *callback=&PL_sv_undef)
1274 PROTOTYPE: ;$
1275 PPCODE: 1314 PPCODE:
1276{ 1315{
1277 dREQ; 1316 dREQ;
1278 1317
1279 req->type = EIO_GROUP; 1318 req->type = EIO_GROUP;
1296 REQ_SEND; 1335 REQ_SEND;
1297} 1336}
1298 1337
1299int 1338int
1300aioreq_pri (int pri = 0) 1339aioreq_pri (int pri = 0)
1301 PROTOTYPE: ;$
1302 CODE: 1340 CODE:
1303 RETVAL = next_pri; 1341 RETVAL = next_pri;
1304 if (items > 0) 1342 if (items > 0)
1305 { 1343 {
1306 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; 1344 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN;
1318 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; 1356 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX;
1319 next_pri = nice; 1357 next_pri = nice;
1320 1358
1321void 1359void
1322flush () 1360flush ()
1323 PROTOTYPE:
1324 CODE: 1361 CODE:
1325 while (eio_nreqs ()) 1362 while (eio_nreqs ())
1326 { 1363 {
1327 poll_wait (); 1364 poll_wait ();
1328 poll_cb (); 1365 poll_cb ();
1329 } 1366 }
1330 1367
1331int 1368int
1332poll() 1369poll ()
1333 PROTOTYPE:
1334 CODE: 1370 CODE:
1335 poll_wait (); 1371 poll_wait ();
1336 RETVAL = poll_cb (); 1372 RETVAL = poll_cb ();
1337 OUTPUT: 1373 OUTPUT:
1338 RETVAL 1374 RETVAL
1339 1375
1340int 1376int
1341poll_fileno() 1377poll_fileno ()
1342 PROTOTYPE:
1343 CODE: 1378 CODE:
1344 RETVAL = s_epipe_fd (&respipe); 1379 RETVAL = s_epipe_fd (&respipe);
1345 OUTPUT: 1380 OUTPUT:
1346 RETVAL 1381 RETVAL
1347 1382
1348int 1383int
1349poll_cb(...) 1384poll_cb (...)
1350 PROTOTYPE: 1385 PROTOTYPE:
1351 CODE: 1386 CODE:
1352 RETVAL = poll_cb (); 1387 RETVAL = poll_cb ();
1353 OUTPUT: 1388 OUTPUT:
1354 RETVAL 1389 RETVAL
1355 1390
1356void 1391void
1357poll_wait() 1392poll_wait ()
1358 PROTOTYPE:
1359 CODE: 1393 CODE:
1360 poll_wait (); 1394 poll_wait ();
1361 1395
1362int 1396int
1363nreqs() 1397nreqs ()
1364 PROTOTYPE:
1365 CODE: 1398 CODE:
1366 RETVAL = eio_nreqs (); 1399 RETVAL = eio_nreqs ();
1367 OUTPUT: 1400 OUTPUT:
1368 RETVAL 1401 RETVAL
1369 1402
1370int 1403int
1371nready() 1404nready ()
1372 PROTOTYPE:
1373 CODE: 1405 CODE:
1374 RETVAL = eio_nready (); 1406 RETVAL = eio_nready ();
1375 OUTPUT: 1407 OUTPUT:
1376 RETVAL 1408 RETVAL
1377 1409
1378int 1410int
1379npending() 1411npending ()
1380 PROTOTYPE:
1381 CODE: 1412 CODE:
1382 RETVAL = eio_npending (); 1413 RETVAL = eio_npending ();
1383 OUTPUT: 1414 OUTPUT:
1384 RETVAL 1415 RETVAL
1385 1416
1386int 1417int
1387nthreads() 1418nthreads ()
1388 PROTOTYPE:
1389 CODE: 1419 CODE:
1390 RETVAL = eio_nthreads (); 1420 RETVAL = eio_nthreads ();
1391 OUTPUT: 1421 OUTPUT:
1392 RETVAL 1422 RETVAL
1393 1423
1394int 1424int
1395fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) 1425fadvise (aio_rfd fh, off_t offset, off_t length, IV advice)
1396 PROTOTYPE: $$$$
1397 CODE: 1426 CODE:
1398 RETVAL = posix_fadvise (fh, offset, length, advice); 1427 RETVAL = posix_fadvise (fh, offset, length, advice);
1399 OUTPUT: 1428 OUTPUT:
1400 RETVAL 1429 RETVAL
1401 1430
1402ssize_t 1431ssize_t
1403sendfile (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)
1404 PROTOTYPE: $$$$
1405 CODE: 1433 CODE:
1406 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1434 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1407 OUTPUT: 1435 OUTPUT:
1408 RETVAL 1436 RETVAL
1409 1437
1410void 1438void
1411mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) 1439mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0)
1412 PROTOTYPE: $$$$$;$
1413 PPCODE: 1440 PPCODE:
1414 sv_unmagic (scalar, MMAP_MAGIC); 1441 sv_unmagic (scalar, MMAP_MAGIC);
1415{ 1442{
1416 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; 1443 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1;
1417 void *addr = (void *)mmap (0, length, prot, flags, fd, offset); 1444 void *addr = (void *)mmap (0, length, prot, flags, fd, offset);
1440 XSRETURN_YES; 1467 XSRETURN_YES;
1441} 1468}
1442 1469
1443void 1470void
1444munmap (SV *scalar) 1471munmap (SV *scalar)
1445 PROTOTYPE: $
1446 CODE: 1472 CODE:
1447 sv_unmagic (scalar, MMAP_MAGIC); 1473 sv_unmagic (scalar, MMAP_MAGIC);
1448 1474
1449int 1475int
1450madvise (SV *scalar, off_t offset, off_t length, IV advice) 1476madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
1451 PROTOTYPE: $$$$ 1477 ALIAS:
1478 mprotect = 1
1452 CODE: 1479 CODE:
1453{ 1480{
1454 char *addr = SvPV_nolen (scalar) + offset; 1481 STRLEN svlen;
1482 void *addr = SvPVbyte (scalar, svlen);
1483 size_t len = SvUV (length);
1455 1484
1456 if (!SvOK (ST (2))) 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)
1457 length = SvCUR (scalar) - offset; 1492 len = svlen - offset;
1458 1493
1459 if (addr >= SvEND (scalar) || length <= 0) 1494 addr = (void *)(((intptr_t)addr) + offset);
1460 XSRETURN_EMPTY; 1495 eio_page_align (&addr, &len);
1461 1496
1497 switch (ix)
1498 {
1462 RETVAL = posix_madvise (addr, length, advice); 1499 case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break;
1500 case 1: RETVAL = mprotect (addr, len, advice_or_prot); break;
1501 }
1463} 1502}
1464 OUTPUT: 1503 OUTPUT:
1465 RETVAL 1504 RETVAL
1466 1505
1467int 1506int
1468mlockall (int flags) 1507munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef)
1469 PROTOTYPE: $
1470 CODE: 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);
1471#if _POSIX_MEMLOCK 1525#if _POSIX_MEMLOCK
1472#if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 1526 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 1527#else
1478 RETVAL = -1; 1528 RETVAL = ((errno = ENOSYS), -1);
1479 errno = ENOSYS;
1480#endif 1529#endif
1530}
1481 OUTPUT: 1531 OUTPUT:
1482 RETVAL 1532 RETVAL
1483 1533
1484int 1534int
1485munlockall () 1535munlockall ()
1486 PROTOTYPE:
1487 CODE: 1536 CODE:
1488#if _POSIX_MEMLOCK 1537#if _POSIX_MEMLOCK
1489 munlockall (); 1538 munlockall ();
1490#else 1539#else
1491 RETVAL = -1; 1540 RETVAL = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines