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.75 by root, Thu Oct 26 06:44:48 2006 UTC vs.
Revision 1.76 by root, Thu Oct 26 12:38:04 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"
144#endif 145#endif
145 146
146#define LOCK(mutex) pthread_mutex_lock (&(mutex)) 147#define LOCK(mutex) pthread_mutex_lock (&(mutex))
147#define UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) 148#define UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
148 149
149/* worker threasd management */ 150/* worker threads management */
150static pthread_mutex_t wrklock = AIO_MUTEX_INIT; 151static pthread_mutex_t wrklock = AIO_MUTEX_INIT;
151 152
152typedef struct worker { 153typedef struct worker {
153 /* locked by wrklock */ 154 /* locked by wrklock */
154 struct worker *prev, *next; 155 struct worker *prev, *next;
242 } 243 }
243 244
244 abort (); 245 abort ();
245} 246}
246 247
247static int poll_cb (); 248static int poll_cb (int max);
248static void req_invoke (aio_req req); 249static void req_invoke (aio_req req);
249static void req_free (aio_req req); 250static void req_free (aio_req req);
250static void req_cancel (aio_req req); 251static void req_cancel (aio_req req);
251 252
252/* must be called at most once */ 253/* must be called at most once */
495 req->flags |= FLAG_CANCELLED; 496 req->flags |= FLAG_CANCELLED;
496 497
497 req_cancel_subs (req); 498 req_cancel_subs (req);
498} 499}
499 500
500static int poll_cb () 501static int poll_cb (int max)
501{ 502{
502 dSP; 503 dSP;
503 int count = 0; 504 int count = 0;
504 int do_croak = 0; 505 int do_croak = 0;
505 aio_req req; 506 aio_req req;
506 507
507 for (;;) 508 while (max <= 0 || count < max)
508 { 509 {
509 LOCK (reslock); 510 LOCK (reslock);
510 req = reqq_shift (&res_queue); 511 req = reqq_shift (&res_queue);
511 512
512 if (req) 513 if (req)
641 } 642 }
642 643
643 while (started > wanted) 644 while (started > wanted)
644 { 645 {
645 poll_wait (); 646 poll_wait ();
646 poll_cb (); 647 poll_cb (0);
647 } 648 }
648} 649}
649 650
650static void create_pipe () 651static void create_pipe ()
651{ 652{
869 int errorno; 870 int errorno;
870 871
871 LOCK (wrklock); 872 LOCK (wrklock);
872 self->dirp = dirp = opendir (req->dataptr); 873 self->dirp = dirp = opendir (req->dataptr);
873 self->dbuf = u = malloc (sizeof (*u)); 874 self->dbuf = u = malloc (sizeof (*u));
875 req->data2ptr = names = malloc (memlen);
874 UNLOCK (wrklock); 876 UNLOCK (wrklock);
875
876 req->data2ptr = names = malloc (memlen);
877 877
878 if (dirp && u && names) 878 if (dirp && u && names)
879 for (;;) 879 for (;;)
880 { 880 {
881 errno = 0; 881 errno = 0;
1396 PROTOTYPE: 1396 PROTOTYPE:
1397 CODE: 1397 CODE:
1398 while (nreqs) 1398 while (nreqs)
1399 { 1399 {
1400 poll_wait (); 1400 poll_wait ();
1401 poll_cb (); 1401 poll_cb (0);
1402 } 1402 }
1403 1403
1404void 1404void
1405poll() 1405poll()
1406 PROTOTYPE: 1406 PROTOTYPE:
1407 CODE: 1407 CODE:
1408 if (nreqs) 1408 if (nreqs)
1409 { 1409 {
1410 poll_wait (); 1410 poll_wait ();
1411 poll_cb (); 1411 poll_cb (0);
1412 } 1412 }
1413 1413
1414int 1414int
1415poll_fileno() 1415poll_fileno()
1416 PROTOTYPE: 1416 PROTOTYPE:
1421 1421
1422int 1422int
1423poll_cb(...) 1423poll_cb(...)
1424 PROTOTYPE: 1424 PROTOTYPE:
1425 CODE: 1425 CODE:
1426 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);
1427 OUTPUT: 1435 OUTPUT:
1428 RETVAL 1436 RETVAL
1429 1437
1430void 1438void
1431poll_wait() 1439poll_wait()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines