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.177 by root, Thu Dec 30 07:19:31 2010 UTC vs.
Revision 1.186 by root, Thu Jul 14 22:36:17 2011 UTC

11#include <stddef.h> 11#include <stddef.h>
12#include <stdlib.h> 12#include <stdlib.h>
13#include <errno.h> 13#include <errno.h>
14#include <sys/types.h> 14#include <sys/types.h>
15#include <sys/stat.h> 15#include <sys/stat.h>
16#include <sys/statvfs.h>
17#include <limits.h> 16#include <limits.h>
18#include <fcntl.h> 17#include <fcntl.h>
19#include <sched.h> 18#include <sched.h>
20 19
21#if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES 20#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
22# include <sys/mman.h> 21# include <sys/mman.h>
23#endif 22#endif
24 23
25/* perl namespace pollution */ 24/* perl namespace pollution */
26#undef VERSION 25#undef VERSION
47# undef unlink 46# undef unlink
48# undef rmdir 47# undef rmdir
49# undef rename 48# undef rename
50# undef lseek 49# undef lseek
51 50
52# define chown(a,b,c) (errno = ENOSYS, -1)
53# define fchown(a,b,c) (errno = ENOSYS, -1)
54# define fchmod(a,b) (errno = ENOSYS, -1)
55# define symlink(a,b) (errno = ENOSYS, -1)
56# define readlink(a,b,c) (errno = ENOSYS, -1)
57# define mknod(a,b,c) (errno = ENOSYS, -1)
58# define truncate(a,b) (errno = ENOSYS, -1)
59# define ftruncate(fd,o) chsize ((fd), (o))
60# define fsync(fd) _commit (fd)
61# define opendir(fd) (errno = ENOSYS, 0) 51# define opendir(fd) (errno = ENOSYS, 0)
62# define readdir(fd) (errno = ENOSYS, -1) 52# define readdir(fd) (errno = ENOSYS, -1)
63# define closedir(fd) (errno = ENOSYS, -1) 53# define closedir(fd) (errno = ENOSYS, -1)
64# define mkdir(a,b) mkdir (a)
65 54
66#else 55#else
67 56
68# include <sys/time.h> 57# include <sys/time.h>
69# include <sys/select.h> 58# include <sys/select.h>
121#define EIO_NO_WRAPPERS 1 110#define EIO_NO_WRAPPERS 1
122 111
123#include "libeio/config.h" 112#include "libeio/config.h"
124#include "libeio/eio.h" 113#include "libeio/eio.h"
125 114
115/* Linux/others */
116#ifndef O_ASYNC
117# define O_ASYNC 0
118#endif
119#ifndef O_DIRECT
120# define O_DIRECT 0
121#endif
122#ifndef O_NOATIME
123# define O_NOATIME 0
124#endif
125
126/* POSIX */
127#ifndef O_CLOEXEC
128# define O_CLOEXEC 0
129#endif
130#ifndef O_NOFOLLOW
131# define O_NOFOLLOW 0
132#endif
133#ifndef O_NOCTTY
134# define O_NOCTTY 0
135#endif
136#ifndef O_NONBLOCK
137# define O_NONBLOCK 0
138#endif
139#ifndef O_EXEC
140# define O_EXEC 0
141#endif
142#ifndef O_SEARCH
143# define O_SEARCH 0
144#endif
145#ifndef O_DIRECTORY
146# define O_DIRECTORY 0
147#endif
148#ifndef O_DSYNC
149# define O_DSYNC 0
150#endif
151#ifndef O_RSYNC
152# define O_RSYNC 0
153#endif
154#ifndef O_SYNC
155# define O_SYNC 0
156#endif
157#ifndef O_TTY_INIT
158# define O_TTY_INIT 0
159#endif
160
126#ifndef POSIX_FADV_NORMAL 161#ifndef POSIX_FADV_NORMAL
127# define POSIX_FADV_NORMAL 0 162# define POSIX_FADV_NORMAL 0
128#endif 163#endif
129#ifndef POSIX_FADV_SEQUENTIAL 164#ifndef POSIX_FADV_SEQUENTIAL
130# define POSIX_FADV_SEQUENTIAL 0 165# define POSIX_FADV_SEQUENTIAL 0
206#ifndef ST_NODIRATIME 241#ifndef ST_NODIRATIME
207# define ST_NODIRATIME 0 242# define ST_NODIRATIME 0
208#endif 243#endif
209#ifndef ST_RELATIME 244#ifndef ST_RELATIME
210# define ST_RELATIME 0 245# define ST_RELATIME 0
246#endif
247
248#ifndef S_IFIFO
249# define S_IFIFO 0
250#endif
251#ifndef S_IFCHR
252# define S_IFCHR 0
253#endif
254#ifndef S_IFBLK
255# define S_IFBLK 0
256#endif
257#ifndef S_IFLNK
258# define S_IFLNK 0
259#endif
260#ifndef S_IFREG
261# define S_IFREG 0
262#endif
263#ifndef S_IFDIR
264# define S_IFDIR 0
265#endif
266#ifndef S_IFWHT
267# define S_IFWHT 0
268#endif
269#ifndef S_IFSOCK
270# define S_IFSOCK 0
211#endif 271#endif
212 272
213#ifndef MAP_ANONYMOUS 273#ifndef MAP_ANONYMOUS
214# ifdef MAP_ANON 274# ifdef MAP_ANON
215# define MAP_ANONYMOUS MAP_ANON 275# define MAP_ANONYMOUS MAP_ANON
229#ifndef MAP_POPULATE 289#ifndef MAP_POPULATE
230# define MAP_POPULATE 0 290# define MAP_POPULATE 0
231#endif 291#endif
232#ifndef MAP_NONBLOCK 292#ifndef MAP_NONBLOCK
233# define MAP_NONBLOCK 0 293# define MAP_NONBLOCK 0
294#endif
295
296#ifndef makedev
297# define makedev(maj,min) (((maj) << 8) | (min))
298#endif
299#ifndef major
300# define major(dev) ((dev) >> 8)
301#endif
302#ifndef minor
303# define minor(dev) ((dev) & 0xff)
234#endif 304#endif
235 305
236#ifndef PAGESIZE 306#ifndef PAGESIZE
237# define PAGESIZE sysconf (_SC_PAGESIZE) 307# define PAGESIZE sysconf (_SC_PAGESIZE)
238#endif 308#endif
504 case EIO_NOP: 574 case EIO_NOP:
505 case EIO_BUSY: 575 case EIO_BUSY:
506 break; 576 break;
507 577
508 case EIO_READLINK: 578 case EIO_READLINK:
579 case EIO_REALPATH:
509 if (req->result > 0) 580 if (req->result > 0)
510 PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); 581 PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result)));
511 break; 582 break;
512 583
513 case EIO_STAT: 584 case EIO_STAT:
585 grp->sv2 = 0; 656 grp->sv2 = 0;
586 657
587 eio_grp_cancel (grp); 658 eio_grp_cancel (grp);
588} 659}
589 660
590static void
591create_respipe (void) 661static void create_respipe (void)
592{ 662{
593 if (s_epipe_renew (&respipe)) 663 if (s_epipe_renew (&respipe))
594 croak ("IO::AIO: unable to initialize result pipe"); 664 croak ("IO::AIO: unable to initialize result pipe");
595} 665}
596 666
637/*****************************************************************************/ 707/*****************************************************************************/
638 708
639#if !_POSIX_MAPPED_FILES 709#if !_POSIX_MAPPED_FILES
640# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) 710# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1)
641# define munmap(addr,length) (errno = ENOSYS, -1) 711# define munmap(addr,length) (errno = ENOSYS, -1)
712#endif
713
714#if !_POSIX_MEMORY_PROTECTION
642# define mprotect(addr,len,prot) (errno = ENOSYS, -1) 715# define mprotect(addr,len,prot) (errno = ENOSYS, -1)
643# define PROT_NONE 0 716# define PROT_NONE 0
644# define PROT_WRITE 0 717# define PROT_WRITE 0
645# define MAP_PRIVATE 0 718# define MAP_PRIVATE 0
646# define MAP_SHARED 0 719# define MAP_SHARED 0
647# define MAP_FIXED 0 720# define MAP_FIXED 0
648#endif 721#endif
649 722
650#define MMAP_MAGIC PERL_MAGIC_ext 723#define MMAP_MAGIC PERL_MAGIC_ext
651 724
652static int
653mmap_free (pTHX_ SV *sv, MAGIC *mg) 725static int mmap_free (pTHX_ SV *sv, MAGIC *mg)
654{ 726{
655 int old_errno = errno; 727 int old_errno = errno;
656 munmap (mg->mg_ptr, (size_t)mg->mg_obj); 728 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
657 errno = old_errno; 729 errno = old_errno;
658 730
674 0, 0, 0, 0, mmap_free 746 0, 0, 0, 0, mmap_free
675}; 747};
676 748
677/*****************************************************************************/ 749/*****************************************************************************/
678 750
679static SV *
680get_cb (SV *cb_sv) 751static SV * get_cb (SV *cb_sv)
681{ 752{
682 SvGETMAGIC (cb_sv); 753 SvGETMAGIC (cb_sv);
683 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; 754 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0;
684} 755}
685 756
726 const_iv (O_RDWR) 797 const_iv (O_RDWR)
727 const_iv (O_CREAT) 798 const_iv (O_CREAT)
728 const_iv (O_TRUNC) 799 const_iv (O_TRUNC)
729 const_iv (O_EXCL) 800 const_iv (O_EXCL)
730 const_iv (O_APPEND) 801 const_iv (O_APPEND)
731#ifndef _WIN32 802
803 const_iv (O_ASYNC)
804 const_iv (O_DIRECT)
805 const_iv (O_NOATIME)
806
807 const_iv (O_CLOEXEC)
808 const_iv (O_NOCTTY)
809 const_iv (O_NOFOLLOW)
810 const_iv (O_NONBLOCK)
811 const_iv (O_EXEC)
812 const_iv (O_SEARCH)
813 const_iv (O_DIRECTORY)
814 const_iv (O_DSYNC)
815 const_iv (O_RSYNC)
816 const_iv (O_SYNC)
817 const_iv (O_TTY_INIT)
818
732 const_iv (S_IFIFO) 819 const_iv (S_IFIFO)
733#endif 820 const_iv (S_IFCHR)
821 const_iv (S_IFBLK)
822 const_iv (S_IFLNK)
823 const_iv (S_IFREG)
824 const_iv (S_IFDIR)
825 const_iv (S_IFWHT)
826 const_iv (S_IFSOCK)
827 const_iv (S_IFMT)
828
734 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) 829 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL)
735 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) 830 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL)
736 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) 831 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM)
737 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) 832 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE)
738 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) 833 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED)
785 880
786 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) 881 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE)
787 const_eio (SYNC_FILE_RANGE_WRITE) 882 const_eio (SYNC_FILE_RANGE_WRITE)
788 const_eio (SYNC_FILE_RANGE_WAIT_AFTER) 883 const_eio (SYNC_FILE_RANGE_WAIT_AFTER)
789 884
885 const_eio (FALLOC_FL_KEEP_SIZE)
886
790 const_eio (READDIR_DENTS) 887 const_eio (READDIR_DENTS)
791 const_eio (READDIR_DIRS_FIRST) 888 const_eio (READDIR_DIRS_FIRST)
792 const_eio (READDIR_STAT_ORDER) 889 const_eio (READDIR_STAT_ORDER)
793 const_eio (READDIR_FOUND_UNKNOWN) 890 const_eio (READDIR_FOUND_UNKNOWN)
794 891
820 /* atfork child called in fifo order, so before eio's handler */ 917 /* atfork child called in fifo order, so before eio's handler */
821 X_THREAD_ATFORK (0, 0, atfork_child); 918 X_THREAD_ATFORK (0, 0, atfork_child);
822} 919}
823 920
824void 921void
825max_poll_reqs (int nreqs) 922max_poll_reqs (unsigned int nreqs)
826 PROTOTYPE: $ 923 PROTOTYPE: $
827 CODE: 924 CODE:
828 eio_set_max_poll_reqs (nreqs); 925 eio_set_max_poll_reqs (nreqs);
829 926
830void 927void
832 PROTOTYPE: $ 929 PROTOTYPE: $
833 CODE: 930 CODE:
834 eio_set_max_poll_time (nseconds); 931 eio_set_max_poll_time (nseconds);
835 932
836void 933void
837min_parallel (int nthreads) 934min_parallel (unsigned int nthreads)
838 PROTOTYPE: $ 935 PROTOTYPE: $
839 CODE: 936 CODE:
840 eio_set_min_parallel (nthreads); 937 eio_set_min_parallel (nthreads);
841 938
842void 939void
843max_parallel (int nthreads) 940max_parallel (unsigned int nthreads)
844 PROTOTYPE: $ 941 PROTOTYPE: $
845 CODE: 942 CODE:
846 eio_set_max_parallel (nthreads); 943 eio_set_max_parallel (nthreads);
847 944
848void 945void
849max_idle (int nthreads) 946max_idle (unsigned int nthreads)
850 PROTOTYPE: $ 947 PROTOTYPE: $
851 CODE: 948 CODE:
852 eio_set_max_idle (nthreads); 949 eio_set_max_idle (nthreads);
853 950
854void 951void
952idle_timeout (unsigned int seconds)
953 PROTOTYPE: $
954 CODE:
955 eio_set_idle_timeout (seconds);
956
957void
855max_outstanding (int maxreqs) 958max_outstanding (unsigned int maxreqs)
856 PROTOTYPE: $ 959 PROTOTYPE: $
857 CODE: 960 CODE:
858 max_outstanding = maxreqs; 961 max_outstanding = maxreqs;
859 962
860void 963void
900 req->sv1 = newSVsv (fh); 1003 req->sv1 = newSVsv (fh);
901 req->int1 = fd; 1004 req->int1 = fd;
902 req->offs = offset; 1005 req->offs = offset;
903 req->size = nbytes; 1006 req->size = nbytes;
904 req->int2 = flags; 1007 req->int2 = flags;
1008
1009 REQ_SEND (req);
1010}
1011
1012void
1013aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef)
1014 PPCODE:
1015{
1016 int fd = s_fileno_croak (fh, 0);
1017 dREQ;
1018
1019 req->type = EIO_FALLOCATE;
1020 req->sv1 = newSVsv (fh);
1021 req->int1 = fd;
1022 req->int2 = mode;
1023 req->offs = offset;
1024 req->size = len;
905 1025
906 REQ_SEND (req); 1026 REQ_SEND (req);
907} 1027}
908 1028
909void 1029void
987 } 1107 }
988} 1108}
989 1109
990void 1110void
991aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1111aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
1112 ALIAS:
1113 aio_readlink = EIO_READLINK
1114 aio_realpath = EIO_REALPATH
992 PPCODE: 1115 PPCODE:
993{ 1116{
994 SV *data; 1117 SV *data;
995 dREQ; 1118 dREQ;
996 1119
997 req->type = EIO_READLINK; 1120 req->type = ix;
998 req->sv1 = newSVsv (path); 1121 req->sv1 = newSVsv (path);
999 req->ptr1 = SvPVbyte_nolen (req->sv1); 1122 req->ptr1 = SvPVbyte_nolen (req->sv1);
1000 1123
1001 REQ_SEND; 1124 REQ_SEND;
1002} 1125}
1060 } 1183 }
1061 1184
1062 REQ_SEND; 1185 REQ_SEND;
1063} 1186}
1064 1187
1188UV
1189major (UV dev)
1190 ALIAS:
1191 minor = 1
1192 CODE:
1193 RETVAL = ix ? major (dev) : minor (dev);
1194 OUTPUT:
1195 RETVAL
1196
1197UV
1198makedev (UV maj, UV min)
1199 CODE:
1200 RETVAL = makedev (maj, min);
1201 OUTPUT:
1202 RETVAL
1203
1065void 1204void
1066aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) 1205aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef)
1067 PPCODE: 1206 PPCODE:
1068{ 1207{
1069 dREQ; 1208 dREQ;
1524 if (!SvOK (length) || len + offset > svlen) 1663 if (!SvOK (length) || len + offset > svlen)
1525 len = svlen - offset; 1664 len = svlen - offset;
1526 1665
1527 addr = (void *)(((intptr_t)addr) + offset); 1666 addr = (void *)(((intptr_t)addr) + offset);
1528 eio_page_align (&addr, &len); 1667 eio_page_align (&addr, &len);
1529#if _POSIX_MEMLOCK 1668#if _POSIX_MEMLOCK_RANGE
1530 RETVAL = munlock (addr, len); 1669 RETVAL = munlock (addr, len);
1531#else 1670#else
1532 RETVAL = ((errno = ENOSYS), -1); 1671 RETVAL = ((errno = ENOSYS), -1);
1533#endif 1672#endif
1534} 1673}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines