ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-AIO/AIO.xs
(Generate patch)

Comparing Linux-AIO/AIO.xs (file contents):
Revision 1.16 by root, Wed May 5 10:13:30 2004 UTC vs.
Revision 1.19 by root, Fri May 7 00:57:29 2004 UTC

1#define PERL_NO_GET_CONTEXT
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 6
5#include <sys/types.h> 7#include <sys/types.h>
26 28
27typedef struct { 29typedef struct {
28 char stack[STACKSIZE]; 30 char stack[STACKSIZE];
29} aio_thread; 31} aio_thread;
30 32
31typedef struct { 33typedef struct aio_cb {
34 struct aio_cb *next;
35
32 int type; 36 int type;
33 aio_thread *thread; 37 aio_thread *thread;
34 38
35 int fd; 39 int fd;
36 off_t offset; 40 off_t offset;
49 53
50static int started; 54static int started;
51static int nreqs; 55static int nreqs;
52static int reqpipe[2], respipe[2]; 56static int reqpipe[2], respipe[2];
53 57
58static aio_req qs, qe; /* queue start, queue end */
59
54static int aio_proc(void *arg); 60static int aio_proc(void *arg);
55 61
56static void 62static void
57start_thread(void) 63start_thread (void)
58{ 64{
59 aio_thread *thr; 65 aio_thread *thr;
60 66
61 New (0, thr, 1, aio_thread); 67 New (0, thr, 1, aio_thread);
62 68
68 else 74 else
69 Safefree (thr); 75 Safefree (thr);
70} 76}
71 77
72static void 78static void
79send_reqs (void)
80{
81 /* this write is atomic */
82 while (qs && write (reqpipe[1], &qs, sizeof qs) == sizeof qs)
83 {
84 qs = qs->next;
85 if (!qs) qe = 0;
86 }
87}
88
89static void
90send_req (aio_req req)
91{
92 nreqs++;
93 req->next = 0;
94
95 if (qe)
96 qe->next = req;
97 else
98 qe = qs = req;
99
100 send_reqs ();
101}
102
103static void
73end_thread(void) 104end_thread (void)
74{ 105{
75 aio_req req; 106 aio_req req;
76 New (0, req, 1, aio_cb); 107 New (0, req, 1, aio_cb);
77 req->type = REQ_QUIT; 108 req->type = REQ_QUIT;
78 write (reqpipe[1], &req, sizeof (aio_req)); 109
110 send_req (req);
79} 111}
80 112
81static void 113static void
82send_req (aio_req req) 114read_write (pTHX_
83{
84 nreqs++;
85 write (reqpipe[1], &req, sizeof (aio_req));
86}
87
88static void
89read_write (pTHX_ int dowrite, int fd, off_t offset, size_t length, 115 int dowrite, int fd, off_t offset, size_t length,
90 SV *data, STRLEN dataoffset, SV*callback) 116 SV *data, STRLEN dataoffset, SV *callback)
91{ 117{
92 aio_req req; 118 aio_req req;
93 STRLEN svlen; 119 STRLEN svlen;
94 char *svptr = SvPV (data, svlen); 120 char *svptr = SvPV (data, svlen);
95 121
195 } 221 }
196 222
197 Safefree (req); 223 Safefree (req);
198 } 224 }
199 225
226 if (qs)
227 send_reqs ();
228
200 return count; 229 return count;
201} 230}
202 231
203static sigset_t fullsigset; 232static sigset_t fullsigset;
204 233
205#undef errno 234#undef errno
206#include <asm/unistd.h> 235#include <asm/unistd.h>
207 236
208static int 237static int
209aio_proc(void *thr_arg) 238aio_proc (void *thr_arg)
210{ 239{
211 aio_thread *thr = thr_arg; 240 aio_thread *thr = thr_arg;
212 aio_req req; 241 aio_req req;
213 int errno; 242 int errno;
214 243
233 while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req)) 262 while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req))
234 { 263 {
235 req->thread = thr; 264 req->thread = thr;
236 errno = 0; /* strictly unnecessary */ 265 errno = 0; /* strictly unnecessary */
237 266
238 if (req->type == REQ_READ) 267 switch (req->type)
239 req->result = pread64 (req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32);
240 else if (req->type == REQ_WRITE)
241 req->result = pwrite64(req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32);
242 else if (req->type == REQ_OPEN)
243 req->result = open (req->dataptr, req->fd, req->mode);
244 else if (req->type == REQ_CLOSE)
245 req->result = close (req->fd);
246 else if (req->type == REQ_STAT)
247 req->result = stat64 (req->dataptr, req->statdata);
248 else if (req->type == REQ_LSTAT)
249 req->result = lstat64 (req->dataptr, req->statdata);
250 else if (req->type == REQ_FSTAT)
251 req->result = fstat64 (req->fd, req->statdata);
252 else
253 { 268 {
269 case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break;
270 case REQ_WRITE: req->result = pwrite64(req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break;
271 case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break;
272 case REQ_CLOSE: req->result = close (req->fd); break;
273 case REQ_STAT: req->result = stat64 (req->dataptr, req->statdata); break;
274 case REQ_LSTAT: req->result = lstat64 (req->dataptr, req->statdata); break;
275 case REQ_FSTAT: req->result = fstat64 (req->fd, req->statdata); break;
276
277 case REQ_QUIT:
278 default:
254 write (respipe[1], (void *)&req, sizeof (req)); 279 write (respipe[1], (void *)&req, sizeof (req));
255 break; 280 return 0;
256 } 281 }
257 282
258 req->errorno = errno; 283 req->errorno = errno;
259 write (respipe[1], (void *)&req, sizeof (req)); 284 write (respipe[1], (void *)&req, sizeof (req));
260 } 285 }
272 sigdelset (&fullsigset, SIGABRT); 297 sigdelset (&fullsigset, SIGABRT);
273 sigdelset (&fullsigset, SIGINT); 298 sigdelset (&fullsigset, SIGINT);
274 299
275 if (pipe (reqpipe) || pipe (respipe)) 300 if (pipe (reqpipe) || pipe (respipe))
276 croak ("unable to initialize request or result pipe"); 301 croak ("unable to initialize request or result pipe");
302
303 if (fcntl (reqpipe[1], F_SETFL, O_NONBLOCK))
304 croak ("cannot set result pipe to nonblocking mode");
277 305
278 if (fcntl (respipe[0], F_SETFL, O_NONBLOCK)) 306 if (fcntl (respipe[0], F_SETFL, O_NONBLOCK))
279 croak ("cannot set result pipe to nonblocking mode"); 307 croak ("cannot set result pipe to nonblocking mode");
280} 308}
281 309
304 fd_set rfd; 332 fd_set rfd;
305 FD_ZERO(&rfd); 333 FD_ZERO(&rfd);
306 FD_SET(respipe[0], &rfd); 334 FD_SET(respipe[0], &rfd);
307 335
308 select (respipe[0] + 1, &rfd, 0, 0, 0); 336 select (respipe[0] + 1, &rfd, 0, 0, 0);
309 poll_cb (); 337 poll_cb (aTHX);
310 } 338 }
311 339
312void 340void
313aio_open(pathname,flags,mode,callback) 341aio_open(pathname,flags,mode,callback)
314 SV * pathname 342 SV * pathname

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines