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.10 by root, Wed Jul 13 00:13:09 2005 UTC vs.
Revision 1.12 by root, Wed Jul 20 21:57:04 2005 UTC

1#define _XOPEN_SOURCE 500
2
1#include "EXTERN.h" 3#include "EXTERN.h"
2#include "perl.h" 4#include "perl.h"
3#include "XSUB.h" 5#include "XSUB.h"
4
5#define _XOPEN_SOURCE 500
6 6
7#include <sys/types.h> 7#include <sys/types.h>
8#include <sys/stat.h> 8#include <sys/stat.h>
9 9
10#include <unistd.h> 10#include <unistd.h>
54} aio_cb; 54} aio_cb;
55 55
56typedef aio_cb *aio_req; 56typedef aio_cb *aio_req;
57 57
58static int started; 58static int started;
59static int nreqs; 59static volatile int nreqs;
60static int max_outstanding = 1<<30; 60static int max_outstanding = 1<<30;
61static int respipe [2]; 61static int respipe [2];
62 62
63static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; 63static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER;
64static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; 64static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER;
68static volatile aio_req ress, rese; /* queue start, queue end */ 68static volatile aio_req ress, rese; /* queue start, queue end */
69 69
70static void 70static void
71poll_wait () 71poll_wait ()
72{ 72{
73 if (!nreqs) 73 if (nreqs && !ress)
74 return; 74 {
75
76 fd_set rfd; 75 fd_set rfd;
77 FD_ZERO(&rfd); 76 FD_ZERO(&rfd);
78 FD_SET(respipe [0], &rfd); 77 FD_SET(respipe [0], &rfd);
79 78
80 select (respipe [0] + 1, &rfd, 0, 0, 0); 79 select (respipe [0] + 1, &rfd, 0, 0, 0);
80 }
81} 81}
82 82
83static int 83static int
84poll_cb () 84poll_cb ()
85{ 85{
86 dSP; 86 dSP;
87 int count = 0; 87 int count = 0;
88 aio_req req; 88 aio_req req, prv;
89 89
90 pthread_mutex_lock (&reslock);
91
90 { 92 {
91 /* read and signals sent by the worker threads */ 93 /* read any signals sent by the worker threads */
92 char buf [32]; 94 char buf [32];
93 while (read (respipe [0], buf, 32) > 0) 95 while (read (respipe [0], buf, 32) > 0)
94 ; 96 ;
95 } 97 }
96 98
97 for (;;) 99 req = ress;
100 ress = rese = 0;
101
102 pthread_mutex_unlock (&reslock);
103
104 while (req)
98 { 105 {
99 pthread_mutex_lock (&reslock);
100
101 req = ress;
102
103 if (ress)
104 {
105 ress = ress->next;
106 if (!ress) rese = 0;
107 }
108
109 pthread_mutex_unlock (&reslock);
110
111 if (!req)
112 break;
113
114 nreqs--; 106 nreqs--;
115 107
116 if (req->type == REQ_QUIT) 108 if (req->type == REQ_QUIT)
117 started--; 109 started--;
118 else 110 else
166 158
167 errno = errorno; 159 errno = errorno;
168 count++; 160 count++;
169 } 161 }
170 162
163 prv = req;
164 req = req->next;
171 Safefree (req); 165 Safefree (prv);
166
167 /* TODO: croak on errors? */
172 } 168 }
173 169
174 return count; 170 return count;
175} 171}
176 172

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines