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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines