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.18 by root, Thu May 6 15:05:57 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 {
228 printf ("outstanding %p %d\n", qs, nreqs);
229 send_reqs ();
230 }
231
200 return count; 232 return count;
201} 233}
202 234
203static sigset_t fullsigset; 235static sigset_t fullsigset;
204 236
205#undef errno 237#undef errno
206#include <asm/unistd.h> 238#include <asm/unistd.h>
207 239
208static int 240static int
209aio_proc(void *thr_arg) 241aio_proc (void *thr_arg)
210{ 242{
211 aio_thread *thr = thr_arg; 243 aio_thread *thr = thr_arg;
212 aio_req req; 244 aio_req req;
213 int errno; 245 int errno;
214 246
233 while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req)) 265 while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req))
234 { 266 {
235 req->thread = thr; 267 req->thread = thr;
236 errno = 0; /* strictly unnecessary */ 268 errno = 0; /* strictly unnecessary */
237 269
238 if (req->type == REQ_READ) 270 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 { 271 {
272 case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break;
273 case REQ_WRITE: req->result = pwrite64(req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); break;
274 case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break;
275 case REQ_CLOSE: req->result = close (req->fd); break;
276 case REQ_STAT: req->result = stat64 (req->dataptr, req->statdata); break;
277 case REQ_LSTAT: req->result = lstat64 (req->dataptr, req->statdata); break;
278 case REQ_FSTAT: req->result = fstat64 (req->fd, req->statdata); break;
279
280 case REQ_QUIT:
281 default:
254 write (respipe[1], (void *)&req, sizeof (req)); 282 write (respipe[1], (void *)&req, sizeof (req));
255 break; 283 return 0;
256 } 284 }
257 285
258 req->errorno = errno; 286 req->errorno = errno;
259 write (respipe[1], (void *)&req, sizeof (req)); 287 write (respipe[1], (void *)&req, sizeof (req));
260 } 288 }
272 sigdelset (&fullsigset, SIGABRT); 300 sigdelset (&fullsigset, SIGABRT);
273 sigdelset (&fullsigset, SIGINT); 301 sigdelset (&fullsigset, SIGINT);
274 302
275 if (pipe (reqpipe) || pipe (respipe)) 303 if (pipe (reqpipe) || pipe (respipe))
276 croak ("unable to initialize request or result pipe"); 304 croak ("unable to initialize request or result pipe");
305
306 if (fcntl (reqpipe[1], F_SETFL, O_NONBLOCK))
307 croak ("cannot set result pipe to nonblocking mode");
277 308
278 if (fcntl (respipe[0], F_SETFL, O_NONBLOCK)) 309 if (fcntl (respipe[0], F_SETFL, O_NONBLOCK))
279 croak ("cannot set result pipe to nonblocking mode"); 310 croak ("cannot set result pipe to nonblocking mode");
280} 311}
281 312
304 fd_set rfd; 335 fd_set rfd;
305 FD_ZERO(&rfd); 336 FD_ZERO(&rfd);
306 FD_SET(respipe[0], &rfd); 337 FD_SET(respipe[0], &rfd);
307 338
308 select (respipe[0] + 1, &rfd, 0, 0, 0); 339 select (respipe[0] + 1, &rfd, 0, 0, 0);
309 poll_cb (); 340 poll_cb (aTHX);
310 } 341 }
311 342
312void 343void
313aio_open(pathname,flags,mode,callback) 344aio_open(pathname,flags,mode,callback)
314 SV * pathname 345 SV * pathname

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines