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.168 by root, Wed Aug 4 14:02:58 2010 UTC vs.
Revision 1.181 by root, Tue Feb 15 03:21:41 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
149#ifndef POSIX_MADV_NORMAL
150# define POSIX_MADV_NORMAL 0
151#endif
152#ifndef POSIX_MADV_SEQUENTIAL
153# define POSIX_MADV_SEQUENTIAL 0
154#endif
155#ifndef POSIX_MADV_RANDOM
156# define POSIX_MADV_RANDOM 0
157#endif
158#ifndef POSIX_MADV_WILLNEED
159# define POSIX_MADV_WILLNEED 0
160#endif
161#ifndef POSIX_MADV_DONTNEED
162# define POSIX_MADV_DONTNEED 0
163#endif
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
145#ifndef ST_NODEV 182#ifndef ST_NODEV
146# define ST_NODEV 0 183# define ST_NODEV 0
147#endif 184#endif
148#ifndef ST_NOEXEC 185#ifndef ST_NOEXEC
149# define ST_NOEXEC 0 186# define ST_NOEXEC 0
171#endif 208#endif
172#ifndef ST_RELATIME 209#ifndef ST_RELATIME
173# define ST_RELATIME 0 210# define ST_RELATIME 0
174#endif 211#endif
175 212
176#ifndef MCL_CURRENT 213#ifndef S_IFIFO
177# define MCL_CURRENT 0 214# define S_IFIFO 0
178#endif 215#endif
179#ifndef MCL_FUTURE 216#ifndef S_IFCHR
180# 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
181#endif 236#endif
182 237
183#ifndef MAP_ANONYMOUS 238#ifndef MAP_ANONYMOUS
184# ifdef MAP_ANON 239# ifdef MAP_ANON
185# define MAP_ANONYMOUS MAP_ANON 240# define MAP_ANONYMOUS MAP_ANON
199#ifndef MAP_POPULATE 254#ifndef MAP_POPULATE
200# define MAP_POPULATE 0 255# define MAP_POPULATE 0
201#endif 256#endif
202#ifndef MAP_NONBLOCK 257#ifndef MAP_NONBLOCK
203# 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)
204#endif 269#endif
205 270
206#ifndef PAGESIZE 271#ifndef PAGESIZE
207# define PAGESIZE sysconf (_SC_PAGESIZE) 272# define PAGESIZE sysconf (_SC_PAGESIZE)
208#endif 273#endif
323 /* do not recreate the result IV from scratch each time */ 388 /* do not recreate the result IV from scratch each time */
324 if (expect_true (sv_result_cache)) 389 if (expect_true (sv_result_cache))
325 { 390 {
326 sv_result = sv_result_cache; sv_result_cache = 0; 391 sv_result = sv_result_cache; sv_result_cache = 0;
327 SvIV_set (sv_result, req->result); 392 SvIV_set (sv_result, req->result);
393 SvIOK_only (sv_result);
328 } 394 }
329 else 395 else
330 { 396 {
331 sv_result = newSViv (req->result); 397 sv_result = newSViv (req->result);
332 SvREADONLY_on (sv_result); 398 SvREADONLY_on (sv_result);
496 SvSETMAGIC (req->sv2); 562 SvSETMAGIC (req->sv2);
497 PUSHs (sv_result); 563 PUSHs (sv_result);
498 } 564 }
499 break; 565 break;
500 566
501 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 */
502 if (req->result > 0) 568 if (req->result > 0)
503 SvIV_set (sv_result, 0); 569 SvIV_set (sv_result, 0);
504 /* FALLTHROUGH */ 570 /* FALLTHROUGH */
505 571
506 default: 572 default:
606/*****************************************************************************/ 672/*****************************************************************************/
607 673
608#if !_POSIX_MAPPED_FILES 674#if !_POSIX_MAPPED_FILES
609# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) 675# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1)
610# 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
611#endif 686#endif
612 687
613#define MMAP_MAGIC PERL_MAGIC_ext 688#define MMAP_MAGIC PERL_MAGIC_ext
614 689
615static int 690static int
689 const_iv (O_RDWR) 764 const_iv (O_RDWR)
690 const_iv (O_CREAT) 765 const_iv (O_CREAT)
691 const_iv (O_TRUNC) 766 const_iv (O_TRUNC)
692 const_iv (O_EXCL) 767 const_iv (O_EXCL)
693 const_iv (O_APPEND) 768 const_iv (O_APPEND)
694#ifndef _WIN32 769
695 const_iv (S_IFIFO) 770 const_iv (S_IFIFO)
696#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
697 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) 780 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL)
698 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) 781 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL)
699 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) 782 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM)
700 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) 783 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE)
701 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) 784 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED)
702 const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) 785 const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED)
786
787 const_niv (MADV_NORMAL , POSIX_MADV_NORMAL)
788 const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL)
789 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
790 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
791 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
703 792
704 const_iv (ST_RDONLY) 793 const_iv (ST_RDONLY)
705 const_iv (ST_NOSUID) 794 const_iv (ST_NOSUID)
706 const_iv (ST_NODEV) 795 const_iv (ST_NODEV)
707 const_iv (ST_NOEXEC) 796 const_iv (ST_NOEXEC)
712 const_iv (ST_IMMUTABLE) 801 const_iv (ST_IMMUTABLE)
713 const_iv (ST_NOATIME) 802 const_iv (ST_NOATIME)
714 const_iv (ST_NODIRATIME) 803 const_iv (ST_NODIRATIME)
715 const_iv (ST_RELATIME) 804 const_iv (ST_RELATIME)
716 805
806 const_iv (PROT_NONE)
717 const_iv (PROT_EXEC) 807 const_iv (PROT_EXEC)
718 const_iv (PROT_NONE)
719 const_iv (PROT_READ) 808 const_iv (PROT_READ)
720 const_iv (PROT_WRITE) 809 const_iv (PROT_WRITE)
721 810
722 /*const_iv (MAP_FIXED)*/ 811 /*const_iv (MAP_FIXED)*/
723 const_iv (MAP_PRIVATE) 812 const_iv (MAP_PRIVATE)
729 const_iv (MAP_LOCKED) 818 const_iv (MAP_LOCKED)
730 const_iv (MAP_NORESERVE) 819 const_iv (MAP_NORESERVE)
731 const_iv (MAP_POPULATE) 820 const_iv (MAP_POPULATE)
732 const_iv (MAP_NONBLOCK) 821 const_iv (MAP_NONBLOCK)
733 822
734 const_iv (MCL_FUTURE) 823 const_eio (MCL_FUTURE)
735 const_iv (MCL_CURRENT) 824 const_eio (MCL_CURRENT)
736 825
737 const_eio (MS_ASYNC) 826 const_eio (MS_ASYNC)
738 const_eio (MS_INVALIDATE) 827 const_eio (MS_INVALIDATE)
739 const_eio (MS_SYNC) 828 const_eio (MS_SYNC)
740 829
777 /* atfork child called in fifo order, so before eio's handler */ 866 /* atfork child called in fifo order, so before eio's handler */
778 X_THREAD_ATFORK (0, 0, atfork_child); 867 X_THREAD_ATFORK (0, 0, atfork_child);
779} 868}
780 869
781void 870void
782max_poll_reqs (int nreqs) 871max_poll_reqs (unsigned int nreqs)
783 PROTOTYPE: $ 872 PROTOTYPE: $
784 CODE: 873 CODE:
785 eio_set_max_poll_reqs (nreqs); 874 eio_set_max_poll_reqs (nreqs);
786 875
787void 876void
789 PROTOTYPE: $ 878 PROTOTYPE: $
790 CODE: 879 CODE:
791 eio_set_max_poll_time (nseconds); 880 eio_set_max_poll_time (nseconds);
792 881
793void 882void
794min_parallel (int nthreads) 883min_parallel (unsigned int nthreads)
795 PROTOTYPE: $ 884 PROTOTYPE: $
796 CODE: 885 CODE:
797 eio_set_min_parallel (nthreads); 886 eio_set_min_parallel (nthreads);
798 887
799void 888void
800max_parallel (int nthreads) 889max_parallel (unsigned int nthreads)
801 PROTOTYPE: $ 890 PROTOTYPE: $
802 CODE: 891 CODE:
803 eio_set_max_parallel (nthreads); 892 eio_set_max_parallel (nthreads);
804 893
805void 894void
806max_idle (int nthreads) 895max_idle (unsigned int nthreads)
807 PROTOTYPE: $ 896 PROTOTYPE: $
808 CODE: 897 CODE:
809 eio_set_max_idle (nthreads); 898 eio_set_max_idle (nthreads);
810 899
811void 900void
901idle_timeout (unsigned int seconds)
902 PROTOTYPE: $
903 CODE:
904 eio_set_idle_timeout (seconds);
905
906void
812max_outstanding (int maxreqs) 907max_outstanding (unsigned int maxreqs)
813 PROTOTYPE: $ 908 PROTOTYPE: $
814 CODE: 909 CODE:
815 max_outstanding = maxreqs; 910 max_outstanding = maxreqs;
816 911
817void 912void
818aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 913aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
819 PROTOTYPE: $$$;$
820 PPCODE: 914 PPCODE:
821{ 915{
822 dREQ; 916 dREQ;
823 917
824 req->type = EIO_OPEN; 918 req->type = EIO_OPEN;
830 REQ_SEND; 924 REQ_SEND;
831} 925}
832 926
833void 927void
834aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 928aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
835 PROTOTYPE: $;$
836 ALIAS: 929 ALIAS:
837 aio_fsync = EIO_FSYNC 930 aio_fsync = EIO_FSYNC
838 aio_fdatasync = EIO_FDATASYNC 931 aio_fdatasync = EIO_FDATASYNC
839 PPCODE: 932 PPCODE:
840{ 933{
848 REQ_SEND (req); 941 REQ_SEND (req);
849} 942}
850 943
851void 944void
852aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) 945aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef)
853 PROTOTYPE: $$$$;$
854 PPCODE: 946 PPCODE:
855{ 947{
856 int fd = s_fileno_croak (fh, 0); 948 int fd = s_fileno_croak (fh, 0);
857 dREQ; 949 dREQ;
858 950
866 REQ_SEND (req); 958 REQ_SEND (req);
867} 959}
868 960
869void 961void
870aio_close (SV *fh, SV *callback=&PL_sv_undef) 962aio_close (SV *fh, SV *callback=&PL_sv_undef)
871 PROTOTYPE: $;$
872 PPCODE: 963 PPCODE:
873{ 964{
874 static int close_pipe = -1; /* dummy fd to close fds via dup2 */ 965 static int close_pipe = -1; /* dummy fd to close fds via dup2 */
875 int fd = s_fileno_croak (fh, 0); 966 int fd = s_fileno_croak (fh, 0);
876 dREQ; 967 dREQ;
898void 989void
899aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) 990aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef)
900 ALIAS: 991 ALIAS:
901 aio_read = EIO_READ 992 aio_read = EIO_READ
902 aio_write = EIO_WRITE 993 aio_write = EIO_WRITE
903 PROTOTYPE: $$$$$;$
904 PPCODE: 994 PPCODE:
905{ 995{
906 STRLEN svlen; 996 STRLEN svlen;
907 int fd = s_fileno_croak (fh, ix == EIO_WRITE); 997 int fd = s_fileno_croak (fh, ix == EIO_WRITE);
908 char *svptr = SvPVbyte (data, svlen); 998 char *svptr = SvPVbyte (data, svlen);
949 } 1039 }
950} 1040}
951 1041
952void 1042void
953aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1043aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
954 PROTOTYPE: $$;$
955 PPCODE: 1044 PPCODE:
956{ 1045{
957 SV *data; 1046 SV *data;
958 dREQ; 1047 dREQ;
959 1048
964 REQ_SEND; 1053 REQ_SEND;
965} 1054}
966 1055
967void 1056void
968aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) 1057aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef)
969 PROTOTYPE: $$$$;$
970 PPCODE: 1058 PPCODE:
971{ 1059{
972 int ifd = s_fileno_croak (in_fh , 0); 1060 int ifd = s_fileno_croak (in_fh , 0);
973 int ofd = s_fileno_croak (out_fh, 1); 1061 int ofd = s_fileno_croak (out_fh, 1);
974 dREQ; 1062 dREQ;
984 REQ_SEND; 1072 REQ_SEND;
985} 1073}
986 1074
987void 1075void
988aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) 1076aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef)
989 PROTOTYPE: $$$;$
990 PPCODE: 1077 PPCODE:
991{ 1078{
992 int fd = s_fileno_croak (fh, 0); 1079 int fd = s_fileno_croak (fh, 0);
993 dREQ; 1080 dREQ;
994 1081
1025 } 1112 }
1026 1113
1027 REQ_SEND; 1114 REQ_SEND;
1028} 1115}
1029 1116
1117UV
1118major (UV dev)
1119 ALIAS:
1120 minor = 1
1121 CODE:
1122 RETVAL = ix ? major (dev) : minor (dev);
1123 OUTPUT:
1124 RETVAL
1125
1126UV
1127makedev (UV maj, UV min)
1128 CODE:
1129 RETVAL = makedev (maj, min);
1130 OUTPUT:
1131 RETVAL
1132
1030void 1133void
1031aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) 1134aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef)
1032 PPCODE: 1135 PPCODE:
1033{ 1136{
1034 dREQ; 1137 dREQ;
1195void 1298void
1196aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) 1299aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef)
1197 ALIAS: 1300 ALIAS:
1198 aio_mtouch = EIO_MTOUCH 1301 aio_mtouch = EIO_MTOUCH
1199 aio_msync = EIO_MSYNC 1302 aio_msync = EIO_MSYNC
1200 PROTOTYPE: $$$$;$
1201 PPCODE: 1303 PPCODE:
1202{ 1304{
1203 STRLEN svlen; 1305 STRLEN svlen;
1306 char *svptr = SvPVbyte (data, svlen);
1204 UV len = SvUV (length); 1307 UV len = SvUV (length);
1205 char *svptr = SvPVbyte (data, svlen);
1206 1308
1207 if (offset < 0) 1309 if (offset < 0)
1208 offset += svlen; 1310 offset += svlen;
1209 1311
1210 if (offset < 0 || offset > svlen) 1312 if (offset < 0 || offset > svlen)
1215 1317
1216 { 1318 {
1217 dREQ; 1319 dREQ;
1218 1320
1219 req->type = ix; 1321 req->type = ix;
1220 req->size = len;
1221 req->sv2 = SvREFCNT_inc (data); 1322 req->sv2 = SvREFCNT_inc (data);
1222 req->ptr2 = (char *)svptr + offset; 1323 req->ptr2 = (char *)svptr + offset;
1324 req->size = len;
1223 req->int1 = flags; 1325 req->int1 = flags;
1224 1326
1225 REQ_SEND; 1327 REQ_SEND;
1226 } 1328 }
1227} 1329}
1228 1330
1229void 1331void
1332aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef)
1333 PPCODE:
1334{
1335 STRLEN svlen;
1336 char *svptr = SvPVbyte (data, svlen);
1337 UV len = SvUV (length);
1338
1339 if (offset < 0)
1340 offset += svlen;
1341
1342 if (offset < 0 || offset > svlen)
1343 croak ("offset outside of scalar");
1344
1345 if (!SvOK (length) || len + offset > svlen)
1346 len = svlen - offset;
1347
1348 {
1349 dREQ;
1350
1351 req->type = EIO_MLOCK;
1352 req->sv2 = SvREFCNT_inc (data);
1353 req->ptr2 = (char *)svptr + offset;
1354 req->size = len;
1355
1356 REQ_SEND;
1357 }
1358}
1359
1360void
1361aio_mlockall (IV flags, SV *callback=&PL_sv_undef)
1362 PPCODE:
1363{
1364 dREQ;
1365
1366 req->type = EIO_MLOCKALL;
1367 req->int1 = flags;
1368
1369 REQ_SEND;
1370}
1371
1372void
1230aio_busy (double delay, SV *callback=&PL_sv_undef) 1373aio_busy (double delay, SV *callback=&PL_sv_undef)
1231 PPCODE: 1374 PPCODE:
1232{ 1375{
1233 dREQ; 1376 dREQ;
1234 1377
1238 REQ_SEND; 1381 REQ_SEND;
1239} 1382}
1240 1383
1241void 1384void
1242aio_group (SV *callback=&PL_sv_undef) 1385aio_group (SV *callback=&PL_sv_undef)
1243 PROTOTYPE: ;$
1244 PPCODE: 1386 PPCODE:
1245{ 1387{
1246 dREQ; 1388 dREQ;
1247 1389
1248 req->type = EIO_GROUP; 1390 req->type = EIO_GROUP;
1265 REQ_SEND; 1407 REQ_SEND;
1266} 1408}
1267 1409
1268int 1410int
1269aioreq_pri (int pri = 0) 1411aioreq_pri (int pri = 0)
1270 PROTOTYPE: ;$
1271 CODE: 1412 CODE:
1272 RETVAL = next_pri; 1413 RETVAL = next_pri;
1273 if (items > 0) 1414 if (items > 0)
1274 { 1415 {
1275 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; 1416 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN;
1287 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; 1428 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX;
1288 next_pri = nice; 1429 next_pri = nice;
1289 1430
1290void 1431void
1291flush () 1432flush ()
1292 PROTOTYPE:
1293 CODE: 1433 CODE:
1294 while (eio_nreqs ()) 1434 while (eio_nreqs ())
1295 { 1435 {
1296 poll_wait (); 1436 poll_wait ();
1297 poll_cb (); 1437 poll_cb ();
1298 } 1438 }
1299 1439
1300int 1440int
1301poll() 1441poll ()
1302 PROTOTYPE:
1303 CODE: 1442 CODE:
1304 poll_wait (); 1443 poll_wait ();
1305 RETVAL = poll_cb (); 1444 RETVAL = poll_cb ();
1306 OUTPUT: 1445 OUTPUT:
1307 RETVAL 1446 RETVAL
1308 1447
1309int 1448int
1310poll_fileno() 1449poll_fileno ()
1311 PROTOTYPE:
1312 CODE: 1450 CODE:
1313 RETVAL = s_epipe_fd (&respipe); 1451 RETVAL = s_epipe_fd (&respipe);
1314 OUTPUT: 1452 OUTPUT:
1315 RETVAL 1453 RETVAL
1316 1454
1317int 1455int
1318poll_cb(...) 1456poll_cb (...)
1319 PROTOTYPE: 1457 PROTOTYPE:
1320 CODE: 1458 CODE:
1321 RETVAL = poll_cb (); 1459 RETVAL = poll_cb ();
1322 OUTPUT: 1460 OUTPUT:
1323 RETVAL 1461 RETVAL
1324 1462
1325void 1463void
1326poll_wait() 1464poll_wait ()
1327 PROTOTYPE:
1328 CODE: 1465 CODE:
1329 poll_wait (); 1466 poll_wait ();
1330 1467
1331int 1468int
1332nreqs() 1469nreqs ()
1333 PROTOTYPE:
1334 CODE: 1470 CODE:
1335 RETVAL = eio_nreqs (); 1471 RETVAL = eio_nreqs ();
1336 OUTPUT: 1472 OUTPUT:
1337 RETVAL 1473 RETVAL
1338 1474
1339int 1475int
1340nready() 1476nready ()
1341 PROTOTYPE:
1342 CODE: 1477 CODE:
1343 RETVAL = eio_nready (); 1478 RETVAL = eio_nready ();
1344 OUTPUT: 1479 OUTPUT:
1345 RETVAL 1480 RETVAL
1346 1481
1347int 1482int
1348npending() 1483npending ()
1349 PROTOTYPE:
1350 CODE: 1484 CODE:
1351 RETVAL = eio_npending (); 1485 RETVAL = eio_npending ();
1352 OUTPUT: 1486 OUTPUT:
1353 RETVAL 1487 RETVAL
1354 1488
1355int 1489int
1356nthreads() 1490nthreads ()
1357 PROTOTYPE:
1358 CODE: 1491 CODE:
1359 RETVAL = eio_nthreads (); 1492 RETVAL = eio_nthreads ();
1360 OUTPUT: 1493 OUTPUT:
1361 RETVAL 1494 RETVAL
1362 1495
1363int 1496int
1364fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) 1497fadvise (aio_rfd fh, off_t offset, off_t length, IV advice)
1365 PROTOTYPE: $$$$
1366 CODE: 1498 CODE:
1367#if _XOPEN_SOURCE >= 600 && !NO_FADVISE
1368 RETVAL = posix_fadvise (fh, offset, length, advice); 1499 RETVAL = posix_fadvise (fh, offset, length, advice);
1369#else
1370 RETVAL = errno = ENOSYS; /* yes, this is actually correct */
1371#endif
1372 OUTPUT: 1500 OUTPUT:
1373 RETVAL 1501 RETVAL
1374 1502
1375ssize_t 1503ssize_t
1376sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1504sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1377 PROTOTYPE: $$$$
1378 CODE: 1505 CODE:
1379 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1506 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1380 OUTPUT: 1507 OUTPUT:
1381 RETVAL 1508 RETVAL
1382 1509
1383void 1510void
1384mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) 1511mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0)
1385 PROTOTYPE: $$$$$;$
1386 PPCODE: 1512 PPCODE:
1387 sv_unmagic (scalar, MMAP_MAGIC); 1513 sv_unmagic (scalar, MMAP_MAGIC);
1388{ 1514{
1389 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; 1515 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1;
1390 void *addr = (void *)mmap (0, length, prot, flags, fd, offset); 1516 void *addr = (void *)mmap (0, length, prot, flags, fd, offset);
1413 XSRETURN_YES; 1539 XSRETURN_YES;
1414} 1540}
1415 1541
1416void 1542void
1417munmap (SV *scalar) 1543munmap (SV *scalar)
1418 PROTOTYPE: $
1419 CODE: 1544 CODE:
1420 sv_unmagic (scalar, MMAP_MAGIC); 1545 sv_unmagic (scalar, MMAP_MAGIC);
1421 1546
1422int 1547int
1423mlockall (int flags) 1548madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
1424 PROTOTYPE: $ 1549 ALIAS:
1550 mprotect = 1
1425 CODE: 1551 CODE:
1552{
1553 STRLEN svlen;
1554 void *addr = SvPVbyte (scalar, svlen);
1555 size_t len = SvUV (length);
1556
1557 if (offset < 0)
1558 offset += svlen;
1559
1560 if (offset < 0 || offset > svlen)
1561 croak ("offset outside of scalar");
1562
1563 if (!SvOK (length) || len + offset > svlen)
1564 len = svlen - offset;
1565
1566 addr = (void *)(((intptr_t)addr) + offset);
1567 eio_page_align (&addr, &len);
1568
1569 switch (ix)
1570 {
1571 case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break;
1572 case 1: RETVAL = mprotect (addr, len, advice_or_prot); break;
1573 }
1574}
1575 OUTPUT:
1576 RETVAL
1577
1578int
1579munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef)
1580 CODE:
1581{
1582 STRLEN svlen;
1583 void *addr = SvPVbyte (scalar, svlen);
1584 size_t len = SvUV (length);
1585
1586 if (offset < 0)
1587 offset += svlen;
1588
1589 if (offset < 0 || offset > svlen)
1590 croak ("offset outside of scalar");
1591
1592 if (!SvOK (length) || len + offset > svlen)
1593 len = svlen - offset;
1594
1595 addr = (void *)(((intptr_t)addr) + offset);
1596 eio_page_align (&addr, &len);
1426#if _POSIX_MEMLOCK 1597#if _POSIX_MEMLOCK_RANGE
1427#if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 1598 RETVAL = munlock (addr, len);
1428 extern int mallopt (int, int);
1429 mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */
1430#endif
1431 mlockall (flags);
1432#else 1599#else
1433 RETVAL = -1; 1600 RETVAL = ((errno = ENOSYS), -1);
1434 errno = ENOSYS;
1435#endif 1601#endif
1602}
1436 OUTPUT: 1603 OUTPUT:
1437 RETVAL 1604 RETVAL
1438 1605
1439int 1606int
1440munlockall () 1607munlockall ()
1441 PROTOTYPE:
1442 CODE: 1608 CODE:
1443#if _POSIX_MEMLOCK 1609#if _POSIX_MEMLOCK
1444 munlockall (); 1610 munlockall ();
1445#else 1611#else
1446 RETVAL = -1; 1612 RETVAL = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines