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 */ |
150 | static pthread_mutex_t wrklock = AIO_MUTEX_INIT; |
151 | static pthread_mutex_t wrklock = AIO_MUTEX_INIT; |
151 | |
152 | |
152 | typedef struct worker { |
153 | typedef 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 | |
247 | static int poll_cb (); |
248 | static int poll_cb (int max); |
248 | static void req_invoke (aio_req req); |
249 | static void req_invoke (aio_req req); |
249 | static void req_free (aio_req req); |
250 | static void req_free (aio_req req); |
250 | static void req_cancel (aio_req req); |
251 | static 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 | |
500 | static int poll_cb () |
501 | static 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 | |
650 | static void create_pipe () |
651 | static void create_pipe () |
651 | { |
652 | { |
… | |
… | |
779 | { |
780 | { |
780 | off_t sbytes; |
781 | off_t sbytes; |
781 | res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); |
782 | res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); |
782 | |
783 | |
783 | if (res < 0 && sbytes) |
784 | if (res < 0 && sbytes) |
784 | /* maybe only on EAGAIN only: as usual, the manpage leaves you guessing */ |
785 | /* maybe only on EAGAIN: as usual, the manpage leaves you guessing */ |
785 | res = sbytes; |
786 | res = sbytes; |
786 | } |
787 | } |
787 | |
788 | |
788 | # elif __hpux |
789 | # elif __hpux |
789 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
790 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
… | |
… | |
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 | |
1404 | void |
1404 | void |
1405 | poll() |
1405 | poll() |
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 | |
1414 | int |
1414 | int |
1415 | poll_fileno() |
1415 | poll_fileno() |
1416 | PROTOTYPE: |
1416 | PROTOTYPE: |
… | |
… | |
1421 | |
1421 | |
1422 | int |
1422 | int |
1423 | poll_cb(...) |
1423 | poll_cb(...) |
1424 | PROTOTYPE: |
1424 | PROTOTYPE: |
1425 | CODE: |
1425 | CODE: |
1426 | RETVAL = poll_cb (); |
1426 | RETVAL = poll_cb (0); |
|
|
1427 | OUTPUT: |
|
|
1428 | RETVAL |
|
|
1429 | |
|
|
1430 | int |
|
|
1431 | poll_some(int max = 0) |
|
|
1432 | PROTOTYPE: $ |
|
|
1433 | CODE: |
|
|
1434 | RETVAL = poll_cb (max); |
1427 | OUTPUT: |
1435 | OUTPUT: |
1428 | RETVAL |
1436 | RETVAL |
1429 | |
1437 | |
1430 | void |
1438 | void |
1431 | poll_wait() |
1439 | poll_wait() |