--- IO-AIO/AIO.xs 2006/10/26 06:44:48 1.75 +++ IO-AIO/AIO.xs 2006/10/26 12:38:04 1.76 @@ -1,10 +1,11 @@ /* solaris */ #define _POSIX_PTHREAD_SEMANTICS 1 -#if __linux +#if __linux && !defined(_GNU_SOURCE) # define _GNU_SOURCE #endif +/* just in case */ #define _REENTRANT 1 #include @@ -146,7 +147,7 @@ #define LOCK(mutex) pthread_mutex_lock (&(mutex)) #define UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) -/* worker threasd management */ +/* worker threads management */ static pthread_mutex_t wrklock = AIO_MUTEX_INIT; typedef struct worker { @@ -244,7 +245,7 @@ abort (); } -static int poll_cb (); +static int poll_cb (int max); static void req_invoke (aio_req req); static void req_free (aio_req req); static void req_cancel (aio_req req); @@ -497,14 +498,14 @@ req_cancel_subs (req); } -static int poll_cb () +static int poll_cb (int max) { dSP; int count = 0; int do_croak = 0; aio_req req; - for (;;) + while (max <= 0 || count < max) { LOCK (reslock); req = reqq_shift (&res_queue); @@ -643,7 +644,7 @@ while (started > wanted) { poll_wait (); - poll_cb (); + poll_cb (0); } } @@ -871,9 +872,8 @@ LOCK (wrklock); self->dirp = dirp = opendir (req->dataptr); self->dbuf = u = malloc (sizeof (*u)); - UNLOCK (wrklock); - req->data2ptr = names = malloc (memlen); + UNLOCK (wrklock); if (dirp && u && names) for (;;) @@ -1398,7 +1398,7 @@ while (nreqs) { poll_wait (); - poll_cb (); + poll_cb (0); } void @@ -1408,7 +1408,7 @@ if (nreqs) { poll_wait (); - poll_cb (); + poll_cb (0); } int @@ -1423,7 +1423,15 @@ poll_cb(...) PROTOTYPE: CODE: - RETVAL = poll_cb (); + RETVAL = poll_cb (0); + OUTPUT: + RETVAL + +int +poll_some(int max = 0) + PROTOTYPE: $ + CODE: + RETVAL = poll_cb (max); OUTPUT: RETVAL