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.232 by root, Sat Jun 13 00:06:13 2015 UTC vs.
Revision 1.237 by root, Thu Jun 25 18:08:47 2015 UTC

145# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 145# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
146# endif 146# endif
147#endif 147#endif
148 148
149/* defines all sorts of constants to 0 unless they are already defined */ 149/* defines all sorts of constants to 0 unless they are already defined */
150/* also provides const_iv_ and const_niv_ macros for them */
150#include "def0.h" 151#include "def0.h"
151 152
152#ifndef makedev 153#ifndef makedev
153# define makedev(maj,min) (((maj) << 8) | (min)) 154# define makedev(maj,min) (((maj) << 8) | (min))
154#endif 155#endif
337 || SvTYPE (SvRV (sv)) != SVt_PVMG 338 || SvTYPE (SvRV (sv)) != SVt_PVMG
338 || SvSTASH (SvRV (sv)) != aio_wd_stash) 339 || SvSTASH (SvRV (sv)) != aio_wd_stash)
339 croak ("IO::AIO: expected a working directory object as returned by aio_wd"); 340 croak ("IO::AIO: expected a working directory object as returned by aio_wd");
340 341
341 return (aio_wd)(long)SvIVX (SvRV (sv)); 342 return (aio_wd)(long)SvIVX (SvRV (sv));
343}
344
345static SV *
346newmortalFH (int fd, int flags)
347{
348 if (fd < 0)
349 return &PL_sv_undef;
350
351 GV *gv = (GV *)sv_newmortal ();
352 char sym[64];
353 int symlen;
354
355 symlen = snprintf (sym, sizeof (sym), "fd#%d", fd);
356 gv_init (gv, aio_stash, sym, symlen, 0);
357
358 symlen = snprintf (
359 sym,
360 sizeof (sym),
361 "%s&=%d",
362 flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<",
363 fd
364 );
365
366 return do_open (gv, sym, symlen, 0, 0, 0, 0)
367 ? (SV *)gv : &PL_sv_undef;
342} 368}
343 369
344static void 370static void
345aio_grp_feed (aio_req grp) 371aio_grp_feed (aio_req grp)
346{ 372{
474 XPUSHs (sv_2mortal (newSViv (req->int1 & ~(EIO_READDIR_CUSTOM1 | EIO_READDIR_CUSTOM2)))); 500 XPUSHs (sv_2mortal (newSViv (req->int1 & ~(EIO_READDIR_CUSTOM1 | EIO_READDIR_CUSTOM2))));
475 } 501 }
476 break; 502 break;
477 503
478 case EIO_OPEN: 504 case EIO_OPEN:
479 { 505 PUSHs (newmortalFH (req->result, req->int1 & (O_RDONLY | O_WRONLY | O_RDWR)));
480 /* convert fd to fh */
481 SV *fh = &PL_sv_undef;
482
483 if (req->result >= 0)
484 {
485 GV *gv = (GV *)sv_newmortal ();
486 int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR);
487 char sym [64];
488 int symlen;
489
490 symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result);
491 gv_init (gv, aio_stash, sym, symlen, 0);
492
493 symlen = snprintf (
494 sym,
495 sizeof (sym),
496 "%s&=%d",
497 flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<",
498 (int)req->result
499 );
500
501 if (do_open (gv, sym, symlen, 0, 0, 0, 0))
502 fh = (SV *)gv;
503 }
504
505 PUSHs (fh);
506 }
507 break; 506 break;
508 507
509 case EIO_STATVFS: 508 case EIO_STATVFS:
510 case EIO_FSTATVFS: 509 case EIO_FSTATVFS:
511 { 510 {
705{ 704{
706 while (eio_nreqs ()) 705 while (eio_nreqs ())
707 { 706 {
708 int size; 707 int size;
709 708
710 X_LOCK (reslock); 709 X_LOCK (EIO_POOL->reslock);
711 size = res_queue.size; 710 size = EIO_POOL->res_queue.size;
712 X_UNLOCK (reslock); 711 X_UNLOCK (EIO_POOL->reslock);
713 712
714 if (size) 713 if (size)
715 return; 714 return;
716 715
717 etp_maybe_start_thread (); 716 etp_maybe_start_thread (EIO_POOL);
718 717
719 s_epipe_wait (&respipe); 718 s_epipe_wait (&respipe);
720 } 719 }
721} 720}
722 721
753# define munmap(addr,length) EIO_ENOSYS () 752# define munmap(addr,length) EIO_ENOSYS ()
754#endif 753#endif
755 754
756#if !_POSIX_MEMORY_PROTECTION 755#if !_POSIX_MEMORY_PROTECTION
757# define mprotect(addr,len,prot) EIO_ENOSYS () 756# define mprotect(addr,len,prot) EIO_ENOSYS ()
758# define PROT_NONE 0
759# define PROT_WRITE 0
760# define MAP_PRIVATE 0
761# define MAP_SHARED 0
762# define MAP_FIXED 0
763#endif 757#endif
764 758
765#define MMAP_MAGIC PERL_MAGIC_ext 759#define MMAP_MAGIC PERL_MAGIC_ext
766 760
767static int ecb_cold 761static int ecb_cold
907 } *civ, const_iv[] = { 901 } *civ, const_iv[] = {
908# define const_niv(name, value) { # name, (IV) value }, 902# define const_niv(name, value) { # name, (IV) value },
909# define const_iv(name) { # name, (IV) name }, 903# define const_iv(name) { # name, (IV) name },
910# define const_eio(name) { # name, (IV) EIO_ ## name }, 904# define const_eio(name) { # name, (IV) EIO_ ## name },
911 905
912 /* you have to re-run ./gendef0 after adding/Removing any constants here */ 906 /* you have to re-run ./gendef0 after adding/removing any constants here */
913 907 /* the first block can be undef if missing */
914 const_iv (ENOSYS) 908 const_iv (ENOSYS)
915 const_iv (EXDEV) 909 const_iv (EXDEV)
916 const_iv (EBADR) 910 const_iv (EBADR)
917 911
912 /* for lseek */
913 const_iv (SEEK_DATA)
914 const_iv (SEEK_HOLE)
915
916 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL)
917 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL)
918 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM)
919 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE)
920 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED)
921 const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED)
922
923 const_niv (MADV_NORMAL , POSIX_MADV_NORMAL)
924 const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL)
925 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
926 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
927 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
928
929 /* the second block will be 0 when missing */
918 const_iv (O_RDONLY) 930 const_iv (O_RDONLY)
919 const_iv (O_WRONLY) 931 const_iv (O_WRONLY)
920 const_iv (O_RDWR) 932 const_iv (O_RDWR)
921 const_iv (O_CREAT) 933 const_iv (O_CREAT)
922 const_iv (O_TRUNC) 934 const_iv (O_TRUNC)
935 const_iv (O_SEARCH) 947 const_iv (O_SEARCH)
936 const_iv (O_DIRECTORY) 948 const_iv (O_DIRECTORY)
937 const_iv (O_DSYNC) 949 const_iv (O_DSYNC)
938 const_iv (O_RSYNC) 950 const_iv (O_RSYNC)
939 const_iv (O_SYNC) 951 const_iv (O_SYNC)
952 const_iv (O_PATH)
953 const_iv (O_TMPFILE)
940 const_iv (O_TTY_INIT) 954 const_iv (O_TTY_INIT)
941 955
942 const_iv (S_IFIFO) 956 const_iv (S_IFIFO)
943 const_iv (S_IFCHR) 957 const_iv (S_IFCHR)
944 const_iv (S_IFBLK) 958 const_iv (S_IFBLK)
946 const_iv (S_IFREG) 960 const_iv (S_IFREG)
947 const_iv (S_IFDIR) 961 const_iv (S_IFDIR)
948 const_iv (S_IFWHT) 962 const_iv (S_IFWHT)
949 const_iv (S_IFSOCK) 963 const_iv (S_IFSOCK)
950 const_iv (S_IFMT) 964 const_iv (S_IFMT)
951
952 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL)
953 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL)
954 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM)
955 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE)
956 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED)
957 const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED)
958
959 const_niv (MADV_NORMAL , POSIX_MADV_NORMAL)
960 const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL)
961 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
962 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
963 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
964 965
965 const_iv (ST_RDONLY) 966 const_iv (ST_RDONLY)
966 const_iv (ST_NOSUID) 967 const_iv (ST_NOSUID)
967 const_iv (ST_NODEV) 968 const_iv (ST_NODEV)
968 const_iv (ST_NOEXEC) 969 const_iv (ST_NOEXEC)
978 const_iv (PROT_NONE) 979 const_iv (PROT_NONE)
979 const_iv (PROT_EXEC) 980 const_iv (PROT_EXEC)
980 const_iv (PROT_READ) 981 const_iv (PROT_READ)
981 const_iv (PROT_WRITE) 982 const_iv (PROT_WRITE)
982 983
983 /*const_iv (MAP_FIXED)*/
984 const_iv (MAP_PRIVATE) 984 const_iv (MAP_PRIVATE)
985 const_iv (MAP_SHARED) 985 const_iv (MAP_SHARED)
986 const_iv (MAP_FIXED)
986 const_iv (MAP_ANONYMOUS) 987 const_iv (MAP_ANONYMOUS)
987 988
988 /* linuxish */ 989 /* linuxish */
989 const_iv (MAP_HUGETLB) 990 const_iv (MAP_HUGETLB)
990 const_iv (MAP_LOCKED) 991 const_iv (MAP_LOCKED)
991 const_iv (MAP_NORESERVE) 992 const_iv (MAP_NORESERVE)
992 const_iv (MAP_POPULATE) 993 const_iv (MAP_POPULATE)
993 const_iv (MAP_NONBLOCK) 994 const_iv (MAP_NONBLOCK)
995 const_iv (MAP_GROWSDOWN)
996 const_iv (MAP_32BIT)
997 const_iv (MAP_HUGETLB)
998 const_iv (MAP_STACK)
994 999
995 const_iv (FIEMAP_FLAG_SYNC) 1000 const_iv (FIEMAP_FLAG_SYNC)
996 const_iv (FIEMAP_FLAG_XATTR) 1001 const_iv (FIEMAP_FLAG_XATTR)
997 const_iv (FIEMAP_FLAGS_COMPAT) 1002 const_iv (FIEMAP_FLAGS_COMPAT)
998 const_iv (FIEMAP_EXTENT_LAST) 1003 const_iv (FIEMAP_EXTENT_LAST)
1010 const_iv (SPLICE_F_MOVE) 1015 const_iv (SPLICE_F_MOVE)
1011 const_iv (SPLICE_F_NONBLOCK) 1016 const_iv (SPLICE_F_NONBLOCK)
1012 const_iv (SPLICE_F_MORE) 1017 const_iv (SPLICE_F_MORE)
1013 const_iv (SPLICE_F_GIFT) 1018 const_iv (SPLICE_F_GIFT)
1014 1019
1015 const_iv (SEEK_DATA) 1020 /* these are libeio constants, and are independent of gendef0 */
1016 const_iv (SEEK_HOLE)
1017
1018 /* libeio constants */
1019 const_eio (SEEK_SET) 1021 const_eio (SEEK_SET)
1020 const_eio (SEEK_CUR) 1022 const_eio (SEEK_CUR)
1021 const_eio (SEEK_END) 1023 const_eio (SEEK_END)
1022 1024
1023 const_eio (MCL_FUTURE) 1025 const_eio (MCL_FUTURE)
1894 RETVAL = -1; 1896 RETVAL = -1;
1895#endif 1897#endif
1896 OUTPUT: 1898 OUTPUT:
1897 RETVAL 1899 RETVAL
1898 1900
1901void
1902pipe2 (int flags = 0)
1903 PROTOTYPE: ;$
1904 PPCODE:
1905{
1906 int fd[2];
1907 int res;
1908
1909 if (flags)
1910#if HAVE_PIPE2
1911 res = pipe2 (fd, flags);
1912#else
1913 res = (errno = ENOSYS, -1);
1914#endif
1915 else
1916 res = pipe (fd);
1917
1918 if (!res)
1919 {
1920 EXTEND (SP, 2);
1921 PUSHs (newmortalFH (fd[0], O_RDONLY));
1922 PUSHs (newmortalFH (fd[1], O_WRONLY));
1923 }
1924}
1925
1899void _on_next_submit (SV *cb) 1926void _on_next_submit (SV *cb)
1900 CODE: 1927 CODE:
1901 SvREFCNT_dec (on_next_submit); 1928 SvREFCNT_dec (on_next_submit);
1902 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; 1929 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1903 1930

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines