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.93 by root, Wed Nov 8 02:01:02 2006 UTC vs.
Revision 1.98 by root, Wed May 9 06:45:12 2007 UTC

1/* solaris */ 1#include "xthread.h"
2#define _POSIX_PTHREAD_SEMANTICS 1
3
4#if __linux && !defined(_GNU_SOURCE)
5# define _GNU_SOURCE
6#endif
7
8/* just in case */
9#define _REENTRANT 1
10 2
11#include <errno.h> 3#include <errno.h>
12 4
13#include "EXTERN.h" 5#include "EXTERN.h"
14#include "perl.h" 6#include "perl.h"
15#include "XSUB.h" 7#include "XSUB.h"
16 8
17#include "autoconf/config.h" 9#include "autoconf/config.h"
18 10
19#include <pthread.h>
20
21#include <stddef.h> 11#include <stddef.h>
12#include <stdlib.h>
22#include <errno.h> 13#include <errno.h>
23#include <sys/time.h> 14#include <sys/time.h>
24#include <sys/select.h> 15#include <sys/select.h>
25#include <sys/types.h> 16#include <sys/types.h>
26#include <sys/stat.h> 17#include <sys/stat.h>
51/* used for struct dirent, AIX doesn't provide it */ 42/* used for struct dirent, AIX doesn't provide it */
52#ifndef NAME_MAX 43#ifndef NAME_MAX
53# define NAME_MAX 4096 44# define NAME_MAX 4096
54#endif 45#endif
55 46
56#ifndef PTHREAD_STACK_MIN
57/* care for broken platforms, e.g. windows */
58# define PTHREAD_STACK_MIN 16384
59#endif
60
61#if __ia64
62# define STACKSIZE 65536
63#elif __i386 || __x86_64 /* 16k is unreasonably high :( */
64# define STACKSIZE PTHREAD_STACK_MIN
65#else
66# define STACKSIZE 16384
67#endif
68
69/* wether word reads are potentially non-atomic.
70 * this is conservatice, likely most arches this runs
71 * on have atomic word read/writes.
72 */
73#ifndef WORDACCESS_UNSAFE
74# if __i386 || __x86_64
75# define WORDACCESS_UNSAFE 0
76# else
77# define WORDACCESS_UNSAFE 1
78# endif
79#endif
80
81/* buffer size for various temporary buffers */ 47/* buffer size for various temporary buffers */
82#define AIO_BUFSIZE 65536 48#define AIO_BUFSIZE 65536
83 49
84#define dBUF \ 50#define dBUF \
85 char *aio_buf; \ 51 char *aio_buf; \
96 REQ_OPEN, REQ_CLOSE, 62 REQ_OPEN, REQ_CLOSE,
97 REQ_READ, REQ_WRITE, REQ_READAHEAD, 63 REQ_READ, REQ_WRITE, REQ_READAHEAD,
98 REQ_SENDFILE, 64 REQ_SENDFILE,
99 REQ_STAT, REQ_LSTAT, REQ_FSTAT, 65 REQ_STAT, REQ_LSTAT, REQ_FSTAT,
100 REQ_FSYNC, REQ_FDATASYNC, 66 REQ_FSYNC, REQ_FDATASYNC,
101 REQ_UNLINK, REQ_RMDIR, REQ_RENAME, 67 REQ_UNLINK, REQ_RMDIR, REQ_MKDIR, REQ_RENAME,
102 REQ_MKNOD, REQ_READDIR, 68 REQ_MKNOD, REQ_READDIR,
103 REQ_LINK, REQ_SYMLINK, REQ_READLINK, 69 REQ_LINK, REQ_SYMLINK, REQ_READLINK,
104 REQ_GROUP, REQ_NOP, 70 REQ_GROUP, REQ_NOP,
105 REQ_BUSY, 71 REQ_BUSY,
106}; 72};
160{ 126{
161 return (tv2->tv_sec - tv1->tv_sec ) * AIO_TICKS 127 return (tv2->tv_sec - tv1->tv_sec ) * AIO_TICKS
162 + ((tv2->tv_usec - tv1->tv_usec) >> 10); 128 + ((tv2->tv_usec - tv1->tv_usec) >> 10);
163} 129}
164 130
131static thread_t main_tid;
132static int main_sig;
133static int block_sig_level;
134
135void block_sig ()
136{
137 sigset_t ss;
138
139 if (block_sig_level++)
140 return;
141
142 if (!main_sig)
143 return;
144
145 sigemptyset (&ss);
146 sigaddset (&ss, main_sig);
147 pthread_sigmask (SIG_BLOCK, &ss, 0);
148}
149
150void unblock_sig ()
151{
152 sigset_t ss;
153
154 if (--block_sig_level)
155 return;
156
157 if (!main_sig)
158 return;
159
160 sigemptyset (&ss);
161 sigaddset (&ss, main_sig);
162 pthread_sigmask (SIG_UNBLOCK, &ss, 0);
163}
164
165static int next_pri = DEFAULT_PRI + PRI_BIAS; 165static int next_pri = DEFAULT_PRI + PRI_BIAS;
166 166
167static unsigned int started, idle, wanted; 167static unsigned int started, idle, wanted;
168 168
169#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
170# define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
171#else
172# define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
173#endif
174
175#define LOCK(mutex) pthread_mutex_lock (&(mutex))
176#define UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
177
178/* worker threads management */ 169/* worker threads management */
179static pthread_mutex_t wrklock = AIO_MUTEX_INIT; 170static mutex_t wrklock = MUTEX_INIT;
180 171
181typedef struct worker { 172typedef struct worker {
182 /* locked by wrklock */ 173 /* locked by wrklock */
183 struct worker *prev, *next; 174 struct worker *prev, *next;
184 175
185 pthread_t tid; 176 thread_t tid;
186 177
187 /* locked by reslock, reqlock or wrklock */ 178 /* locked by reslock, reqlock or wrklock */
188 aio_req req; /* currently processed request */ 179 aio_req req; /* currently processed request */
189 void *dbuf; 180 void *dbuf;
190 DIR *dirp; 181 DIR *dirp;
218static volatile unsigned int nreqs, nready, npending; 209static volatile unsigned int nreqs, nready, npending;
219static volatile unsigned int max_idle = 4; 210static volatile unsigned int max_idle = 4;
220static volatile unsigned int max_outstanding = 0xffffffff; 211static volatile unsigned int max_outstanding = 0xffffffff;
221static int respipe [2]; 212static int respipe [2];
222 213
223static pthread_mutex_t reslock = AIO_MUTEX_INIT; 214static mutex_t reslock = MUTEX_INIT;
224static pthread_mutex_t reqlock = AIO_MUTEX_INIT; 215static mutex_t reqlock = MUTEX_INIT;
225static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; 216static cond_t reqwait = COND_INIT;
226 217
227#if WORDACCESS_UNSAFE 218#if WORDACCESS_UNSAFE
228 219
229static unsigned int get_nready () 220static unsigned int get_nready ()
230{ 221{
320 311
321 abort (); 312 abort ();
322} 313}
323 314
324static int poll_cb (); 315static int poll_cb ();
325static void req_invoke (aio_req req); 316static int req_invoke (aio_req req);
326static void req_free (aio_req req); 317static void req_free (aio_req req);
327static void req_cancel (aio_req req); 318static void req_cancel (aio_req req);
328 319
329/* must be called at most once */ 320/* must be called at most once */
330static SV *req_sv (aio_req req, const char *klass) 321static SV *req_sv (aio_req req, const char *klass)
350 return mg ? (aio_req)mg->mg_ptr : 0; 341 return mg ? (aio_req)mg->mg_ptr : 0;
351} 342}
352 343
353static void aio_grp_feed (aio_req grp) 344static void aio_grp_feed (aio_req grp)
354{ 345{
346 block_sig ();
347
355 while (grp->size < grp->int2 && !(grp->flags & FLAG_CANCELLED)) 348 while (grp->size < grp->int2 && !(grp->flags & FLAG_CANCELLED))
356 { 349 {
357 int old_len = grp->size; 350 int old_len = grp->size;
358 351
359 if (grp->sv2 && SvOK (grp->sv2)) 352 if (grp->sv2 && SvOK (grp->sv2))
377 SvREFCNT_dec (grp->sv2); 370 SvREFCNT_dec (grp->sv2);
378 grp->sv2 = 0; 371 grp->sv2 = 0;
379 break; 372 break;
380 } 373 }
381 } 374 }
375
376 unblock_sig ();
382} 377}
383 378
384static void aio_grp_dec (aio_req grp) 379static void aio_grp_dec (aio_req grp)
385{ 380{
386 --grp->size; 381 --grp->size;
389 aio_grp_feed (grp); 384 aio_grp_feed (grp);
390 385
391 /* finish, if done */ 386 /* finish, if done */
392 if (!grp->size && grp->int1) 387 if (!grp->size && grp->int1)
393 { 388 {
389 block_sig ();
390
394 req_invoke (grp); 391 if (!req_invoke (grp))
392 {
393 req_free (grp);
394 unblock_sig ();
395 croak (0);
396 }
397
395 req_free (grp); 398 req_free (grp);
399 unblock_sig ();
396 } 400 }
397} 401}
398 402
399static void req_invoke (aio_req req) 403static int req_invoke (aio_req req)
400{ 404{
401 dSP; 405 dSP;
402 406
403 if (req->flags & FLAG_SV1_RO_OFF) 407 if (req->flags & FLAG_SV1_RO_OFF)
404 SvREADONLY_off (req->sv1); 408 SvREADONLY_off (req->sv1);
524 grp->grp_first = req->grp_next; 528 grp->grp_first = req->grp_next;
525 529
526 aio_grp_dec (grp); 530 aio_grp_dec (grp);
527 } 531 }
528 532
529 if (SvTRUE (ERRSV)) 533 return !SvTRUE (ERRSV);
530 {
531 req_free (req);
532 croak (0);
533 }
534} 534}
535 535
536static void req_free (aio_req req) 536static void req_free (aio_req req)
537{ 537{
538 if (req->self) 538 if (req->self)
575 575
576static void *aio_proc(void *arg); 576static void *aio_proc(void *arg);
577 577
578static void start_thread (void) 578static void start_thread (void)
579{ 579{
580 sigset_t fullsigset, oldsigset;
581 pthread_attr_t attr;
582
583 worker *wrk = calloc (1, sizeof (worker)); 580 worker *wrk = calloc (1, sizeof (worker));
584 581
585 if (!wrk) 582 if (!wrk)
586 croak ("unable to allocate worker thread data"); 583 croak ("unable to allocate worker thread data");
587 584
588 pthread_attr_init (&attr);
589 pthread_attr_setstacksize (&attr, STACKSIZE);
590 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
591#ifdef PTHREAD_SCOPE_PROCESS
592 pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS);
593#endif
594
595 sigfillset (&fullsigset);
596
597 LOCK (wrklock); 585 LOCK (wrklock);
598 sigprocmask (SIG_SETMASK, &fullsigset, &oldsigset);
599 586
600 if (pthread_create (&wrk->tid, &attr, aio_proc, (void *)wrk) == 0) 587 if (thread_create (&wrk->tid, aio_proc, (void *)wrk))
601 { 588 {
602 wrk->prev = &wrk_first; 589 wrk->prev = &wrk_first;
603 wrk->next = wrk_first.next; 590 wrk->next = wrk_first.next;
604 wrk_first.next->prev = wrk; 591 wrk_first.next->prev = wrk;
605 wrk_first.next = wrk; 592 wrk_first.next = wrk;
606 ++started; 593 ++started;
607 } 594 }
608 else 595 else
609 free (wrk); 596 free (wrk);
610 597
611 sigprocmask (SIG_SETMASK, &oldsigset, 0);
612 UNLOCK (wrklock); 598 UNLOCK (wrklock);
613} 599}
614 600
615static void maybe_start_thread () 601static void maybe_start_thread ()
616{ 602{
624 start_thread (); 610 start_thread ();
625} 611}
626 612
627static void req_send (aio_req req) 613static void req_send (aio_req req)
628{ 614{
615 block_sig ();
616
629 ++nreqs; 617 ++nreqs;
630 618
631 LOCK (reqlock); 619 LOCK (reqlock);
632 ++nready; 620 ++nready;
633 reqq_push (&req_queue, req); 621 reqq_push (&req_queue, req);
634 pthread_cond_signal (&reqwait); 622 COND_SIGNAL (reqwait);
635 UNLOCK (reqlock); 623 UNLOCK (reqlock);
624
625 unblock_sig ();
636 626
637 maybe_start_thread (); 627 maybe_start_thread ();
638} 628}
639 629
640static void end_thread (void) 630static void end_thread (void)
646 req->type = REQ_QUIT; 636 req->type = REQ_QUIT;
647 req->pri = PRI_MAX + PRI_BIAS; 637 req->pri = PRI_MAX + PRI_BIAS;
648 638
649 LOCK (reqlock); 639 LOCK (reqlock);
650 reqq_push (&req_queue, req); 640 reqq_push (&req_queue, req);
651 pthread_cond_signal (&reqwait); 641 COND_SIGNAL (reqwait);
652 UNLOCK (reqlock); 642 UNLOCK (reqlock);
653 643
654 LOCK (wrklock); 644 LOCK (wrklock);
655 --started; 645 --started;
656 UNLOCK (wrklock); 646 UNLOCK (wrklock);
711 aio_req req; 701 aio_req req;
712 702
713 if (max_poll_time) 703 if (max_poll_time)
714 gettimeofday (&tv_start, 0); 704 gettimeofday (&tv_start, 0);
715 705
706 block_sig ();
707
716 for (;;) 708 for (;;)
717 { 709 {
718 for (;;) 710 for (;;)
719 { 711 {
720 maybe_start_thread (); 712 maybe_start_thread ();
727 --npending; 719 --npending;
728 720
729 if (!res_queue.size) 721 if (!res_queue.size)
730 { 722 {
731 /* read any signals sent by the worker threads */ 723 /* read any signals sent by the worker threads */
732 char buf [32]; 724 char buf [4];
733 while (read (respipe [0], buf, 32) == 32) 725 while (read (respipe [0], buf, 4) == 4)
734 ; 726 ;
735 } 727 }
736 } 728 }
737 729
738 UNLOCK (reslock); 730 UNLOCK (reslock);
747 req->int1 = 1; /* mark request as delayed */ 739 req->int1 = 1; /* mark request as delayed */
748 continue; 740 continue;
749 } 741 }
750 else 742 else
751 { 743 {
752 req_invoke (req); 744 if (!req_invoke (req))
745 {
746 req_free (req);
747 unblock_sig ();
748 croak (0);
749 }
753 750
754 count++; 751 count++;
755 } 752 }
756 753
757 req_free (req); 754 req_free (req);
774 poll_wait (); 771 poll_wait ();
775 772
776 ++maxreqs; 773 ++maxreqs;
777 } 774 }
778 775
776 unblock_sig ();
779 return count; 777 return count;
780} 778}
781 779
782static void create_pipe () 780static void create_pipe ()
783{ 781{
801/* 799/*
802 * make our pread/pwrite safe against themselves, but not against 800 * make our pread/pwrite safe against themselves, but not against
803 * normal read/write by using a mutex. slows down execution a lot, 801 * normal read/write by using a mutex. slows down execution a lot,
804 * but that's your problem, not mine. 802 * but that's your problem, not mine.
805 */ 803 */
806static pthread_mutex_t preadwritelock = PTHREAD_MUTEX_INITIALIZER; 804static mutex_t preadwritelock = MUTEX_INIT;
807 805
808static ssize_t pread (int fd, void *buf, size_t count, off_t offset) 806static ssize_t pread (int fd, void *buf, size_t count, off_t offset)
809{ 807{
810 ssize_t res; 808 ssize_t res;
811 off_t ooffset; 809 off_t ooffset;
862#endif 860#endif
863 861
864#if !HAVE_READDIR_R 862#if !HAVE_READDIR_R
865# define readdir_r aio_readdir_r 863# define readdir_r aio_readdir_r
866 864
867static pthread_mutex_t readdirlock = PTHREAD_MUTEX_INITIALIZER; 865static mutex_t readdirlock = MUTEX_INIT;
868 866
869static int readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) 867static int readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res)
870{ 868{
871 struct dirent *e; 869 struct dirent *e;
872 int errorno; 870 int errorno;
1071 if (req) 1069 if (req)
1072 break; 1070 break;
1073 1071
1074 ++idle; 1072 ++idle;
1075 1073
1076 if (pthread_cond_timedwait (&reqwait, &reqlock, &ts) 1074 if (COND_TIMEDWAIT (reqwait, reqlock, ts)
1077 == ETIMEDOUT) 1075 == ETIMEDOUT)
1078 { 1076 {
1079 if (idle > max_idle) 1077 if (idle > max_idle)
1080 { 1078 {
1081 --idle; 1079 --idle;
1085 UNLOCK (wrklock); 1083 UNLOCK (wrklock);
1086 goto quit; 1084 goto quit;
1087 } 1085 }
1088 1086
1089 /* we are allowed to idle, so do so without any timeout */ 1087 /* we are allowed to idle, so do so without any timeout */
1090 pthread_cond_wait (&reqwait, &reqlock); 1088 COND_WAIT (reqwait, reqlock);
1091 ts.tv_sec = time (0) + IDLE_TIMEOUT; 1089 ts.tv_sec = time (0) + IDLE_TIMEOUT;
1092 } 1090 }
1093 1091
1094 --idle; 1092 --idle;
1095 } 1093 }
1115 1113
1116 case REQ_OPEN: req->result = open (req->ptr1, req->int1, req->mode); break; 1114 case REQ_OPEN: req->result = open (req->ptr1, req->int1, req->mode); break;
1117 case REQ_CLOSE: req->result = close (req->int1); break; 1115 case REQ_CLOSE: req->result = close (req->int1); break;
1118 case REQ_UNLINK: req->result = unlink (req->ptr1); break; 1116 case REQ_UNLINK: req->result = unlink (req->ptr1); break;
1119 case REQ_RMDIR: req->result = rmdir (req->ptr1); break; 1117 case REQ_RMDIR: req->result = rmdir (req->ptr1); break;
1118 case REQ_MKDIR: req->result = mkdir (req->ptr1, req->mode); break;
1120 case REQ_RENAME: req->result = rename (req->ptr2, req->ptr1); break; 1119 case REQ_RENAME: req->result = rename (req->ptr2, req->ptr1); break;
1121 case REQ_LINK: req->result = link (req->ptr2, req->ptr1); break; 1120 case REQ_LINK: req->result = link (req->ptr2, req->ptr1); break;
1122 case REQ_SYMLINK: req->result = symlink (req->ptr2, req->ptr1); break; 1121 case REQ_SYMLINK: req->result = symlink (req->ptr2, req->ptr1); break;
1123 case REQ_MKNOD: req->result = mknod (req->ptr2, req->mode, (dev_t)req->offs); break; 1122 case REQ_MKNOD: req->result = mknod (req->ptr2, req->mode, (dev_t)req->offs); break;
1124 case REQ_READLINK: req->result = readlink (req->ptr2, req->ptr1, NAME_MAX); break; 1123 case REQ_READLINK: req->result = readlink (req->ptr2, req->ptr1, NAME_MAX); break;
1154 LOCK (reslock); 1153 LOCK (reslock);
1155 1154
1156 ++npending; 1155 ++npending;
1157 1156
1158 if (!reqq_push (&res_queue, req)) 1157 if (!reqq_push (&res_queue, req))
1158 {
1159 /* write a dummy byte to the pipe so fh becomes ready */ 1159 /* write a dummy byte to the pipe so fh becomes ready */
1160 write (respipe [1], &respipe, 1); 1160 write (respipe [1], &respipe, 1);
1161
1162 /* optionally signal the main thread asynchronously */
1163 if (main_sig)
1164 pthread_kill (main_tid, main_sig);
1165 }
1161 1166
1162 self->req = 0; 1167 self->req = 0;
1163 worker_clear (self); 1168 worker_clear (self);
1164 1169
1165 UNLOCK (reslock); 1170 UNLOCK (reslock);
1268 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); 1273 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY));
1269 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); 1274 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY));
1270 newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); 1275 newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT));
1271 newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); 1276 newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC));
1272 newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); 1277 newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO));
1278 newCONSTSUB (stash, "SIGIO", newSViv (SIGIO));
1273 1279
1274 create_pipe (); 1280 create_pipe ();
1275 pthread_atfork (atfork_prepare, atfork_parent, atfork_child); 1281 ATFORK (atfork_prepare, atfork_parent, atfork_child);
1276} 1282}
1277 1283
1278void 1284void
1279max_poll_reqs (int nreqs) 1285max_poll_reqs (int nreqs)
1280 PROTOTYPE: $ 1286 PROTOTYPE: $
1383 length = svlen - dataoffset; 1389 length = svlen - dataoffset;
1384 } 1390 }
1385 else 1391 else
1386 { 1392 {
1387 /* read: grow scalar as necessary */ 1393 /* read: grow scalar as necessary */
1388 svptr = SvGROW (data, length + dataoffset); 1394 svptr = SvGROW (data, length + dataoffset + 1);
1389 } 1395 }
1390 1396
1391 if (length < 0) 1397 if (length < 0)
1392 croak ("length must not be negative"); 1398 croak ("length must not be negative");
1393 1399
1533 1539
1534 REQ_SEND; 1540 REQ_SEND;
1535} 1541}
1536 1542
1537void 1543void
1544aio_mkdir (pathname,mode,callback=&PL_sv_undef)
1545 SV8 * pathname
1546 UV mode
1547 SV * callback
1548 PPCODE:
1549{
1550 dREQ;
1551
1552 req->type = REQ_MKDIR;
1553 req->sv1 = newSVsv (pathname);
1554 req->ptr1 = SvPVbyte_nolen (req->sv1);
1555 req->mode = mode;
1556
1557 REQ_SEND;
1558}
1559
1560void
1538aio_link (oldpath,newpath,callback=&PL_sv_undef) 1561aio_link (oldpath,newpath,callback=&PL_sv_undef)
1539 SV8 * oldpath 1562 SV8 * oldpath
1540 SV8 * newpath 1563 SV8 * newpath
1541 SV * callback 1564 SV * callback
1542 ALIAS: 1565 ALIAS:
1557} 1580}
1558 1581
1559void 1582void
1560aio_mknod (pathname,mode,dev,callback=&PL_sv_undef) 1583aio_mknod (pathname,mode,dev,callback=&PL_sv_undef)
1561 SV8 * pathname 1584 SV8 * pathname
1562 SV * callback
1563 UV mode 1585 UV mode
1564 UV dev 1586 UV dev
1587 SV * callback
1565 PPCODE: 1588 PPCODE:
1566{ 1589{
1567 dREQ; 1590 dREQ;
1568 1591
1569 req->type = REQ_MKNOD; 1592 req->type = REQ_MKNOD;
1677poll_wait() 1700poll_wait()
1678 PROTOTYPE: 1701 PROTOTYPE:
1679 CODE: 1702 CODE:
1680 poll_wait (); 1703 poll_wait ();
1681 1704
1705void
1706setsig (int signum = SIGIO)
1707 PROTOTYPE: ;$
1708 CODE:
1709{
1710 if (block_sig_level)
1711 croak ("cannot call IO::AIO::setsig from within aio_block/callback");
1712
1713 LOCK (reslock);
1714 main_tid = pthread_self ();
1715 main_sig = signum;
1716 UNLOCK (reslock);
1717
1718 if (main_sig && npending)
1719 pthread_kill (main_tid, main_sig);
1720}
1721
1722void
1723aio_block (SV *cb)
1724 PROTOTYPE: &
1725 PPCODE:
1726{
1727 int count;
1728
1729 block_sig ();
1730 PUSHMARK (SP);
1731 PUTBACK;
1732 count = call_sv (cb, GIMME_V | G_NOARGS | G_EVAL);
1733 SPAGAIN;
1734 unblock_sig ();
1735
1736 if (SvTRUE (ERRSV))
1737 croak (0);
1738
1739 XSRETURN (count);
1740}
1741
1682int 1742int
1683nreqs() 1743nreqs()
1684 PROTOTYPE: 1744 PROTOTYPE:
1685 CODE: 1745 CODE:
1686 RETVAL = nreqs; 1746 RETVAL = nreqs;
1735 PPCODE: 1795 PPCODE:
1736{ 1796{
1737 int i; 1797 int i;
1738 aio_req req; 1798 aio_req req;
1739 1799
1800 if (main_sig && !block_sig_level)
1801 croak ("aio_group->add called outside aio_block/callback context while IO::AIO::setsig is in use");
1802
1740 if (grp->int1 == 2) 1803 if (grp->int1 == 2)
1741 croak ("cannot add requests to IO::AIO::GRP after the group finished"); 1804 croak ("cannot add requests to IO::AIO::GRP after the group finished");
1742 1805
1743 for (i = 1; i < items; ++i ) 1806 for (i = 1; i < items; ++i )
1744 { 1807 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines