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.37 by root, Tue Aug 23 12:37:19 2005 UTC vs.
Revision 1.42 by root, Fri Jul 21 07:35:31 2006 UTC

8#include "autoconf/config.h" 8#include "autoconf/config.h"
9 9
10#include <pthread.h> 10#include <pthread.h>
11 11
12#include <stddef.h> 12#include <stddef.h>
13#include <errno.h>
13#include <sys/types.h> 14#include <sys/types.h>
14#include <sys/stat.h> 15#include <sys/stat.h>
15#include <limits.h> 16#include <limits.h>
16#include <unistd.h> 17#include <unistd.h>
17#include <fcntl.h> 18#include <fcntl.h>
31# else 32# else
32# error sendfile support requested but not available 33# error sendfile support requested but not available
33# endif 34# endif
34#endif 35#endif
35 36
37/* used for struct dirent, AIX doesn't provide it */
38#ifndef NAME_MAX
39# define NAME_MAX 4096
40#endif
41
36#if __ia64 42#if __ia64
37# define STACKSIZE 65536 43# define STACKSIZE 65536
38#else 44#else
39# define STACKSIZE 8192 45# define STACKSIZE 8192
40#endif 46#endif
44 REQ_OPEN, REQ_CLOSE, 50 REQ_OPEN, REQ_CLOSE,
45 REQ_READ, REQ_WRITE, REQ_READAHEAD, 51 REQ_READ, REQ_WRITE, REQ_READAHEAD,
46 REQ_SENDFILE, 52 REQ_SENDFILE,
47 REQ_STAT, REQ_LSTAT, REQ_FSTAT, 53 REQ_STAT, REQ_LSTAT, REQ_FSTAT,
48 REQ_FSYNC, REQ_FDATASYNC, 54 REQ_FSYNC, REQ_FDATASYNC,
49 REQ_UNLINK, REQ_RMDIR, 55 REQ_UNLINK, REQ_RMDIR, REQ_RENAME,
50 REQ_READDIR, 56 REQ_READDIR,
51 REQ_SYMLINK, 57 REQ_LINK, REQ_SYMLINK,
52}; 58};
53 59
54typedef struct aio_cb { 60typedef struct aio_cb {
55 struct aio_cb *volatile next; 61 struct aio_cb *volatile next;
56 62
499 505
500 if (res < 0 && sbytes) 506 if (res < 0 && sbytes)
501 res = sbytes; 507 res = sbytes;
502 } 508 }
503 509
510# endif
504# else 511#else
505 res = -1; 512 res = -1;
506 errno = ENOSYS; 513 errno = ENOSYS;
507# endif
508#endif 514#endif
509 515
510 if (res < 0 516 if (res < 0
511 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK 517 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK
512#if __solaris 518#if __solaris
517 { 523 {
518 /* emulate sendfile. this is a major pain in the ass */ 524 /* emulate sendfile. this is a major pain in the ass */
519 char buf[4096]; 525 char buf[4096];
520 res = 0; 526 res = 0;
521 527
522 for (;;) 528 while (count)
523 { 529 {
524 ssize_t cnt; 530 ssize_t cnt;
525 531
526 cnt = pread (ifd, buf, 4096, offset); 532 cnt = pread (ifd, buf, count > 4096 ? 4096 : count, offset);
527 533
528 if (cnt <= 0) 534 if (cnt <= 0)
529 { 535 {
530 if (cnt && !res) res = -1; 536 if (cnt && !res) res = -1;
531 break; 537 break;
539 break; 545 break;
540 } 546 }
541 547
542 offset += cnt; 548 offset += cnt;
543 res += cnt; 549 res += cnt;
550 count -= cnt;
544 } 551 }
545 } 552 }
546 553
547 return res; 554 return res;
548} 555}
659 666
660 case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; 667 case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break;
661 case REQ_CLOSE: req->result = close (req->fd); break; 668 case REQ_CLOSE: req->result = close (req->fd); break;
662 case REQ_UNLINK: req->result = unlink (req->dataptr); break; 669 case REQ_UNLINK: req->result = unlink (req->dataptr); break;
663 case REQ_RMDIR: req->result = rmdir (req->dataptr); break; 670 case REQ_RMDIR: req->result = rmdir (req->dataptr); break;
671 case REQ_RENAME: req->result = rename (req->data2ptr, req->dataptr); break;
672 case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break;
664 case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; 673 case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break;
665 674
666 case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; 675 case REQ_FDATASYNC: req->result = fdatasync (req->fd); break;
667 case REQ_FSYNC: req->result = fsync (req->fd); break; 676 case REQ_FSYNC: req->result = fsync (req->fd); break;
668 case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; 677 case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break;
774 783
775PROTOTYPES: ENABLE 784PROTOTYPES: ENABLE
776 785
777BOOT: 786BOOT:
778{ 787{
788 HV *stash = gv_stashpv ("IO::AIO", 1);
789 newCONSTSUB (stash, "EXDEV", newSViv (EXDEV));
790 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY));
791 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY));
792
779 create_pipe (); 793 create_pipe ();
780 pthread_atfork (atfork_prepare, atfork_parent, atfork_child); 794 pthread_atfork (atfork_prepare, atfork_parent, atfork_child);
781} 795}
782 796
783void 797void
784min_parallel(nthreads) 798min_parallel (nthreads)
785 int nthreads 799 int nthreads
786 PROTOTYPE: $ 800 PROTOTYPE: $
787 801
788void 802void
789max_parallel(nthreads) 803max_parallel (nthreads)
790 int nthreads 804 int nthreads
791 PROTOTYPE: $ 805 PROTOTYPE: $
792 806
793int 807int
794max_outstanding(nreqs) 808max_outstanding (nreqs)
795 int nreqs 809 int nreqs
796 PROTOTYPE: $ 810 PROTOTYPE: $
797 CODE: 811 CODE:
798 RETVAL = max_outstanding; 812 RETVAL = max_outstanding;
799 max_outstanding = nreqs; 813 max_outstanding = nreqs;
800 814
801void 815void
802aio_open(pathname,flags,mode,callback=&PL_sv_undef) 816aio_open (pathname,flags,mode,callback=&PL_sv_undef)
803 SV * pathname 817 SV * pathname
804 int flags 818 int flags
805 int mode 819 int mode
806 SV * callback 820 SV * callback
807 PROTOTYPE: $$$;$ 821 PROTOTYPE: $$$;$
817 831
818 send_req (req); 832 send_req (req);
819} 833}
820 834
821void 835void
822aio_close(fh,callback=&PL_sv_undef) 836aio_close (fh,callback=&PL_sv_undef)
823 SV * fh 837 SV * fh
824 SV * callback 838 SV * callback
825 PROTOTYPE: $;$ 839 PROTOTYPE: $;$
826 ALIAS: 840 ALIAS:
827 aio_close = REQ_CLOSE 841 aio_close = REQ_CLOSE
837 851
838 send_req (req); 852 send_req (req);
839} 853}
840 854
841void 855void
842aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) 856aio_read (fh,offset,length,data,dataoffset,callback=&PL_sv_undef)
843 SV * fh 857 SV * fh
844 UV offset 858 UV offset
845 UV length 859 UV length
846 SV * data 860 SV * data
847 UV dataoffset 861 UV dataoffset
901 send_req (req); 915 send_req (req);
902 } 916 }
903} 917}
904 918
905void 919void
906aio_sendfile(out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) 920aio_sendfile (out_fh,in_fh,in_offset,length,callback=&PL_sv_undef)
907 SV * out_fh 921 SV * out_fh
908 SV * in_fh 922 SV * in_fh
909 UV in_offset 923 UV in_offset
910 UV length 924 UV length
911 SV * callback 925 SV * callback
924 938
925 send_req (req); 939 send_req (req);
926} 940}
927 941
928void 942void
929aio_readahead(fh,offset,length,callback=&PL_sv_undef) 943aio_readahead (fh,offset,length,callback=&PL_sv_undef)
930 SV * fh 944 SV * fh
931 UV offset 945 UV offset
932 IV length 946 IV length
933 SV * callback 947 SV * callback
934 PROTOTYPE: $$$;$ 948 PROTOTYPE: $$$;$
944 958
945 send_req (req); 959 send_req (req);
946} 960}
947 961
948void 962void
949aio_stat(fh_or_path,callback=&PL_sv_undef) 963aio_stat (fh_or_path,callback=&PL_sv_undef)
950 SV * fh_or_path 964 SV * fh_or_path
951 SV * callback 965 SV * callback
952 ALIAS: 966 ALIAS:
953 aio_stat = REQ_STAT 967 aio_stat = REQ_STAT
954 aio_lstat = REQ_LSTAT 968 aio_lstat = REQ_LSTAT
978 992
979 send_req (req); 993 send_req (req);
980} 994}
981 995
982void 996void
983aio_unlink(pathname,callback=&PL_sv_undef) 997aio_unlink (pathname,callback=&PL_sv_undef)
984 SV * pathname 998 SV * pathname
985 SV * callback 999 SV * callback
986 ALIAS: 1000 ALIAS:
987 aio_unlink = REQ_UNLINK 1001 aio_unlink = REQ_UNLINK
988 aio_rmdir = REQ_RMDIR 1002 aio_rmdir = REQ_RMDIR
1003 aio_readdir = REQ_READDIR
989 CODE: 1004 CODE:
990{ 1005{
991 dREQ; 1006 dREQ;
992 1007
993 req->type = ix; 1008 req->type = ix;
996 1011
997 send_req (req); 1012 send_req (req);
998} 1013}
999 1014
1000void 1015void
1001aio_symlink(oldpath,newpath,callback=&PL_sv_undef) 1016aio_link (oldpath,newpath,callback=&PL_sv_undef)
1002 SV * oldpath 1017 SV * oldpath
1003 SV * newpath 1018 SV * newpath
1004 SV * callback 1019 SV * callback
1020 ALIAS:
1021 aio_link = REQ_LINK
1022 aio_symlink = REQ_SYMLINK
1023 aio_rename = REQ_RENAME
1005 CODE: 1024 CODE:
1006{ 1025{
1007 dREQ; 1026 dREQ;
1008 1027
1009 req->type = REQ_SYMLINK; 1028 req->type = ix;
1010 req->fh = newSVsv (oldpath); 1029 req->fh = newSVsv (oldpath);
1011 req->data2ptr = SvPVbyte_nolen (req->fh); 1030 req->data2ptr = SvPVbyte_nolen (req->fh);
1012 req->data = newSVsv (newpath); 1031 req->data = newSVsv (newpath);
1013 req->dataptr = SvPVbyte_nolen (req->data); 1032 req->dataptr = SvPVbyte_nolen (req->data);
1014 1033
1015 send_req (req); 1034 send_req (req);
1016} 1035}
1017 1036
1018void 1037#if 0
1019aio_readdir(pathname,callback=&PL_sv_undef)
1020 SV * pathname
1021 SV * callback
1022 CODE:
1023{
1024 dREQ;
1025
1026 req->type = REQ_READDIR;
1027 req->data = newSVsv (pathname);
1028 req->dataptr = SvPVbyte_nolen (req->data);
1029
1030 send_req (req);
1031}
1032 1038
1039# undocumented, because it does not cancel active requests
1033void 1040void
1041cancel_most_requests ()
1042 PROTOTYPE:
1043 CODE:
1044{
1045 aio_req *req;
1046
1047 pthread_mutex_lock (&reqlock);
1048 for (req = reqs; req; req = req->next)
1049 req->flags |= 1;
1050 pthread_mutex_unlock (&reqlock);
1051
1052 pthread_mutex_lock (&reslock);
1053 for (req = ress; req; req = req->next)
1054 req->flags |= 1;
1055 pthread_mutex_unlock (&reslock);
1056}
1057
1058#endif
1059
1060void
1034flush() 1061flush ()
1035 PROTOTYPE: 1062 PROTOTYPE:
1036 CODE: 1063 CODE:
1037 while (nreqs) 1064 while (nreqs)
1038 { 1065 {
1039 poll_wait (); 1066 poll_wait ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines