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.101 by root, Fri Jun 1 13:25:51 2007 UTC vs.
Revision 1.113 by root, Wed Apr 16 16:45:18 2008 UTC

4 4
5#include "EXTERN.h" 5#include "EXTERN.h"
6#include "perl.h" 6#include "perl.h"
7#include "XSUB.h" 7#include "XSUB.h"
8 8
9#include "autoconf/config.h"
10
11#include <stddef.h> 9#include <stddef.h>
12#include <stdlib.h> 10#include <stdlib.h>
13#include <errno.h> 11#include <errno.h>
14#include <sys/time.h>
15#include <sys/select.h>
16#include <sys/types.h> 12#include <sys/types.h>
17#include <sys/stat.h> 13#include <sys/stat.h>
18#include <limits.h> 14#include <limits.h>
19#include <unistd.h>
20#include <fcntl.h> 15#include <fcntl.h>
21#include <signal.h>
22#include <sched.h> 16#include <sched.h>
17
18#ifdef _WIN32
19
20# define SIGIO 0
21 typedef Direntry_t X_DIRENT;
22#undef malloc
23#undef free
24
25// perl overrides all those nice win32 functions
26# undef open
27# undef read
28# undef write
29# undef send
30# undef recv
31# undef stat
32# undef fstat
33# define lstat stat
34# undef truncate
35# undef ftruncate
36# undef open
37# undef close
38# undef unlink
39# undef rmdir
40# undef rename
41# undef lseek
42
43# define chown(a,b,c) (errno = ENOSYS, -1)
44# define fchown(a,b,c) (errno = ENOSYS, -1)
45# define fchmod(a,b) (errno = ENOSYS, -1)
46# define symlink(a,b) (errno = ENOSYS, -1)
47# define readlink(a,b,c) (errno = ENOSYS, -1)
48# define mknod(a,b,c) (errno = ENOSYS, -1)
49# define truncate(a,b) (errno = ENOSYS, -1)
50# define ftruncate(fd,o) chsize ((fd), (o))
51# define fsync(fd) _commit (fd)
52# define opendir(fd) (errno = ENOSYS, 0)
53# define readdir(fd) (errno = ENOSYS, -1)
54# define closedir(fd) (errno = ENOSYS, -1)
55# define mkdir(a,b) mkdir (a)
56
57#else
58
59# include "autoconf/config.h"
60# include <sys/time.h>
61# include <sys/select.h>
62# include <unistd.h>
23#include <utime.h> 63# include <utime.h>
64# include <signal.h>
65 typedef struct dirent X_DIRENT;
66
67#endif
24 68
25#if HAVE_SENDFILE 69#if HAVE_SENDFILE
26# if __linux 70# if __linux
27# include <sys/sendfile.h> 71# include <sys/sendfile.h>
28# elif __freebsd 72# elif __freebsd
53# define SvVAL64 SvIV 97# define SvVAL64 SvIV
54#else 98#else
55# define SvVAL64 SvNV 99# define SvVAL64 SvNV
56#endif 100#endif
57 101
102static HV *stash;
103
58#define dBUF \ 104#define dBUF \
59 char *aio_buf; \ 105 char *aio_buf; \
60 LOCK (wrklock); \ 106 X_LOCK (wrklock); \
61 self->dbuf = aio_buf = malloc (AIO_BUFSIZE); \ 107 self->dbuf = aio_buf = malloc (AIO_BUFSIZE); \
62 UNLOCK (wrklock); \ 108 X_UNLOCK (wrklock); \
63 if (!aio_buf) \ 109 if (!aio_buf) \
64 return -1; 110 return -1;
65 111
66typedef SV SV8; /* byte-sv, used for argument-checking */ 112typedef SV SV8; /* byte-sv, used for argument-checking */
67 113
69 REQ_QUIT, 115 REQ_QUIT,
70 REQ_OPEN, REQ_CLOSE, 116 REQ_OPEN, REQ_CLOSE,
71 REQ_READ, REQ_WRITE, 117 REQ_READ, REQ_WRITE,
72 REQ_READAHEAD, REQ_SENDFILE, 118 REQ_READAHEAD, REQ_SENDFILE,
73 REQ_STAT, REQ_LSTAT, REQ_FSTAT, 119 REQ_STAT, REQ_LSTAT, REQ_FSTAT,
120 REQ_TRUNCATE, REQ_FTRUNCATE,
74 REQ_UTIME, REQ_FUTIME, 121 REQ_UTIME, REQ_FUTIME,
75 REQ_CHMOD, REQ_FCHMOD, 122 REQ_CHMOD, REQ_FCHMOD,
76 REQ_CHOWN, REQ_FCHOWN, 123 REQ_CHOWN, REQ_FCHOWN,
77 REQ_FSYNC, REQ_FDATASYNC, 124 REQ_SYNC, REQ_FSYNC, REQ_FDATASYNC,
78 REQ_UNLINK, REQ_RMDIR, REQ_MKDIR, REQ_RENAME, 125 REQ_UNLINK, REQ_RMDIR, REQ_MKDIR, REQ_RENAME,
79 REQ_MKNOD, REQ_READDIR, 126 REQ_MKNOD, REQ_READDIR,
80 REQ_LINK, REQ_SYMLINK, REQ_READLINK, 127 REQ_LINK, REQ_SYMLINK, REQ_READLINK,
81 REQ_GROUP, REQ_NOP, 128 REQ_GROUP, REQ_NOP,
82 REQ_BUSY, 129 REQ_BUSY,
142 189
143static thread_t main_tid; 190static thread_t main_tid;
144static int main_sig; 191static int main_sig;
145static int block_sig_level; 192static int block_sig_level;
146 193
147void block_sig () 194void block_sig (void)
148{ 195{
149 sigset_t ss; 196 sigset_t ss;
150 197
151 if (block_sig_level++) 198 if (block_sig_level++)
152 return; 199 return;
157 sigemptyset (&ss); 204 sigemptyset (&ss);
158 sigaddset (&ss, main_sig); 205 sigaddset (&ss, main_sig);
159 pthread_sigmask (SIG_BLOCK, &ss, 0); 206 pthread_sigmask (SIG_BLOCK, &ss, 0);
160} 207}
161 208
162void unblock_sig () 209void unblock_sig (void)
163{ 210{
164 sigset_t ss; 211 sigset_t ss;
165 212
166 if (--block_sig_level) 213 if (--block_sig_level)
167 return; 214 return;
177static int next_pri = DEFAULT_PRI + PRI_BIAS; 224static int next_pri = DEFAULT_PRI + PRI_BIAS;
178 225
179static unsigned int started, idle, wanted; 226static unsigned int started, idle, wanted;
180 227
181/* worker threads management */ 228/* worker threads management */
182static mutex_t wrklock = MUTEX_INIT; 229static mutex_t wrklock = X_MUTEX_INIT;
183 230
184typedef struct worker { 231typedef struct worker {
185 /* locked by wrklock */ 232 /* locked by wrklock */
186 struct worker *prev, *next; 233 struct worker *prev, *next;
187 234
219} 266}
220 267
221static volatile unsigned int nreqs, nready, npending; 268static volatile unsigned int nreqs, nready, npending;
222static volatile unsigned int max_idle = 4; 269static volatile unsigned int max_idle = 4;
223static volatile unsigned int max_outstanding = 0xffffffff; 270static volatile unsigned int max_outstanding = 0xffffffff;
224static int respipe [2]; 271static int respipe_osf [2], respipe [2] = { -1, -1 };
225 272
226static mutex_t reslock = MUTEX_INIT; 273static mutex_t reslock = X_MUTEX_INIT;
227static mutex_t reqlock = MUTEX_INIT; 274static mutex_t reqlock = X_MUTEX_INIT;
228static cond_t reqwait = COND_INIT; 275static cond_t reqwait = X_COND_INIT;
229 276
230#if WORDACCESS_UNSAFE 277#if WORDACCESS_UNSAFE
231 278
232static unsigned int get_nready () 279static unsigned int get_nready (void)
233{ 280{
234 unsigned int retval; 281 unsigned int retval;
235 282
236 LOCK (reqlock); 283 X_LOCK (reqlock);
237 retval = nready; 284 retval = nready;
238 UNLOCK (reqlock); 285 X_UNLOCK (reqlock);
239 286
240 return retval; 287 return retval;
241} 288}
242 289
243static unsigned int get_npending () 290static unsigned int get_npending (void)
244{ 291{
245 unsigned int retval; 292 unsigned int retval;
246 293
247 LOCK (reslock); 294 X_LOCK (reslock);
248 retval = npending; 295 retval = npending;
249 UNLOCK (reslock); 296 X_UNLOCK (reslock);
250 297
251 return retval; 298 return retval;
252} 299}
253 300
254static unsigned int get_nthreads () 301static unsigned int get_nthreads (void)
255{ 302{
256 unsigned int retval; 303 unsigned int retval;
257 304
258 LOCK (wrklock); 305 X_LOCK (wrklock);
259 retval = started; 306 retval = started;
260 UNLOCK (wrklock); 307 X_UNLOCK (wrklock);
261 308
262 return retval; 309 return retval;
263} 310}
264 311
265#else 312#else
322 } 369 }
323 370
324 abort (); 371 abort ();
325} 372}
326 373
327static int poll_cb (); 374static int poll_cb (void);
328static int req_invoke (aio_req req); 375static int req_invoke (aio_req req);
329static void req_destroy (aio_req req); 376static void req_destroy (aio_req req);
330static void req_cancel (aio_req req); 377static void req_cancel (aio_req req);
331 378
332/* must be called at most once */ 379/* must be called at most once */
456 break; 503 break;
457 504
458 case REQ_OPEN: 505 case REQ_OPEN:
459 { 506 {
460 /* convert fd to fh */ 507 /* convert fd to fh */
461 SV *fh; 508 SV *fh = &PL_sv_undef;
462 509
463 PUSHs (sv_2mortal (newSViv (req->result))); 510 if (req->result >= 0)
464 PUTBACK; 511 {
465 call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); 512 GV *gv = (GV *)sv_newmortal ();
466 SPAGAIN; 513 int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR);
514 char sym [64];
515 int symlen;
516
517 symlen = snprintf (sym, sizeof (sym), "fd#%d", req->result);
518 gv_init (gv, stash, sym, symlen, 0);
467 519
468 fh = POPs; 520 symlen = snprintf (
469 PUSHMARK (SP); 521 sym,
522 sizeof (sym),
523 "%s&=%d",
524 flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<",
525 req->result
526 );
527
528 if (do_open (gv, sym, symlen, 0, 0, 0, 0))
529 fh = (SV *)gv;
530 }
531
470 XPUSHs (fh); 532 PUSHs (fh);
471 } 533 }
472 break; 534 break;
473 535
474 case REQ_GROUP: 536 case REQ_GROUP:
475 req->int1 = 2; /* mark group as finished */ 537 req->int1 = 2; /* mark group as finished */
519 } 581 }
520 582
521 errno = req->errorno; 583 errno = req->errorno;
522 584
523 PUTBACK; 585 PUTBACK;
524 call_sv (req->callback, G_VOID | G_EVAL); 586 call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD);
525 SPAGAIN; 587 SPAGAIN;
526 588
527 FREETMPS; 589 FREETMPS;
528 LEAVE; 590 LEAVE;
591
592 PUTBACK;
529 } 593 }
530 594
531 if (req->grp) 595 if (req->grp)
532 { 596 {
533 aio_req grp = req->grp; 597 aio_req grp = req->grp;
582 req->flags |= FLAG_CANCELLED; 646 req->flags |= FLAG_CANCELLED;
583 647
584 req_cancel_subs (req); 648 req_cancel_subs (req);
585} 649}
586 650
587static void *aio_proc (void *arg); 651#ifdef USE_SOCKETS_AS_HANDLES
652# define TO_SOCKET(x) (win32_get_osfhandle (x))
653#else
654# define TO_SOCKET(x) (x)
655#endif
656
657static void
658create_respipe (void)
659{
660 int old_readfd = respipe [0];
661
662 if (respipe [1] >= 0)
663 respipe_close (TO_SOCKET (respipe [1]));
664
665#ifdef _WIN32
666 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
667#else
668 if (pipe (respipe))
669#endif
670 croak ("unable to initialize result pipe");
671
672 if (old_readfd >= 0)
673 {
674 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
675 croak ("unable to initialize result pipe(2)");
676
677 respipe_close (respipe [0]);
678 respipe [0] = old_readfd;
679 }
680
681#ifdef _WIN32
682 int arg = 1;
683 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
684 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
685#else
686 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
687 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
688#endif
689 croak ("unable to initialize result pipe(3)");
690
691 respipe_osf [0] = TO_SOCKET (respipe [0]);
692 respipe_osf [1] = TO_SOCKET (respipe [1]);
693}
694
695X_THREAD_PROC (aio_proc);
588 696
589static void start_thread (void) 697static void start_thread (void)
590{ 698{
591 worker *wrk = calloc (1, sizeof (worker)); 699 worker *wrk = calloc (1, sizeof (worker));
592 700
593 if (!wrk) 701 if (!wrk)
594 croak ("unable to allocate worker thread data"); 702 croak ("unable to allocate worker thread data");
595 703
596 LOCK (wrklock); 704 X_LOCK (wrklock);
597 705
598 if (thread_create (&wrk->tid, aio_proc, (void *)wrk)) 706 if (thread_create (&wrk->tid, aio_proc, (void *)wrk))
599 { 707 {
600 wrk->prev = &wrk_first; 708 wrk->prev = &wrk_first;
601 wrk->next = wrk_first.next; 709 wrk->next = wrk_first.next;
604 ++started; 712 ++started;
605 } 713 }
606 else 714 else
607 free (wrk); 715 free (wrk);
608 716
609 UNLOCK (wrklock); 717 X_UNLOCK (wrklock);
610} 718}
611 719
612static void maybe_start_thread () 720static void maybe_start_thread (void)
613{ 721{
614 if (get_nthreads () >= wanted) 722 if (get_nthreads () >= wanted)
615 return; 723 return;
616 724
617 /* todo: maybe use idle here, but might be less exact */ 725 /* todo: maybe use idle here, but might be less exact */
625{ 733{
626 block_sig (); 734 block_sig ();
627 735
628 ++nreqs; 736 ++nreqs;
629 737
630 LOCK (reqlock); 738 X_LOCK (reqlock);
631 ++nready; 739 ++nready;
632 reqq_push (&req_queue, req); 740 reqq_push (&req_queue, req);
633 COND_SIGNAL (reqwait); 741 X_COND_SIGNAL (reqwait);
634 UNLOCK (reqlock); 742 X_UNLOCK (reqlock);
635 743
636 unblock_sig (); 744 unblock_sig ();
637 745
638 maybe_start_thread (); 746 maybe_start_thread ();
639} 747}
645 Newz (0, req, 1, aio_cb); 753 Newz (0, req, 1, aio_cb);
646 754
647 req->type = REQ_QUIT; 755 req->type = REQ_QUIT;
648 req->pri = PRI_MAX + PRI_BIAS; 756 req->pri = PRI_MAX + PRI_BIAS;
649 757
650 LOCK (reqlock); 758 X_LOCK (reqlock);
651 reqq_push (&req_queue, req); 759 reqq_push (&req_queue, req);
652 COND_SIGNAL (reqwait); 760 X_COND_SIGNAL (reqwait);
653 UNLOCK (reqlock); 761 X_UNLOCK (reqlock);
654 762
655 LOCK (wrklock); 763 X_LOCK (wrklock);
656 --started; 764 --started;
657 UNLOCK (wrklock); 765 X_UNLOCK (wrklock);
658} 766}
659 767
660static void set_max_idle (int nthreads) 768static void set_max_idle (int nthreads)
661{ 769{
662 if (WORDACCESS_UNSAFE) LOCK (reqlock); 770 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
663 max_idle = nthreads <= 0 ? 1 : nthreads; 771 max_idle = nthreads <= 0 ? 1 : nthreads;
664 if (WORDACCESS_UNSAFE) UNLOCK (reqlock); 772 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
665} 773}
666 774
667static void min_parallel (int nthreads) 775static void min_parallel (int nthreads)
668{ 776{
669 if (wanted < nthreads) 777 if (wanted < nthreads)
677 785
678 while (started > wanted) 786 while (started > wanted)
679 end_thread (); 787 end_thread ();
680} 788}
681 789
682static void poll_wait () 790static void poll_wait (void)
683{ 791{
684 fd_set rfd; 792 fd_set rfd;
685 793
686 while (nreqs) 794 while (nreqs)
687 { 795 {
688 int size; 796 int size;
689 if (WORDACCESS_UNSAFE) LOCK (reslock); 797 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
690 size = res_queue.size; 798 size = res_queue.size;
691 if (WORDACCESS_UNSAFE) UNLOCK (reslock); 799 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock);
692 800
693 if (size) 801 if (size)
694 return; 802 return;
695 803
696 maybe_start_thread (); 804 maybe_start_thread ();
697 805
698 FD_ZERO(&rfd); 806 FD_ZERO (&rfd);
699 FD_SET(respipe [0], &rfd); 807 FD_SET (respipe [0], &rfd);
700 808
701 select (respipe [0] + 1, &rfd, 0, 0, 0); 809 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
702 } 810 }
703} 811}
704 812
705static int poll_cb () 813static int poll_cb (void)
706{ 814{
707 dSP; 815 dSP;
708 int count = 0; 816 int count = 0;
709 int maxreqs = max_poll_reqs; 817 int maxreqs = max_poll_reqs;
710 int do_croak = 0; 818 int do_croak = 0;
720 { 828 {
721 for (;;) 829 for (;;)
722 { 830 {
723 maybe_start_thread (); 831 maybe_start_thread ();
724 832
725 LOCK (reslock); 833 X_LOCK (reslock);
726 req = reqq_shift (&res_queue); 834 req = reqq_shift (&res_queue);
727 835
728 if (req) 836 if (req)
729 { 837 {
730 --npending; 838 --npending;
731 839
732 if (!res_queue.size) 840 if (!res_queue.size)
733 { 841 {
734 /* read any signals sent by the worker threads */ 842 /* read any signals sent by the worker threads */
735 char buf [4]; 843 char buf [4];
736 while (read (respipe [0], buf, 4) == 4) 844 while (respipe_read (respipe [0], buf, 4) == 4)
737 ; 845 ;
738 } 846 }
739 } 847 }
740 848
741 UNLOCK (reslock); 849 X_UNLOCK (reslock);
742 850
743 if (!req) 851 if (!req)
744 break; 852 break;
745 853
746 --nreqs; 854 --nreqs;
786 894
787 unblock_sig (); 895 unblock_sig ();
788 return count; 896 return count;
789} 897}
790 898
791static void create_pipe ()
792{
793 if (pipe (respipe))
794 croak ("unable to initialize result pipe");
795
796 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK))
797 croak ("cannot set result pipe to nonblocking mode");
798
799 if (fcntl (respipe [1], F_SETFL, O_NONBLOCK))
800 croak ("cannot set result pipe to nonblocking mode");
801}
802
803/*****************************************************************************/ 899/*****************************************************************************/
804/* work around various missing functions */ 900/* work around various missing functions */
805 901
806#if !HAVE_PREADWRITE 902#if !HAVE_PREADWRITE
807# define pread aio_pread 903# define pread aio_pread
810/* 906/*
811 * make our pread/pwrite safe against themselves, but not against 907 * make our pread/pwrite safe against themselves, but not against
812 * normal read/write by using a mutex. slows down execution a lot, 908 * normal read/write by using a mutex. slows down execution a lot,
813 * but that's your problem, not mine. 909 * but that's your problem, not mine.
814 */ 910 */
815static mutex_t preadwritelock = MUTEX_INIT; 911static mutex_t preadwritelock = X_MUTEX_INIT;
816 912
817static ssize_t pread (int fd, void *buf, size_t count, off_t offset) 913static ssize_t pread (int fd, void *buf, size_t count, off_t offset)
818{ 914{
819 ssize_t res; 915 ssize_t res;
820 off_t ooffset; 916 off_t ooffset;
821 917
822 LOCK (preadwritelock); 918 X_LOCK (preadwritelock);
823 ooffset = lseek (fd, 0, SEEK_CUR); 919 ooffset = lseek (fd, 0, SEEK_CUR);
824 lseek (fd, offset, SEEK_SET); 920 lseek (fd, offset, SEEK_SET);
825 res = read (fd, buf, count); 921 res = read (fd, buf, count);
826 lseek (fd, ooffset, SEEK_SET); 922 lseek (fd, ooffset, SEEK_SET);
827 UNLOCK (preadwritelock); 923 X_UNLOCK (preadwritelock);
828 924
829 return res; 925 return res;
830} 926}
831 927
832static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset) 928static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset)
833{ 929{
834 ssize_t res; 930 ssize_t res;
835 off_t ooffset; 931 off_t ooffset;
836 932
837 LOCK (preadwritelock); 933 X_LOCK (preadwritelock);
838 ooffset = lseek (fd, 0, SEEK_CUR); 934 ooffset = lseek (fd, 0, SEEK_CUR);
839 lseek (fd, offset, SEEK_SET); 935 lseek (fd, offset, SEEK_SET);
840 res = write (fd, buf, count); 936 res = write (fd, buf, count);
841 lseek (fd, offset, SEEK_SET); 937 lseek (fd, offset, SEEK_SET);
842 UNLOCK (preadwritelock); 938 X_UNLOCK (preadwritelock);
843 939
844 return res; 940 return res;
845} 941}
846#endif 942#endif
847 943
880#if !HAVE_READAHEAD 976#if !HAVE_READAHEAD
881# define readahead(fd,offset,count) aio_readahead (fd, offset, count, self) 977# define readahead(fd,offset,count) aio_readahead (fd, offset, count, self)
882 978
883static ssize_t aio_readahead (int fd, off_t offset, size_t count, worker *self) 979static ssize_t aio_readahead (int fd, off_t offset, size_t count, worker *self)
884{ 980{
981 size_t todo = count;
885 dBUF; 982 dBUF;
886 983
887 while (count > 0) 984 while (todo > 0)
888 { 985 {
889 size_t len = count < AIO_BUFSIZE ? count : AIO_BUFSIZE; 986 size_t len = todo < AIO_BUFSIZE ? todo : AIO_BUFSIZE;
890 987
891 pread (fd, aio_buf, len, offset); 988 pread (fd, aio_buf, len, offset);
892 offset += len; 989 offset += len;
893 count -= len; 990 todo -= len;
894 } 991 }
895 992
896 errno = 0; 993 errno = 0;
994 return count;
897} 995}
898 996
899#endif 997#endif
900 998
901#if !HAVE_READDIR_R 999#if !HAVE_READDIR_R
902# define readdir_r aio_readdir_r 1000# define readdir_r aio_readdir_r
903 1001
904static mutex_t readdirlock = MUTEX_INIT; 1002static mutex_t readdirlock = X_MUTEX_INIT;
905 1003
906static int readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) 1004static int readdir_r (DIR *dirp, X_DIRENT *ent, X_DIRENT **res)
907{ 1005{
908 struct dirent *e; 1006 X_DIRENT *e;
909 int errorno; 1007 int errorno;
910 1008
911 LOCK (readdirlock); 1009 X_LOCK (readdirlock);
912 1010
913 e = readdir (dirp); 1011 e = readdir (dirp);
914 errorno = errno; 1012 errorno = errno;
915 1013
916 if (e) 1014 if (e)
919 strcpy (ent->d_name, e->d_name); 1017 strcpy (ent->d_name, e->d_name);
920 } 1018 }
921 else 1019 else
922 *res = 0; 1020 *res = 0;
923 1021
924 UNLOCK (readdirlock); 1022 X_UNLOCK (readdirlock);
925 1023
926 errno = errorno; 1024 errno = errorno;
927 return e ? 0 : -1; 1025 return e ? 0 : -1;
928} 1026}
929#endif 1027#endif
1025static void scandir_ (aio_req req, worker *self) 1123static void scandir_ (aio_req req, worker *self)
1026{ 1124{
1027 DIR *dirp; 1125 DIR *dirp;
1028 union 1126 union
1029 { 1127 {
1030 struct dirent d; 1128 X_DIRENT d;
1031 char b [offsetof (struct dirent, d_name) + NAME_MAX + 1]; 1129 char b [offsetof (X_DIRENT, d_name) + NAME_MAX + 1];
1032 } *u; 1130 } *u;
1033 struct dirent *entp; 1131 X_DIRENT *entp;
1034 char *name, *names; 1132 char *name, *names;
1035 int memlen = 4096; 1133 int memlen = 4096;
1036 int memofs = 0; 1134 int memofs = 0;
1037 int res = 0; 1135 int res = 0;
1038 int errorno;
1039 1136
1040 LOCK (wrklock); 1137 X_LOCK (wrklock);
1041 self->dirp = dirp = opendir (req->ptr1); 1138 self->dirp = dirp = opendir (req->ptr1);
1042 self->dbuf = u = malloc (sizeof (*u)); 1139 self->dbuf = u = malloc (sizeof (*u));
1043 req->flags |= FLAG_PTR2_FREE; 1140 req->flags |= FLAG_PTR2_FREE;
1044 req->ptr2 = names = malloc (memlen); 1141 req->ptr2 = names = malloc (memlen);
1045 UNLOCK (wrklock); 1142 X_UNLOCK (wrklock);
1046 1143
1047 if (dirp && u && names) 1144 if (dirp && u && names)
1048 for (;;) 1145 for (;;)
1049 { 1146 {
1050 errno = 0; 1147 errno = 0;
1062 res++; 1159 res++;
1063 1160
1064 while (memofs + len > memlen) 1161 while (memofs + len > memlen)
1065 { 1162 {
1066 memlen *= 2; 1163 memlen *= 2;
1067 LOCK (wrklock); 1164 X_LOCK (wrklock);
1068 req->ptr2 = names = realloc (names, memlen); 1165 req->ptr2 = names = realloc (names, memlen);
1069 UNLOCK (wrklock); 1166 X_UNLOCK (wrklock);
1070 1167
1071 if (!names) 1168 if (!names)
1072 break; 1169 break;
1073 } 1170 }
1074 1171
1081 res = -1; 1178 res = -1;
1082 1179
1083 req->result = res; 1180 req->result = res;
1084} 1181}
1085 1182
1183static int
1184aio_close (int fd)
1185{
1186 static int close_pipe = -1; /* dummy fd to close fds via dup2 */
1187
1188 X_LOCK (wrklock);
1189
1190 if (close_pipe < 0)
1191 {
1192 int pipefd [2];
1193
1194 if (pipe (pipefd) < 0
1195 || close (pipefd [1]) < 0
1196 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0)
1197 {
1198 X_UNLOCK (wrklock);
1199 return -1;
1200 }
1201
1202 close_pipe = pipefd [0];
1203 }
1204
1205 X_UNLOCK (wrklock);
1206
1207 return dup2 (close_pipe, fd) < 0 ? -1 : 0;
1208}
1209
1086/*****************************************************************************/ 1210/*****************************************************************************/
1087 1211
1088static void *aio_proc (void *thr_arg) 1212X_THREAD_PROC (aio_proc)
1089{ 1213{
1090 aio_req req; 1214 aio_req req;
1091 struct timespec ts; 1215 struct timespec ts;
1092 worker *self = (worker *)thr_arg; 1216 worker *self = (worker *)thr_arg;
1093 1217
1094 /* try to distribute timeouts somewhat evenly */ 1218 /* try to distribute timeouts somewhat randomly */
1095 ts.tv_nsec = (((unsigned long)self + (unsigned long)ts.tv_sec) & 1023UL) 1219 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
1096 * (1000000000UL / 1024UL);
1097 1220
1098 for (;;) 1221 for (;;)
1099 { 1222 {
1100 ts.tv_sec = time (0) + IDLE_TIMEOUT; 1223 ts.tv_sec = time (0) + IDLE_TIMEOUT;
1101 1224
1102 LOCK (reqlock); 1225 X_LOCK (reqlock);
1103 1226
1104 for (;;) 1227 for (;;)
1105 { 1228 {
1106 self->req = req = reqq_shift (&req_queue); 1229 self->req = req = reqq_shift (&req_queue);
1107 1230
1108 if (req) 1231 if (req)
1109 break; 1232 break;
1110 1233
1111 ++idle; 1234 ++idle;
1112 1235
1113 if (COND_TIMEDWAIT (reqwait, reqlock, ts) 1236 if (X_COND_TIMEDWAIT (reqwait, reqlock, ts)
1114 == ETIMEDOUT) 1237 == ETIMEDOUT)
1115 { 1238 {
1116 if (idle > max_idle) 1239 if (idle > max_idle)
1117 { 1240 {
1118 --idle; 1241 --idle;
1119 UNLOCK (reqlock); 1242 X_UNLOCK (reqlock);
1120 LOCK (wrklock); 1243 X_LOCK (wrklock);
1121 --started; 1244 --started;
1122 UNLOCK (wrklock); 1245 X_UNLOCK (wrklock);
1123 goto quit; 1246 goto quit;
1124 } 1247 }
1125 1248
1126 /* we are allowed to idle, so do so without any timeout */ 1249 /* we are allowed to idle, so do so without any timeout */
1127 COND_WAIT (reqwait, reqlock); 1250 X_COND_WAIT (reqwait, reqlock);
1128 ts.tv_sec = time (0) + IDLE_TIMEOUT; 1251 ts.tv_sec = time (0) + IDLE_TIMEOUT;
1129 } 1252 }
1130 1253
1131 --idle; 1254 --idle;
1132 } 1255 }
1133 1256
1134 --nready; 1257 --nready;
1135 1258
1136 UNLOCK (reqlock); 1259 X_UNLOCK (reqlock);
1137 1260
1138 errno = 0; /* strictly unnecessary */ 1261 errno = 0; /* strictly unnecessary */
1139 1262
1140 if (!(req->flags & FLAG_CANCELLED)) 1263 if (!(req->flags & FLAG_CANCELLED))
1141 switch (req->type) 1264 switch (req->type)
1156 1279
1157 case REQ_CHOWN: req->result = chown (req->ptr1, req->int2, req->int3); break; 1280 case REQ_CHOWN: req->result = chown (req->ptr1, req->int2, req->int3); break;
1158 case REQ_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; 1281 case REQ_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break;
1159 case REQ_CHMOD: req->result = chmod (req->ptr1, req->mode); break; 1282 case REQ_CHMOD: req->result = chmod (req->ptr1, req->mode); break;
1160 case REQ_FCHMOD: req->result = fchmod (req->int1, req->mode); break; 1283 case REQ_FCHMOD: req->result = fchmod (req->int1, req->mode); break;
1284 case REQ_TRUNCATE: req->result = truncate (req->ptr1, req->offs); break;
1285 case REQ_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break;
1161 1286
1162 case REQ_OPEN: req->result = open (req->ptr1, req->int1, req->mode); break; 1287 case REQ_OPEN: req->result = open (req->ptr1, req->int1, req->mode); break;
1163 case REQ_CLOSE: req->result = close (req->int1); break; 1288 case REQ_CLOSE: req->result = aio_close (req->int1); break;
1164 case REQ_UNLINK: req->result = unlink (req->ptr1); break; 1289 case REQ_UNLINK: req->result = unlink (req->ptr1); break;
1165 case REQ_RMDIR: req->result = rmdir (req->ptr1); break; 1290 case REQ_RMDIR: req->result = rmdir (req->ptr1); break;
1166 case REQ_MKDIR: req->result = mkdir (req->ptr1, req->mode); break; 1291 case REQ_MKDIR: req->result = mkdir (req->ptr1, req->mode); break;
1167 case REQ_RENAME: req->result = rename (req->ptr2, req->ptr1); break; 1292 case REQ_RENAME: req->result = rename (req->ptr2, req->ptr1); break;
1168 case REQ_LINK: req->result = link (req->ptr2, req->ptr1); break; 1293 case REQ_LINK: req->result = link (req->ptr2, req->ptr1); break;
1169 case REQ_SYMLINK: req->result = symlink (req->ptr2, req->ptr1); break; 1294 case REQ_SYMLINK: req->result = symlink (req->ptr2, req->ptr1); break;
1170 case REQ_MKNOD: req->result = mknod (req->ptr2, req->mode, (dev_t)req->offs); break; 1295 case REQ_MKNOD: req->result = mknod (req->ptr2, req->mode, (dev_t)req->offs); break;
1171 case REQ_READLINK: req->result = readlink (req->ptr2, req->ptr1, NAME_MAX); break; 1296 case REQ_READLINK: req->result = readlink (req->ptr2, req->ptr1, NAME_MAX); break;
1172 1297
1298 case REQ_SYNC: req->result = 0; sync (); break;
1299 case REQ_FSYNC: req->result = fsync (req->int1); break;
1173 case REQ_FDATASYNC: req->result = fdatasync (req->int1); break; 1300 case REQ_FDATASYNC: req->result = fdatasync (req->int1); break;
1174 case REQ_FSYNC: req->result = fsync (req->int1); break; 1301
1175 case REQ_READDIR: scandir_ (req, self); break; 1302 case REQ_READDIR: scandir_ (req, self); break;
1176 1303
1177 case REQ_BUSY: 1304 case REQ_BUSY:
1305#ifdef _WIN32
1306 Sleep (req->nv1 * 1000.);
1307#else
1178 { 1308 {
1179 struct timeval tv; 1309 struct timeval tv;
1180 1310
1181 tv.tv_sec = req->nv1; 1311 tv.tv_sec = req->nv1;
1182 tv.tv_usec = (req->nv1 - tv.tv_usec) * 1000000.; 1312 tv.tv_usec = (req->nv1 - tv.tv_sec) * 1000000.;
1183 1313
1184 req->result = select (0, 0, 0, 0, &tv); 1314 req->result = select (0, 0, 0, 0, &tv);
1185 } 1315 }
1316#endif
1317 break;
1186 1318
1187 case REQ_UTIME: 1319 case REQ_UTIME:
1188 case REQ_FUTIME: 1320 case REQ_FUTIME:
1189 { 1321 {
1190 struct timeval tv[2]; 1322 struct timeval tv[2];
1220 break; 1352 break;
1221 } 1353 }
1222 1354
1223 req->errorno = errno; 1355 req->errorno = errno;
1224 1356
1225 LOCK (reslock); 1357 X_LOCK (reslock);
1226 1358
1227 ++npending; 1359 ++npending;
1228 1360
1229 if (!reqq_push (&res_queue, req)) 1361 if (!reqq_push (&res_queue, req))
1230 { 1362 {
1231 /* write a dummy byte to the pipe so fh becomes ready */ 1363 /* write a dummy byte to the pipe so fh becomes ready */
1232 write (respipe [1], &respipe, 1); 1364 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
1233 1365
1234 /* optionally signal the main thread asynchronously */ 1366 /* optionally signal the main thread asynchronously */
1235 if (main_sig) 1367 if (main_sig)
1236 pthread_kill (main_tid, main_sig); 1368 pthread_kill (main_tid, main_sig);
1237 } 1369 }
1238 1370
1239 self->req = 0; 1371 self->req = 0;
1240 worker_clear (self); 1372 worker_clear (self);
1241 1373
1242 UNLOCK (reslock); 1374 X_UNLOCK (reslock);
1243 } 1375 }
1244 1376
1245quit: 1377quit:
1246 LOCK (wrklock); 1378 X_LOCK (wrklock);
1247 worker_free (self); 1379 worker_free (self);
1248 UNLOCK (wrklock); 1380 X_UNLOCK (wrklock);
1249 1381
1250 return 0; 1382 return 0;
1251} 1383}
1252 1384
1253/*****************************************************************************/ 1385/*****************************************************************************/
1254 1386
1255static void atfork_prepare (void) 1387static void atfork_prepare (void)
1256{ 1388{
1257 LOCK (wrklock); 1389 X_LOCK (wrklock);
1258 LOCK (reqlock); 1390 X_LOCK (reqlock);
1259 LOCK (reslock); 1391 X_LOCK (reslock);
1260#if !HAVE_PREADWRITE 1392#if !HAVE_PREADWRITE
1261 LOCK (preadwritelock); 1393 X_LOCK (preadwritelock);
1262#endif 1394#endif
1263#if !HAVE_READDIR_R 1395#if !HAVE_READDIR_R
1264 LOCK (readdirlock); 1396 X_LOCK (readdirlock);
1265#endif 1397#endif
1266} 1398}
1267 1399
1268static void atfork_parent (void) 1400static void atfork_parent (void)
1269{ 1401{
1270#if !HAVE_READDIR_R 1402#if !HAVE_READDIR_R
1271 UNLOCK (readdirlock); 1403 X_UNLOCK (readdirlock);
1272#endif 1404#endif
1273#if !HAVE_PREADWRITE 1405#if !HAVE_PREADWRITE
1274 UNLOCK (preadwritelock); 1406 X_UNLOCK (preadwritelock);
1275#endif 1407#endif
1276 UNLOCK (reslock); 1408 X_UNLOCK (reslock);
1277 UNLOCK (reqlock); 1409 X_UNLOCK (reqlock);
1278 UNLOCK (wrklock); 1410 X_UNLOCK (wrklock);
1279} 1411}
1280 1412
1281static void atfork_child (void) 1413static void atfork_child (void)
1282{ 1414{
1283 aio_req prv; 1415 aio_req prv;
1303 idle = 0; 1435 idle = 0;
1304 nreqs = 0; 1436 nreqs = 0;
1305 nready = 0; 1437 nready = 0;
1306 npending = 0; 1438 npending = 0;
1307 1439
1308 close (respipe [0]);
1309 close (respipe [1]);
1310 create_pipe (); 1440 create_respipe ();
1311 1441
1312 atfork_parent (); 1442 atfork_parent ();
1313} 1443}
1314 1444
1315#define dREQ \ 1445#define dREQ \
1337 1467
1338PROTOTYPES: ENABLE 1468PROTOTYPES: ENABLE
1339 1469
1340BOOT: 1470BOOT:
1341{ 1471{
1342 HV *stash = gv_stashpv ("IO::AIO", 1); 1472 stash = gv_stashpv ("IO::AIO", 1);
1343 1473
1344 newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); 1474 newCONSTSUB (stash, "EXDEV", newSViv (EXDEV));
1345 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); 1475 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY));
1346 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); 1476 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY));
1347 newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); 1477 newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT));
1348 newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); 1478 newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC));
1479#ifdef _WIN32
1480 X_MUTEX_CHECK (wrklock);
1481 X_MUTEX_CHECK (reslock);
1482 X_MUTEX_CHECK (reqlock);
1483 X_MUTEX_CHECK (reqwait);
1484 X_MUTEX_CHECK (preadwritelock);
1485 X_MUTEX_CHECK (readdirlock);
1486
1487 X_COND_CHECK (reqwait);
1488#else
1349 newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); 1489 newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO));
1350 newCONSTSUB (stash, "SIGIO", newSViv (SIGIO)); 1490 newCONSTSUB (stash, "SIGIO", newSViv (SIGIO));
1491#endif
1351 1492
1352 create_pipe (); 1493 create_respipe ();
1494
1353 ATFORK (atfork_prepare, atfork_parent, atfork_child); 1495 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1354} 1496}
1355 1497
1356void 1498void
1357max_poll_reqs (int nreqs) 1499max_poll_reqs (int nreqs)
1358 PROTOTYPE: $ 1500 PROTOTYPE: $
1403 1545
1404 REQ_SEND; 1546 REQ_SEND;
1405} 1547}
1406 1548
1407void 1549void
1408aio_close (SV *fh, SV *callback=&PL_sv_undef) 1550aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
1409 PROTOTYPE: $;$ 1551 PROTOTYPE: $;$
1410 ALIAS: 1552 ALIAS:
1411 aio_close = REQ_CLOSE
1412 aio_fsync = REQ_FSYNC 1553 aio_fsync = REQ_FSYNC
1413 aio_fdatasync = REQ_FDATASYNC 1554 aio_fdatasync = REQ_FDATASYNC
1414 PPCODE: 1555 PPCODE:
1415{ 1556{
1416 dREQ; 1557 dREQ;
1421 1562
1422 REQ_SEND (req); 1563 REQ_SEND (req);
1423} 1564}
1424 1565
1425void 1566void
1567aio_close (SV *fh, SV *callback=&PL_sv_undef)
1568 PROTOTYPE: $;$
1569 PPCODE:
1570{
1571 dREQ;
1572
1573 req->type = REQ_CLOSE;
1574 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh)));
1575
1576 REQ_SEND (req);
1577}
1578
1579void
1426aio_read (SV *fh, SV *offset, UV length, SV8 *data, UV dataoffset, SV *callback=&PL_sv_undef) 1580aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef)
1427 ALIAS: 1581 ALIAS:
1428 aio_read = REQ_READ 1582 aio_read = REQ_READ
1429 aio_write = REQ_WRITE 1583 aio_write = REQ_WRITE
1430 PROTOTYPE: $$$$$;$ 1584 PROTOTYPE: $$$$$;$
1431 PPCODE: 1585 PPCODE:
1432{ 1586{
1433 STRLEN svlen; 1587 STRLEN svlen;
1434 char *svptr = SvPVbyte (data, svlen); 1588 char *svptr = SvPVbyte (data, svlen);
1589 UV len = SvUV (length);
1435 1590
1436 SvUPGRADE (data, SVt_PV); 1591 SvUPGRADE (data, SVt_PV);
1437 SvPOK_on (data); 1592 SvPOK_on (data);
1438 1593
1439 if (dataoffset < 0) 1594 if (dataoffset < 0)
1440 dataoffset += svlen; 1595 dataoffset += svlen;
1441 1596
1442 if (dataoffset < 0 || dataoffset > svlen) 1597 if (dataoffset < 0 || dataoffset > svlen)
1443 croak ("data offset outside of string"); 1598 croak ("dataoffset outside of data scalar");
1444 1599
1445 if (ix == REQ_WRITE) 1600 if (ix == REQ_WRITE)
1446 { 1601 {
1447 /* write: check length and adjust. */ 1602 /* write: check length and adjust. */
1448 if (length < 0 || length + dataoffset > svlen) 1603 if (!SvOK (length) || len + dataoffset > svlen)
1449 length = svlen - dataoffset; 1604 len = svlen - dataoffset;
1450 } 1605 }
1451 else 1606 else
1452 { 1607 {
1453 /* read: grow scalar as necessary */ 1608 /* read: grow scalar as necessary */
1454 svptr = SvGROW (data, length + dataoffset + 1); 1609 svptr = SvGROW (data, len + dataoffset + 1);
1455 } 1610 }
1456 1611
1457 if (length < 0) 1612 if (len < 0)
1458 croak ("length must not be negative"); 1613 croak ("length must not be negative");
1459 1614
1460 { 1615 {
1461 dREQ; 1616 dREQ;
1462 1617
1463 req->type = ix; 1618 req->type = ix;
1464 req->sv1 = newSVsv (fh); 1619 req->sv1 = newSVsv (fh);
1465 req->int1 = PerlIO_fileno (ix == REQ_READ ? IoIFP (sv_2io (fh)) 1620 req->int1 = PerlIO_fileno (ix == REQ_READ ? IoIFP (sv_2io (fh))
1466 : IoOFP (sv_2io (fh))); 1621 : IoOFP (sv_2io (fh)));
1467 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; 1622 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
1468 req->size = length; 1623 req->size = len;
1469 req->sv2 = SvREFCNT_inc (data); 1624 req->sv2 = SvREFCNT_inc (data);
1470 req->ptr1 = (char *)svptr + dataoffset; 1625 req->ptr1 = (char *)svptr + dataoffset;
1471 req->stroffset = dataoffset; 1626 req->stroffset = dataoffset;
1472 1627
1473 if (!SvREADONLY (data)) 1628 if (!SvREADONLY (data))
1590 1745
1591 REQ_SEND; 1746 REQ_SEND;
1592} 1747}
1593 1748
1594void 1749void
1750aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef)
1751 PPCODE:
1752{
1753 dREQ;
1754
1755 req->sv1 = newSVsv (fh_or_path);
1756 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
1757
1758 if (SvPOK (fh_or_path))
1759 {
1760 req->type = REQ_TRUNCATE;
1761 req->ptr1 = SvPVbyte_nolen (req->sv1);
1762 }
1763 else
1764 {
1765 req->type = REQ_FTRUNCATE;
1766 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1767 }
1768
1769 REQ_SEND;
1770}
1771
1772void
1595aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) 1773aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef)
1596 PPCODE: 1774 PPCODE:
1597{ 1775{
1598 dREQ; 1776 dREQ;
1599 1777
1728 XPUSHs (req_sv (req, AIO_GRP_KLASS)); 1906 XPUSHs (req_sv (req, AIO_GRP_KLASS));
1729} 1907}
1730 1908
1731void 1909void
1732aio_nop (SV *callback=&PL_sv_undef) 1910aio_nop (SV *callback=&PL_sv_undef)
1911 ALIAS:
1912 aio_nop = REQ_NOP
1913 aio_sync = REQ_SYNC
1733 PPCODE: 1914 PPCODE:
1734{ 1915{
1735 dREQ; 1916 dREQ;
1736 1917
1737 req->type = REQ_NOP; 1918 req->type = ix;
1738 1919
1739 REQ_SEND; 1920 REQ_SEND;
1740} 1921}
1741 1922
1742int 1923int
1808 CODE: 1989 CODE:
1809{ 1990{
1810 if (block_sig_level) 1991 if (block_sig_level)
1811 croak ("cannot call IO::AIO::setsig from within aio_block/callback"); 1992 croak ("cannot call IO::AIO::setsig from within aio_block/callback");
1812 1993
1813 LOCK (reslock); 1994 X_LOCK (reslock);
1814 main_tid = pthread_self (); 1995 main_tid = pthread_self ();
1815 main_sig = signum; 1996 main_sig = signum;
1816 UNLOCK (reslock); 1997 X_UNLOCK (reslock);
1817 1998
1818 if (main_sig && npending) 1999 if (main_sig && npending)
1819 pthread_kill (main_tid, main_sig); 2000 pthread_kill (main_tid, main_sig);
1820} 2001}
1821 2002
1828 2009
1829 block_sig (); 2010 block_sig ();
1830 PUSHMARK (SP); 2011 PUSHMARK (SP);
1831 PUTBACK; 2012 PUTBACK;
1832 count = call_sv (cb, GIMME_V | G_NOARGS | G_EVAL); 2013 count = call_sv (cb, GIMME_V | G_NOARGS | G_EVAL);
1833 SPAGAIN;
1834 unblock_sig (); 2014 unblock_sig ();
1835 2015
1836 if (SvTRUE (ERRSV)) 2016 if (SvTRUE (ERRSV))
1837 croak (0); 2017 croak (0);
1838 2018
1865 2045
1866int 2046int
1867nthreads() 2047nthreads()
1868 PROTOTYPE: 2048 PROTOTYPE:
1869 CODE: 2049 CODE:
1870 if (WORDACCESS_UNSAFE) LOCK (wrklock); 2050 if (WORDACCESS_UNSAFE) X_LOCK (wrklock);
1871 RETVAL = started; 2051 RETVAL = started;
1872 if (WORDACCESS_UNSAFE) UNLOCK (wrklock); 2052 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock);
1873 OUTPUT: 2053 OUTPUT:
1874 RETVAL 2054 RETVAL
1875 2055
1876PROTOTYPES: DISABLE 2056PROTOTYPES: DISABLE
1877 2057

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines