--- IO-AIO/AIO.xs 2010/08/04 17:16:19 1.171 +++ IO-AIO/AIO.xs 2010/12/01 04:43:12 1.175 @@ -124,7 +124,6 @@ #ifndef POSIX_FADV_NORMAL # define POSIX_FADV_NORMAL 0 -# define NO_FADVISE 1 #endif #ifndef POSIX_FADV_SEQUENTIAL # define POSIX_FADV_SEQUENTIAL 0 @@ -142,13 +141,12 @@ # define POSIX_FADV_DONTNEED 0 #endif -#if _XOPEN_SOURCE < 600 || NO_FADVISE +#if !HAVE_POSIX_FADVISE # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ #endif #ifndef POSIX_MADV_NORMAL # define POSIX_MADV_NORMAL 0 -# define NO_MADVISE 1 #endif #ifndef POSIX_MADV_SEQUENTIAL # define POSIX_MADV_SEQUENTIAL 0 @@ -163,7 +161,7 @@ # define POSIX_MADV_DONTNEED 0 #endif -#if _XOPEN_SOURCE < 600 || NO_MADVISE +#if !HAVE_POSIX_MADVISE # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ #endif @@ -211,13 +209,6 @@ # define ST_RELATIME 0 #endif -#ifndef MCL_CURRENT -# define MCL_CURRENT 0 -#endif -#ifndef MCL_FUTURE -# define MCL_FUTURE 0 -#endif - #ifndef MAP_ANONYMOUS # ifdef MAP_ANON # define MAP_ANONYMOUS MAP_ANON @@ -647,6 +638,11 @@ # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) # define munmap(addr,length) (errno = ENOSYS, -1) # define mprotect(addr,len,prot) (errno = ENOSYS, -1) +# define PROT_NONE 0 +# define PROT_WRITE 0 +# define MAP_PRIVATE 0 +# define MAP_SHARED 0 +# define MAP_FIXED 0 #endif #define MMAP_MAGIC PERL_MAGIC_ext @@ -776,8 +772,8 @@ const_iv (MAP_POPULATE) const_iv (MAP_NONBLOCK) - const_iv (MCL_FUTURE) - const_iv (MCL_CURRENT) + const_eio (MCL_FUTURE) + const_eio (MCL_CURRENT) const_eio (MS_ASYNC) const_eio (MS_INVALIDATE) @@ -861,7 +857,6 @@ void aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) - PROTOTYPE: $$$;$ PPCODE: { dREQ; @@ -877,7 +872,6 @@ void aio_fsync (SV *fh, SV *callback=&PL_sv_undef) - PROTOTYPE: $;$ ALIAS: aio_fsync = EIO_FSYNC aio_fdatasync = EIO_FDATASYNC @@ -895,7 +889,6 @@ void aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) - PROTOTYPE: $$$$;$ PPCODE: { int fd = s_fileno_croak (fh, 0); @@ -913,7 +906,6 @@ void aio_close (SV *fh, SV *callback=&PL_sv_undef) - PROTOTYPE: $;$ PPCODE: { static int close_pipe = -1; /* dummy fd to close fds via dup2 */ @@ -945,7 +937,6 @@ ALIAS: aio_read = EIO_READ aio_write = EIO_WRITE - PROTOTYPE: $$$$$;$ PPCODE: { STRLEN svlen; @@ -996,7 +987,6 @@ void aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) - PROTOTYPE: $$;$ PPCODE: { SV *data; @@ -1011,7 +1001,6 @@ void aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) - PROTOTYPE: $$$$;$ PPCODE: { int ifd = s_fileno_croak (in_fh , 0); @@ -1031,7 +1020,6 @@ void aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) - PROTOTYPE: $$$;$ PPCODE: { int fd = s_fileno_croak (fh, 0); @@ -1242,12 +1230,11 @@ ALIAS: aio_mtouch = EIO_MTOUCH aio_msync = EIO_MSYNC - PROTOTYPE: $$$$;$ PPCODE: { STRLEN svlen; - UV len = SvUV (length); char *svptr = SvPVbyte (data, svlen); + UV len = SvUV (length); if (offset < 0) offset += svlen; @@ -1262,9 +1249,9 @@ dREQ; req->type = ix; - req->size = len; req->sv2 = SvREFCNT_inc (data); req->ptr2 = (char *)svptr + offset; + req->size = len; req->int1 = flags; REQ_SEND; @@ -1272,6 +1259,47 @@ } void +aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) + PPCODE: +{ + STRLEN svlen; + char *svptr = SvPVbyte (data, svlen); + UV len = SvUV (length); + + if (offset < 0) + offset += svlen; + + if (offset < 0 || offset > svlen) + croak ("offset outside of scalar"); + + if (!SvOK (length) || len + offset > svlen) + len = svlen - offset; + + { + dREQ; + + req->type = EIO_MLOCK; + req->sv2 = SvREFCNT_inc (data); + req->ptr2 = (char *)svptr + offset; + req->size = len; + + REQ_SEND; + } +} + +void +aio_mlockall (IV flags, SV *callback=&PL_sv_undef) + PPCODE: +{ + dREQ; + + req->type = EIO_MLOCKALL; + req->int1 = flags; + + REQ_SEND; +} + +void aio_busy (double delay, SV *callback=&PL_sv_undef) PPCODE: { @@ -1285,7 +1313,6 @@ void aio_group (SV *callback=&PL_sv_undef) - PROTOTYPE: ;$ PPCODE: { dREQ; @@ -1312,7 +1339,6 @@ int aioreq_pri (int pri = 0) - PROTOTYPE: ;$ CODE: RETVAL = next_pri; if (items > 0) @@ -1334,7 +1360,6 @@ void flush () - PROTOTYPE: CODE: while (eio_nreqs ()) { @@ -1343,8 +1368,7 @@ } int -poll() - PROTOTYPE: +poll () CODE: poll_wait (); RETVAL = poll_cb (); @@ -1352,15 +1376,14 @@ RETVAL int -poll_fileno() - PROTOTYPE: +poll_fileno () CODE: RETVAL = s_epipe_fd (&respipe); OUTPUT: RETVAL int -poll_cb(...) +poll_cb (...) PROTOTYPE: CODE: RETVAL = poll_cb (); @@ -1368,38 +1391,33 @@ RETVAL void -poll_wait() - PROTOTYPE: +poll_wait () CODE: poll_wait (); int -nreqs() - PROTOTYPE: +nreqs () CODE: RETVAL = eio_nreqs (); OUTPUT: RETVAL int -nready() - PROTOTYPE: +nready () CODE: RETVAL = eio_nready (); OUTPUT: RETVAL int -npending() - PROTOTYPE: +npending () CODE: RETVAL = eio_npending (); OUTPUT: RETVAL int -nthreads() - PROTOTYPE: +nthreads () CODE: RETVAL = eio_nthreads (); OUTPUT: @@ -1407,7 +1425,6 @@ int fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) - PROTOTYPE: $$$$ CODE: RETVAL = posix_fadvise (fh, offset, length, advice); OUTPUT: @@ -1415,7 +1432,6 @@ ssize_t sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) - PROTOTYPE: $$$$ CODE: RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); OUTPUT: @@ -1423,7 +1439,6 @@ void mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) - PROTOTYPE: $$$$$;$ PPCODE: sv_unmagic (scalar, MMAP_MAGIC); { @@ -1456,60 +1471,70 @@ void munmap (SV *scalar) - PROTOTYPE: $ CODE: sv_unmagic (scalar, MMAP_MAGIC); int -madvise (SV *scalar, off_t offset, off_t length, IV advice_or_prot) +madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) ALIAS: mprotect = 1 - PROTOTYPE: $$$$ CODE: { - STRLEN cur; - char *addr = SvPVbyte (scalar, cur); + STRLEN svlen; + void *addr = SvPVbyte (scalar, svlen); + size_t len = SvUV (length); - if (offset > cur) - RETVAL = errno = EFAULT; - else - { - if (!SvOK (ST (2))) - length = cur - offset; + if (offset < 0) + offset += svlen; - if (offset + length > cur) - RETVAL = errno = EFAULT; - else - switch (ix) - { - case 0: RETVAL = posix_madvise (addr + offset, length, advice_or_prot); break; - case 1: RETVAL = mprotect (addr + offset, length, advice_or_prot); break; - } + if (offset < 0 || offset > svlen) + croak ("offset outside of scalar"); + + if (!SvOK (length) || len + offset > svlen) + len = svlen - offset; + + addr = (void *)(((intptr_t)addr) + offset); + eio_page_align (&addr, &len); + + switch (ix) + { + case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; + case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; } } OUTPUT: RETVAL int -mlockall (int flags) - PROTOTYPE: $ +munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) CODE: +{ + STRLEN svlen; + void *addr = SvPVbyte (scalar, svlen); + size_t len = SvUV (length); + + if (offset < 0) + offset += svlen; + + if (offset < 0 || offset > svlen) + croak ("offset outside of scalar"); + + if (!SvOK (length) || len + offset > svlen) + len = svlen - offset; + + addr = (void *)(((intptr_t)addr) + offset); + eio_page_align (&addr, &len); #if _POSIX_MEMLOCK -#if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 - extern int mallopt (int, int); - mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ -#endif - mlockall (flags); + RETVAL = munlock (addr, len); #else - RETVAL = -1; - errno = ENOSYS; + RETVAL = ((errno = ENOSYS), -1); #endif +} OUTPUT: RETVAL int munlockall () - PROTOTYPE: CODE: #if _POSIX_MEMLOCK munlockall ();