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.173 by root, Mon Sep 13 01:59:05 2010 UTC

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
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 151# define NO_MADVISE 1
148#endif 152#endif
149#ifndef POSIX_MADV_SEQUENTIAL 153#ifndef POSIX_MADV_SEQUENTIAL
157#endif 161#endif
158#ifndef POSIX_MADV_DONTNEED 162#ifndef POSIX_MADV_DONTNEED
159# define POSIX_MADV_DONTNEED 0 163# define POSIX_MADV_DONTNEED 0
160#endif 164#endif
161 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
162#ifndef ST_NODEV 183#ifndef ST_NODEV
163# define ST_NODEV 0 184# define ST_NODEV 0
164#endif 185#endif
165#ifndef ST_NOEXEC 186#ifndef ST_NOEXEC
166# define ST_NOEXEC 0 187# define ST_NOEXEC 0
186#ifndef ST_NODIRATIME 207#ifndef ST_NODIRATIME
187# define ST_NODIRATIME 0 208# define ST_NODIRATIME 0
188#endif 209#endif
189#ifndef ST_RELATIME 210#ifndef ST_RELATIME
190# define ST_RELATIME 0 211# 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 212#endif
199 213
200#ifndef MAP_ANONYMOUS 214#ifndef MAP_ANONYMOUS
201# ifdef MAP_ANON 215# ifdef MAP_ANON
202# define MAP_ANONYMOUS MAP_ANON 216# define MAP_ANONYMOUS MAP_ANON
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# define mprotect(addr,len,prot) (errno = ENOSYS, -1)
628#endif 643#endif
629 644
630#define MMAP_MAGIC PERL_MAGIC_ext 645#define MMAP_MAGIC PERL_MAGIC_ext
631 646
632static int 647static int
735 const_iv (ST_IMMUTABLE) 750 const_iv (ST_IMMUTABLE)
736 const_iv (ST_NOATIME) 751 const_iv (ST_NOATIME)
737 const_iv (ST_NODIRATIME) 752 const_iv (ST_NODIRATIME)
738 const_iv (ST_RELATIME) 753 const_iv (ST_RELATIME)
739 754
755 const_iv (PROT_NONE)
740 const_iv (PROT_EXEC) 756 const_iv (PROT_EXEC)
741 const_iv (PROT_NONE)
742 const_iv (PROT_READ) 757 const_iv (PROT_READ)
743 const_iv (PROT_WRITE) 758 const_iv (PROT_WRITE)
744 759
745 /*const_iv (MAP_FIXED)*/ 760 /*const_iv (MAP_FIXED)*/
746 const_iv (MAP_PRIVATE) 761 const_iv (MAP_PRIVATE)
752 const_iv (MAP_LOCKED) 767 const_iv (MAP_LOCKED)
753 const_iv (MAP_NORESERVE) 768 const_iv (MAP_NORESERVE)
754 const_iv (MAP_POPULATE) 769 const_iv (MAP_POPULATE)
755 const_iv (MAP_NONBLOCK) 770 const_iv (MAP_NONBLOCK)
756 771
757 const_iv (MCL_FUTURE) 772 const_eio (MCL_FUTURE)
758 const_iv (MCL_CURRENT) 773 const_eio (MCL_CURRENT)
759 774
760 const_eio (MS_ASYNC) 775 const_eio (MS_ASYNC)
761 const_eio (MS_INVALIDATE) 776 const_eio (MS_INVALIDATE)
762 const_eio (MS_SYNC) 777 const_eio (MS_SYNC)
763 778
837 CODE: 852 CODE:
838 max_outstanding = maxreqs; 853 max_outstanding = maxreqs;
839 854
840void 855void
841aio_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)
842 PROTOTYPE: $$$;$
843 PPCODE: 857 PPCODE:
844{ 858{
845 dREQ; 859 dREQ;
846 860
847 req->type = EIO_OPEN; 861 req->type = EIO_OPEN;
853 REQ_SEND; 867 REQ_SEND;
854} 868}
855 869
856void 870void
857aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 871aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
858 PROTOTYPE: $;$
859 ALIAS: 872 ALIAS:
860 aio_fsync = EIO_FSYNC 873 aio_fsync = EIO_FSYNC
861 aio_fdatasync = EIO_FDATASYNC 874 aio_fdatasync = EIO_FDATASYNC
862 PPCODE: 875 PPCODE:
863{ 876{
871 REQ_SEND (req); 884 REQ_SEND (req);
872} 885}
873 886
874void 887void
875aio_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)
876 PROTOTYPE: $$$$;$
877 PPCODE: 889 PPCODE:
878{ 890{
879 int fd = s_fileno_croak (fh, 0); 891 int fd = s_fileno_croak (fh, 0);
880 dREQ; 892 dREQ;
881 893
889 REQ_SEND (req); 901 REQ_SEND (req);
890} 902}
891 903
892void 904void
893aio_close (SV *fh, SV *callback=&PL_sv_undef) 905aio_close (SV *fh, SV *callback=&PL_sv_undef)
894 PROTOTYPE: $;$
895 PPCODE: 906 PPCODE:
896{ 907{
897 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 */
898 int fd = s_fileno_croak (fh, 0); 909 int fd = s_fileno_croak (fh, 0);
899 dREQ; 910 dREQ;
921void 932void
922aio_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)
923 ALIAS: 934 ALIAS:
924 aio_read = EIO_READ 935 aio_read = EIO_READ
925 aio_write = EIO_WRITE 936 aio_write = EIO_WRITE
926 PROTOTYPE: $$$$$;$
927 PPCODE: 937 PPCODE:
928{ 938{
929 STRLEN svlen; 939 STRLEN svlen;
930 int fd = s_fileno_croak (fh, ix == EIO_WRITE); 940 int fd = s_fileno_croak (fh, ix == EIO_WRITE);
931 char *svptr = SvPVbyte (data, svlen); 941 char *svptr = SvPVbyte (data, svlen);
972 } 982 }
973} 983}
974 984
975void 985void
976aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 986aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
977 PROTOTYPE: $$;$
978 PPCODE: 987 PPCODE:
979{ 988{
980 SV *data; 989 SV *data;
981 dREQ; 990 dREQ;
982 991
987 REQ_SEND; 996 REQ_SEND;
988} 997}
989 998
990void 999void
991aio_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)
992 PROTOTYPE: $$$$;$
993 PPCODE: 1001 PPCODE:
994{ 1002{
995 int ifd = s_fileno_croak (in_fh , 0); 1003 int ifd = s_fileno_croak (in_fh , 0);
996 int ofd = s_fileno_croak (out_fh, 1); 1004 int ofd = s_fileno_croak (out_fh, 1);
997 dREQ; 1005 dREQ;
1007 REQ_SEND; 1015 REQ_SEND;
1008} 1016}
1009 1017
1010void 1018void
1011aio_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)
1012 PROTOTYPE: $$$;$
1013 PPCODE: 1020 PPCODE:
1014{ 1021{
1015 int fd = s_fileno_croak (fh, 0); 1022 int fd = s_fileno_croak (fh, 0);
1016 dREQ; 1023 dREQ;
1017 1024
1218void 1225void
1219aio_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)
1220 ALIAS: 1227 ALIAS:
1221 aio_mtouch = EIO_MTOUCH 1228 aio_mtouch = EIO_MTOUCH
1222 aio_msync = EIO_MSYNC 1229 aio_msync = EIO_MSYNC
1223 PROTOTYPE: $$$$;$
1224 PPCODE: 1230 PPCODE:
1225{ 1231{
1226 STRLEN svlen; 1232 STRLEN svlen;
1233 char *svptr = SvPVbyte (data, svlen);
1227 UV len = SvUV (length); 1234 UV len = SvUV (length);
1228 char *svptr = SvPVbyte (data, svlen);
1229 1235
1230 if (offset < 0) 1236 if (offset < 0)
1231 offset += svlen; 1237 offset += svlen;
1232 1238
1233 if (offset < 0 || offset > svlen) 1239 if (offset < 0 || offset > svlen)
1238 1244
1239 { 1245 {
1240 dREQ; 1246 dREQ;
1241 1247
1242 req->type = ix; 1248 req->type = ix;
1243 req->size = len;
1244 req->sv2 = SvREFCNT_inc (data); 1249 req->sv2 = SvREFCNT_inc (data);
1245 req->ptr2 = (char *)svptr + offset; 1250 req->ptr2 = (char *)svptr + offset;
1251 req->size = len;
1246 req->int1 = flags; 1252 req->int1 = flags;
1247 1253
1248 REQ_SEND; 1254 REQ_SEND;
1249 } 1255 }
1250} 1256}
1251 1257
1252void 1258void
1259aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef)
1260 PPCODE:
1261{
1262 STRLEN svlen;
1263 char *svptr = SvPVbyte (data, svlen);
1264 UV len = SvUV (length);
1265
1266 if (offset < 0)
1267 offset += svlen;
1268
1269 if (offset < 0 || offset > svlen)
1270 croak ("offset outside of scalar");
1271
1272 if (!SvOK (length) || len + offset > svlen)
1273 len = svlen - offset;
1274
1275 {
1276 dREQ;
1277
1278 req->type = EIO_MLOCK;
1279 req->sv2 = SvREFCNT_inc (data);
1280 req->ptr2 = (char *)svptr + offset;
1281 req->size = len;
1282
1283 REQ_SEND;
1284 }
1285}
1286
1287void
1288aio_mlockall (IV flags, SV *callback=&PL_sv_undef)
1289 PPCODE:
1290{
1291 dREQ;
1292
1293 req->type = EIO_MLOCKALL;
1294 req->int1 = flags;
1295
1296 REQ_SEND;
1297}
1298
1299void
1253aio_busy (double delay, SV *callback=&PL_sv_undef) 1300aio_busy (double delay, SV *callback=&PL_sv_undef)
1254 PPCODE: 1301 PPCODE:
1255{ 1302{
1256 dREQ; 1303 dREQ;
1257 1304
1261 REQ_SEND; 1308 REQ_SEND;
1262} 1309}
1263 1310
1264void 1311void
1265aio_group (SV *callback=&PL_sv_undef) 1312aio_group (SV *callback=&PL_sv_undef)
1266 PROTOTYPE: ;$
1267 PPCODE: 1313 PPCODE:
1268{ 1314{
1269 dREQ; 1315 dREQ;
1270 1316
1271 req->type = EIO_GROUP; 1317 req->type = EIO_GROUP;
1288 REQ_SEND; 1334 REQ_SEND;
1289} 1335}
1290 1336
1291int 1337int
1292aioreq_pri (int pri = 0) 1338aioreq_pri (int pri = 0)
1293 PROTOTYPE: ;$
1294 CODE: 1339 CODE:
1295 RETVAL = next_pri; 1340 RETVAL = next_pri;
1296 if (items > 0) 1341 if (items > 0)
1297 { 1342 {
1298 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; 1343 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN;
1310 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; 1355 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX;
1311 next_pri = nice; 1356 next_pri = nice;
1312 1357
1313void 1358void
1314flush () 1359flush ()
1315 PROTOTYPE:
1316 CODE: 1360 CODE:
1317 while (eio_nreqs ()) 1361 while (eio_nreqs ())
1318 { 1362 {
1319 poll_wait (); 1363 poll_wait ();
1320 poll_cb (); 1364 poll_cb ();
1321 } 1365 }
1322 1366
1323int 1367int
1324poll() 1368poll ()
1325 PROTOTYPE:
1326 CODE: 1369 CODE:
1327 poll_wait (); 1370 poll_wait ();
1328 RETVAL = poll_cb (); 1371 RETVAL = poll_cb ();
1329 OUTPUT: 1372 OUTPUT:
1330 RETVAL 1373 RETVAL
1331 1374
1332int 1375int
1333poll_fileno() 1376poll_fileno ()
1334 PROTOTYPE:
1335 CODE: 1377 CODE:
1336 RETVAL = s_epipe_fd (&respipe); 1378 RETVAL = s_epipe_fd (&respipe);
1337 OUTPUT: 1379 OUTPUT:
1338 RETVAL 1380 RETVAL
1339 1381
1340int 1382int
1341poll_cb(...) 1383poll_cb (...)
1342 PROTOTYPE: 1384 PROTOTYPE:
1343 CODE: 1385 CODE:
1344 RETVAL = poll_cb (); 1386 RETVAL = poll_cb ();
1345 OUTPUT: 1387 OUTPUT:
1346 RETVAL 1388 RETVAL
1347 1389
1348void 1390void
1349poll_wait() 1391poll_wait ()
1350 PROTOTYPE:
1351 CODE: 1392 CODE:
1352 poll_wait (); 1393 poll_wait ();
1353 1394
1354int 1395int
1355nreqs() 1396nreqs ()
1356 PROTOTYPE:
1357 CODE: 1397 CODE:
1358 RETVAL = eio_nreqs (); 1398 RETVAL = eio_nreqs ();
1359 OUTPUT: 1399 OUTPUT:
1360 RETVAL 1400 RETVAL
1361 1401
1362int 1402int
1363nready() 1403nready ()
1364 PROTOTYPE:
1365 CODE: 1404 CODE:
1366 RETVAL = eio_nready (); 1405 RETVAL = eio_nready ();
1367 OUTPUT: 1406 OUTPUT:
1368 RETVAL 1407 RETVAL
1369 1408
1370int 1409int
1371npending() 1410npending ()
1372 PROTOTYPE:
1373 CODE: 1411 CODE:
1374 RETVAL = eio_npending (); 1412 RETVAL = eio_npending ();
1375 OUTPUT: 1413 OUTPUT:
1376 RETVAL 1414 RETVAL
1377 1415
1378int 1416int
1379nthreads() 1417nthreads ()
1380 PROTOTYPE:
1381 CODE: 1418 CODE:
1382 RETVAL = eio_nthreads (); 1419 RETVAL = eio_nthreads ();
1383 OUTPUT: 1420 OUTPUT:
1384 RETVAL 1421 RETVAL
1385 1422
1386int 1423int
1387fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) 1424fadvise (aio_rfd fh, off_t offset, off_t length, IV advice)
1388 PROTOTYPE: $$$$
1389 CODE: 1425 CODE:
1390#if _XOPEN_SOURCE >= 600 && !NO_FADVISE
1391 RETVAL = posix_fadvise (fh, offset, length, advice); 1426 RETVAL = posix_fadvise (fh, offset, length, advice);
1392#else
1393 RETVAL = errno = ENOSYS; /* yes, this is actually correct */
1394#endif
1395 OUTPUT: 1427 OUTPUT:
1396 RETVAL 1428 RETVAL
1397 1429
1398ssize_t 1430ssize_t
1399sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1431sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1400 PROTOTYPE: $$$$
1401 CODE: 1432 CODE:
1402 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1433 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1403 OUTPUT: 1434 OUTPUT:
1404 RETVAL 1435 RETVAL
1405 1436
1406void 1437void
1407mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) 1438mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0)
1408 PROTOTYPE: $$$$$;$
1409 PPCODE: 1439 PPCODE:
1410 sv_unmagic (scalar, MMAP_MAGIC); 1440 sv_unmagic (scalar, MMAP_MAGIC);
1411{ 1441{
1412 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; 1442 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1;
1413 void *addr = (void *)mmap (0, length, prot, flags, fd, offset); 1443 void *addr = (void *)mmap (0, length, prot, flags, fd, offset);
1436 XSRETURN_YES; 1466 XSRETURN_YES;
1437} 1467}
1438 1468
1439void 1469void
1440munmap (SV *scalar) 1470munmap (SV *scalar)
1441 PROTOTYPE: $
1442 CODE: 1471 CODE:
1443 sv_unmagic (scalar, MMAP_MAGIC); 1472 sv_unmagic (scalar, MMAP_MAGIC);
1444 1473
1445int 1474int
1446madvise (SV *scalar, off_t offset, off_t length, IV advice) 1475madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
1447 PROTOTYPE: $$$$ 1476 ALIAS:
1477 mprotect = 1
1448 CODE: 1478 CODE:
1449{ 1479{
1450 char *addr = SvPV_nolen (scalar) + offset; 1480 STRLEN svlen;
1481 void *addr = SvPVbyte (scalar, svlen);
1482 size_t len = SvUV (length);
1451 1483
1452 if (!SvOK (ST (2))) 1484 if (offset < 0)
1485 offset += svlen;
1486
1487 if (offset < 0 || offset > svlen)
1488 croak ("offset outside of scalar");
1489
1490 if (!SvOK (length) || len + offset > svlen)
1453 length = SvCUR (scalar) - offset; 1491 len = svlen - offset;
1454 1492
1455 if (addr >= SvEND (scalar) || length <= 0) 1493 addr = (void *)(((intptr_t)addr) + offset);
1456 XSRETURN_EMPTY; 1494 eio_page_align (&addr, &len);
1457 1495
1458 #if _XOPEN_SOURCE >= 600 && !NO_MADVISE 1496 switch (ix)
1497 {
1459 RETVAL = posix_madvise (addr, length, advice); 1498 case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break;
1460 #else 1499 case 1: RETVAL = mprotect (addr, len, advice_or_prot); break;
1461 RETVAL = errno = ENOSYS; /* yes, this is actually correct */ 1500 }
1462 #endif
1463} 1501}
1464 OUTPUT: 1502 OUTPUT:
1465 RETVAL 1503 RETVAL
1466 1504
1467int 1505int
1468mlockall (int flags) 1506munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef)
1469 PROTOTYPE: $
1470 CODE: 1507 CODE:
1508{
1509 STRLEN svlen;
1510 void *addr = SvPVbyte (scalar, svlen);
1511 size_t len = SvUV (length);
1512
1513 if (offset < 0)
1514 offset += svlen;
1515
1516 if (offset < 0 || offset > svlen)
1517 croak ("offset outside of scalar");
1518
1519 if (!SvOK (length) || len + offset > svlen)
1520 len = svlen - offset;
1521
1522 addr = (void *)(((intptr_t)addr) + offset);
1523 eio_page_align (&addr, &len);
1471#if _POSIX_MEMLOCK 1524#if _POSIX_MEMLOCK
1472#if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 1525 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 1526#else
1478 RETVAL = -1; 1527 RETVAL = ((errno = ENOSYS), -1);
1479 errno = ENOSYS;
1480#endif 1528#endif
1529}
1481 OUTPUT: 1530 OUTPUT:
1482 RETVAL 1531 RETVAL
1483 1532
1484int 1533int
1485munlockall () 1534munlockall ()
1486 PROTOTYPE:
1487 CODE: 1535 CODE:
1488#if _POSIX_MEMLOCK 1536#if _POSIX_MEMLOCK
1489 munlockall (); 1537 munlockall ();
1490#else 1538#else
1491 RETVAL = -1; 1539 RETVAL = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines