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.175 by root, Wed Dec 1 04:43:12 2010 UTC vs.
Revision 1.184 by root, Tue Jul 5 20:34:42 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"
125
126/* Linux/others */
127#ifndef O_ASYNC
128# define O_ASYNC 0
129#endif
130#ifndef O_DIRECT
131# define O_DIRECT 0
132#endif
133#ifndef O_NOATIME
134# define O_NOATIME 0
135#endif
136
137/* POSIX */
138#ifndef O_CLOEXEC
139# define O_CLOEXEC 0
140#endif
141#ifndef O_NOFOLLOW
142# define O_NOFOLLOW 0
143#endif
144#ifndef O_NOCTTY
145# define O_NOCTTY 0
146#endif
147#ifndef O_NONBLOCK
148# define O_NONBLOCK 0
149#endif
150#ifndef O_EXEC
151# define O_EXEC 0
152#endif
153#ifndef O_SEARCH
154# define O_SEARCH 0
155#endif
156#ifndef O_DIRECTORY
157# define O_DIRECTORY 0
158#endif
159#ifndef O_DSYNC
160# define O_DSYNC 0
161#endif
162#ifndef O_RSYNC
163# define O_RSYNC 0
164#endif
165#ifndef O_SYNC
166# define O_SYNC 0
167#endif
168#ifndef O_TTY_INIT
169# define O_TTY_INIT 0
170#endif
124 171
125#ifndef POSIX_FADV_NORMAL 172#ifndef POSIX_FADV_NORMAL
126# define POSIX_FADV_NORMAL 0 173# define POSIX_FADV_NORMAL 0
127#endif 174#endif
128#ifndef POSIX_FADV_SEQUENTIAL 175#ifndef POSIX_FADV_SEQUENTIAL
205#ifndef ST_NODIRATIME 252#ifndef ST_NODIRATIME
206# define ST_NODIRATIME 0 253# define ST_NODIRATIME 0
207#endif 254#endif
208#ifndef ST_RELATIME 255#ifndef ST_RELATIME
209# define ST_RELATIME 0 256# define ST_RELATIME 0
257#endif
258
259#ifndef S_IFIFO
260# define S_IFIFO 0
261#endif
262#ifndef S_IFCHR
263# define S_IFCHR 0
264#endif
265#ifndef S_IFBLK
266# define S_IFBLK 0
267#endif
268#ifndef S_IFLNK
269# define S_IFLNK 0
270#endif
271#ifndef S_IFREG
272# define S_IFREG 0
273#endif
274#ifndef S_IFDIR
275# define S_IFDIR 0
276#endif
277#ifndef S_IFWHT
278# define S_IFWHT 0
279#endif
280#ifndef S_IFSOCK
281# define S_IFSOCK 0
210#endif 282#endif
211 283
212#ifndef MAP_ANONYMOUS 284#ifndef MAP_ANONYMOUS
213# ifdef MAP_ANON 285# ifdef MAP_ANON
214# define MAP_ANONYMOUS MAP_ANON 286# define MAP_ANONYMOUS MAP_ANON
228#ifndef MAP_POPULATE 300#ifndef MAP_POPULATE
229# define MAP_POPULATE 0 301# define MAP_POPULATE 0
230#endif 302#endif
231#ifndef MAP_NONBLOCK 303#ifndef MAP_NONBLOCK
232# define MAP_NONBLOCK 0 304# define MAP_NONBLOCK 0
305#endif
306
307#ifndef makedev
308# define makedev(maj,min) (((maj) << 8) | (min))
309#endif
310#ifndef major
311# define major(dev) ((dev) >> 8)
312#endif
313#ifndef minor
314# define minor(dev) ((dev) & 0xff)
233#endif 315#endif
234 316
235#ifndef PAGESIZE 317#ifndef PAGESIZE
236# define PAGESIZE sysconf (_SC_PAGESIZE) 318# define PAGESIZE sysconf (_SC_PAGESIZE)
237#endif 319#endif
352 /* do not recreate the result IV from scratch each time */ 434 /* do not recreate the result IV from scratch each time */
353 if (expect_true (sv_result_cache)) 435 if (expect_true (sv_result_cache))
354 { 436 {
355 sv_result = sv_result_cache; sv_result_cache = 0; 437 sv_result = sv_result_cache; sv_result_cache = 0;
356 SvIV_set (sv_result, req->result); 438 SvIV_set (sv_result, req->result);
439 SvIOK_only (sv_result);
357 } 440 }
358 else 441 else
359 { 442 {
360 sv_result = newSViv (req->result); 443 sv_result = newSViv (req->result);
361 SvREADONLY_on (sv_result); 444 SvREADONLY_on (sv_result);
502 case EIO_NOP: 585 case EIO_NOP:
503 case EIO_BUSY: 586 case EIO_BUSY:
504 break; 587 break;
505 588
506 case EIO_READLINK: 589 case EIO_READLINK:
590 case EIO_REALPATH:
507 if (req->result > 0) 591 if (req->result > 0)
508 PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); 592 PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result)));
509 break; 593 break;
510 594
511 case EIO_STAT: 595 case EIO_STAT:
525 SvSETMAGIC (req->sv2); 609 SvSETMAGIC (req->sv2);
526 PUSHs (sv_result); 610 PUSHs (sv_result);
527 } 611 }
528 break; 612 break;
529 613
530 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ 614 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */
531 if (req->result > 0) 615 if (req->result > 0)
532 SvIV_set (sv_result, 0); 616 SvIV_set (sv_result, 0);
533 /* FALLTHROUGH */ 617 /* FALLTHROUGH */
534 618
535 default: 619 default:
583 grp->sv2 = 0; 667 grp->sv2 = 0;
584 668
585 eio_grp_cancel (grp); 669 eio_grp_cancel (grp);
586} 670}
587 671
588static void
589create_respipe (void) 672static void create_respipe (void)
590{ 673{
591 if (s_epipe_renew (&respipe)) 674 if (s_epipe_renew (&respipe))
592 croak ("IO::AIO: unable to initialize result pipe"); 675 croak ("IO::AIO: unable to initialize result pipe");
593} 676}
594 677
635/*****************************************************************************/ 718/*****************************************************************************/
636 719
637#if !_POSIX_MAPPED_FILES 720#if !_POSIX_MAPPED_FILES
638# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) 721# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1)
639# define munmap(addr,length) (errno = ENOSYS, -1) 722# define munmap(addr,length) (errno = ENOSYS, -1)
723#endif
724
725#if !_POSIX_MEMORY_PROTECTION
640# define mprotect(addr,len,prot) (errno = ENOSYS, -1) 726# define mprotect(addr,len,prot) (errno = ENOSYS, -1)
641# define PROT_NONE 0 727# define PROT_NONE 0
642# define PROT_WRITE 0 728# define PROT_WRITE 0
643# define MAP_PRIVATE 0 729# define MAP_PRIVATE 0
644# define MAP_SHARED 0 730# define MAP_SHARED 0
645# define MAP_FIXED 0 731# define MAP_FIXED 0
646#endif 732#endif
647 733
648#define MMAP_MAGIC PERL_MAGIC_ext 734#define MMAP_MAGIC PERL_MAGIC_ext
649 735
650static int
651mmap_free (pTHX_ SV *sv, MAGIC *mg) 736static int mmap_free (pTHX_ SV *sv, MAGIC *mg)
652{ 737{
653 int old_errno = errno; 738 int old_errno = errno;
654 munmap (mg->mg_ptr, (size_t)mg->mg_obj); 739 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
655 errno = old_errno; 740 errno = old_errno;
656 741
672 0, 0, 0, 0, mmap_free 757 0, 0, 0, 0, mmap_free
673}; 758};
674 759
675/*****************************************************************************/ 760/*****************************************************************************/
676 761
677static SV *
678get_cb (SV *cb_sv) 762static SV * get_cb (SV *cb_sv)
679{ 763{
680 SvGETMAGIC (cb_sv); 764 SvGETMAGIC (cb_sv);
681 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; 765 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0;
682} 766}
683 767
724 const_iv (O_RDWR) 808 const_iv (O_RDWR)
725 const_iv (O_CREAT) 809 const_iv (O_CREAT)
726 const_iv (O_TRUNC) 810 const_iv (O_TRUNC)
727 const_iv (O_EXCL) 811 const_iv (O_EXCL)
728 const_iv (O_APPEND) 812 const_iv (O_APPEND)
729#ifndef _WIN32 813
814 const_iv (O_ASYNC)
815 const_iv (O_DIRECT)
816 const_iv (O_NOATIME)
817
818 const_iv (O_CLOEXEC)
819 const_iv (O_NOCTTY)
820 const_iv (O_NOFOLLOW)
821 const_iv (O_NONBLOCK)
822 const_iv (O_EXEC)
823 const_iv (O_SEARCH)
824 const_iv (O_DIRECTORY)
825 const_iv (O_DSYNC)
826 const_iv (O_RSYNC)
827 const_iv (O_SYNC)
828 const_iv (O_TTY_INIT)
829
730 const_iv (S_IFIFO) 830 const_iv (S_IFIFO)
731#endif 831 const_iv (S_IFCHR)
832 const_iv (S_IFBLK)
833 const_iv (S_IFLNK)
834 const_iv (S_IFREG)
835 const_iv (S_IFDIR)
836 const_iv (S_IFWHT)
837 const_iv (S_IFSOCK)
838 const_iv (S_IFMT)
839
732 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) 840 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL)
733 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) 841 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL)
734 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) 842 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM)
735 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) 843 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE)
736 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) 844 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED)
818 /* atfork child called in fifo order, so before eio's handler */ 926 /* atfork child called in fifo order, so before eio's handler */
819 X_THREAD_ATFORK (0, 0, atfork_child); 927 X_THREAD_ATFORK (0, 0, atfork_child);
820} 928}
821 929
822void 930void
823max_poll_reqs (int nreqs) 931max_poll_reqs (unsigned int nreqs)
824 PROTOTYPE: $ 932 PROTOTYPE: $
825 CODE: 933 CODE:
826 eio_set_max_poll_reqs (nreqs); 934 eio_set_max_poll_reqs (nreqs);
827 935
828void 936void
830 PROTOTYPE: $ 938 PROTOTYPE: $
831 CODE: 939 CODE:
832 eio_set_max_poll_time (nseconds); 940 eio_set_max_poll_time (nseconds);
833 941
834void 942void
835min_parallel (int nthreads) 943min_parallel (unsigned int nthreads)
836 PROTOTYPE: $ 944 PROTOTYPE: $
837 CODE: 945 CODE:
838 eio_set_min_parallel (nthreads); 946 eio_set_min_parallel (nthreads);
839 947
840void 948void
841max_parallel (int nthreads) 949max_parallel (unsigned int nthreads)
842 PROTOTYPE: $ 950 PROTOTYPE: $
843 CODE: 951 CODE:
844 eio_set_max_parallel (nthreads); 952 eio_set_max_parallel (nthreads);
845 953
846void 954void
847max_idle (int nthreads) 955max_idle (unsigned int nthreads)
848 PROTOTYPE: $ 956 PROTOTYPE: $
849 CODE: 957 CODE:
850 eio_set_max_idle (nthreads); 958 eio_set_max_idle (nthreads);
851 959
852void 960void
961idle_timeout (unsigned int seconds)
962 PROTOTYPE: $
963 CODE:
964 eio_set_idle_timeout (seconds);
965
966void
853max_outstanding (int maxreqs) 967max_outstanding (unsigned int maxreqs)
854 PROTOTYPE: $ 968 PROTOTYPE: $
855 CODE: 969 CODE:
856 max_outstanding = maxreqs; 970 max_outstanding = maxreqs;
857 971
858void 972void
985 } 1099 }
986} 1100}
987 1101
988void 1102void
989aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1103aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
1104 ALIAS:
1105 aio_readlink = EIO_READLINK
1106 aio_realpath = EIO_REALPATH
990 PPCODE: 1107 PPCODE:
991{ 1108{
992 SV *data; 1109 SV *data;
993 dREQ; 1110 dREQ;
994 1111
995 req->type = EIO_READLINK; 1112 req->type = ix;
996 req->sv1 = newSVsv (path); 1113 req->sv1 = newSVsv (path);
997 req->ptr1 = SvPVbyte_nolen (req->sv1); 1114 req->ptr1 = SvPVbyte_nolen (req->sv1);
998 1115
999 REQ_SEND; 1116 REQ_SEND;
1000} 1117}
1058 } 1175 }
1059 1176
1060 REQ_SEND; 1177 REQ_SEND;
1061} 1178}
1062 1179
1180UV
1181major (UV dev)
1182 ALIAS:
1183 minor = 1
1184 CODE:
1185 RETVAL = ix ? major (dev) : minor (dev);
1186 OUTPUT:
1187 RETVAL
1188
1189UV
1190makedev (UV maj, UV min)
1191 CODE:
1192 RETVAL = makedev (maj, min);
1193 OUTPUT:
1194 RETVAL
1195
1063void 1196void
1064aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) 1197aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef)
1065 PPCODE: 1198 PPCODE:
1066{ 1199{
1067 dREQ; 1200 dREQ;
1522 if (!SvOK (length) || len + offset > svlen) 1655 if (!SvOK (length) || len + offset > svlen)
1523 len = svlen - offset; 1656 len = svlen - offset;
1524 1657
1525 addr = (void *)(((intptr_t)addr) + offset); 1658 addr = (void *)(((intptr_t)addr) + offset);
1526 eio_page_align (&addr, &len); 1659 eio_page_align (&addr, &len);
1527#if _POSIX_MEMLOCK 1660#if _POSIX_MEMLOCK_RANGE
1528 RETVAL = munlock (addr, len); 1661 RETVAL = munlock (addr, len);
1529#else 1662#else
1530 RETVAL = ((errno = ENOSYS), -1); 1663 RETVAL = ((errno = ENOSYS), -1);
1531#endif 1664#endif
1532} 1665}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines