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.74 by root, Wed Oct 25 17:57:30 2006 UTC vs.
Revision 1.77 by root, Thu Oct 26 13:25:40 2006 UTC

1/* solaris */ 1/* solaris */
2#define _POSIX_PTHREAD_SEMANTICS 1 2#define _POSIX_PTHREAD_SEMANTICS 1
3 3
4#if __linux 4#if __linux && !defined(_GNU_SOURCE)
5# define _GNU_SOURCE 5# define _GNU_SOURCE
6#endif 6#endif
7 7
8/* just in case */
8#define _REENTRANT 1 9#define _REENTRANT 1
9 10
10#include <errno.h> 11#include <errno.h>
11 12
12#include "EXTERN.h" 13#include "EXTERN.h"
47/* used for struct dirent, AIX doesn't provide it */ 48/* used for struct dirent, AIX doesn't provide it */
48#ifndef NAME_MAX 49#ifndef NAME_MAX
49# define NAME_MAX 4096 50# define NAME_MAX 4096
50#endif 51#endif
51 52
53#ifndef PTHREAD_STACK_MIN
54/* care for broken platforms, e.g. windows */
55# define PTHREAD_STACK_MIN 16384
56#endif
57
52#if __ia64 58#if __ia64
53# define STACKSIZE 65536 59# define STACKSIZE 65536
54#elif __i386 || __x86_64 /* 16k is unreasonably high :( */ 60#elif __i386 || __x86_64 /* 16k is unreasonably high :( */
55# define STACKSIZE PTHREAD_STACK_MIN 61# define STACKSIZE PTHREAD_STACK_MIN
56#else 62#else
139#endif 145#endif
140 146
141#define LOCK(mutex) pthread_mutex_lock (&(mutex)) 147#define LOCK(mutex) pthread_mutex_lock (&(mutex))
142#define UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) 148#define UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
143 149
144/* worker threasd management */ 150/* worker threads management */
145static pthread_mutex_t wrklock = AIO_MUTEX_INIT; 151static pthread_mutex_t wrklock = AIO_MUTEX_INIT;
146 152
147typedef struct worker { 153typedef struct worker {
148 /* locked by wrklock */ 154 /* locked by wrklock */
149 struct worker *prev, *next; 155 struct worker *prev, *next;
237 } 243 }
238 244
239 abort (); 245 abort ();
240} 246}
241 247
242static int poll_cb (); 248static int poll_cb (int max);
243static void req_invoke (aio_req req); 249static void req_invoke (aio_req req);
244static void req_free (aio_req req); 250static void req_free (aio_req req);
245static void req_cancel (aio_req req); 251static void req_cancel (aio_req req);
246 252
247/* must be called at most once */ 253/* must be called at most once */
490 req->flags |= FLAG_CANCELLED; 496 req->flags |= FLAG_CANCELLED;
491 497
492 req_cancel_subs (req); 498 req_cancel_subs (req);
493} 499}
494 500
495static int poll_cb () 501static int poll_cb (int max)
496{ 502{
497 dSP; 503 dSP;
498 int count = 0; 504 int count = 0;
499 int do_croak = 0; 505 int do_croak = 0;
500 aio_req req; 506 aio_req req;
501 507
502 for (;;) 508 while (max <= 0 || count < max)
503 { 509 {
504 LOCK (reslock); 510 LOCK (reslock);
505 req = reqq_shift (&res_queue); 511 req = reqq_shift (&res_queue);
506 512
507 if (req) 513 if (req)
636 } 642 }
637 643
638 while (started > wanted) 644 while (started > wanted)
639 { 645 {
640 poll_wait (); 646 poll_wait ();
641 poll_cb (); 647 poll_cb (0);
642 } 648 }
643} 649}
644 650
645static void create_pipe () 651static void create_pipe ()
646{ 652{
702#if !HAVE_FDATASYNC 708#if !HAVE_FDATASYNC
703# define fdatasync fsync 709# define fdatasync fsync
704#endif 710#endif
705 711
706#if !HAVE_READAHEAD 712#if !HAVE_READAHEAD
707# define readahead aio_readahead 713# define readahead(fd,offset,count) aio_readahead (fd, offset, count, self)
708 714
709static ssize_t readahead (int fd, off_t offset, size_t count) 715static ssize_t aio_readahead (int fd, off_t offset, size_t count, worker *self)
710{ 716{
711 dBUF; 717 dBUF;
712 718
713 while (count > 0) 719 while (count > 0)
714 { 720 {
719 count -= len; 725 count -= len;
720 } 726 }
721 727
722 errno = 0; 728 errno = 0;
723} 729}
730
724#endif 731#endif
725 732
726#if !HAVE_READDIR_R 733#if !HAVE_READDIR_R
727# define readdir_r aio_readdir_r 734# define readdir_r aio_readdir_r
728 735
773 { 780 {
774 off_t sbytes; 781 off_t sbytes;
775 res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); 782 res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0);
776 783
777 if (res < 0 && sbytes) 784 if (res < 0 && sbytes)
778 /* maybe only on EAGAIN only: as usual, the manpage leaves you guessing */ 785 /* maybe only on EAGAIN: as usual, the manpage leaves you guessing */
779 res = sbytes; 786 res = sbytes;
780 } 787 }
781 788
782# elif __hpux 789# elif __hpux
783 res = sendfile (ofd, ifd, offset, count, 0, 0); 790 res = sendfile (ofd, ifd, offset, count, 0, 0);
863 int errorno; 870 int errorno;
864 871
865 LOCK (wrklock); 872 LOCK (wrklock);
866 self->dirp = dirp = opendir (req->dataptr); 873 self->dirp = dirp = opendir (req->dataptr);
867 self->dbuf = u = malloc (sizeof (*u)); 874 self->dbuf = u = malloc (sizeof (*u));
875 req->data2ptr = names = malloc (memlen);
868 UNLOCK (wrklock); 876 UNLOCK (wrklock);
869
870 req->data2ptr = names = malloc (memlen);
871 877
872 if (dirp && u && names) 878 if (dirp && u && names)
873 for (;;) 879 for (;;)
874 { 880 {
875 errno = 0; 881 errno = 0;
1390 PROTOTYPE: 1396 PROTOTYPE:
1391 CODE: 1397 CODE:
1392 while (nreqs) 1398 while (nreqs)
1393 { 1399 {
1394 poll_wait (); 1400 poll_wait ();
1395 poll_cb (); 1401 poll_cb (0);
1396 } 1402 }
1397 1403
1398void 1404void
1399poll() 1405poll()
1400 PROTOTYPE: 1406 PROTOTYPE:
1401 CODE: 1407 CODE:
1402 if (nreqs) 1408 if (nreqs)
1403 { 1409 {
1404 poll_wait (); 1410 poll_wait ();
1405 poll_cb (); 1411 poll_cb (0);
1406 } 1412 }
1407 1413
1408int 1414int
1409poll_fileno() 1415poll_fileno()
1410 PROTOTYPE: 1416 PROTOTYPE:
1415 1421
1416int 1422int
1417poll_cb(...) 1423poll_cb(...)
1418 PROTOTYPE: 1424 PROTOTYPE:
1419 CODE: 1425 CODE:
1420 RETVAL = poll_cb (); 1426 RETVAL = poll_cb (0);
1427 OUTPUT:
1428 RETVAL
1429
1430int
1431poll_some(int max = 0)
1432 PROTOTYPE: $
1433 CODE:
1434 RETVAL = poll_cb (max);
1421 OUTPUT: 1435 OUTPUT:
1422 RETVAL 1436 RETVAL
1423 1437
1424void 1438void
1425poll_wait() 1439poll_wait()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines