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.21 by root, Fri Aug 6 17:18:08 2004 UTC vs.
Revision 1.24 by root, Sat Jul 2 13:16:33 2005 UTC

13 13
14typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ 14typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */
15typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ 15typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */
16typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ 16typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */
17 17
18#define STACKSIZE 1024 /* yeah */ 18#define STACKSIZE (128 * sizeof (long)) /* yeah */
19 19
20enum { 20enum {
21 REQ_QUIT, 21 REQ_QUIT,
22 REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE, 22 REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE,
23 REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK 23 REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK
62 aio_thread *thr; 62 aio_thread *thr;
63 63
64 New (0, thr, 1, aio_thread); 64 New (0, thr, 1, aio_thread);
65 65
66 if (clone (aio_proc, 66 if (clone (aio_proc,
67 &(thr->stack[STACKSIZE]), 67 &(thr->stack[STACKSIZE - sizeof (long)]),
68 CLONE_VM|CLONE_FS|CLONE_FILES, 68 CLONE_VM|CLONE_FS|CLONE_FILES,
69 thr) >= 0) 69 thr) >= 0)
70 started++; 70 started++;
71 else 71 else
72 Safefree (thr); 72 Safefree (thr);
88{ 88{
89 nreqs++; 89 nreqs++;
90 req->next = 0; 90 req->next = 0;
91 91
92 if (qe) 92 if (qe)
93 {
93 qe->next = req; 94 qe->next = req;
95 qe = req;
96 }
94 else 97 else
95 qe = qs = req; 98 qe = qs = req;
96 99
97 send_reqs (); 100 send_reqs ();
98} 101}
154 req->callback = SvREFCNT_inc (callback); 157 req->callback = SvREFCNT_inc (callback);
155 158
156 send_req (req); 159 send_req (req);
157} 160}
158 161
162static void
163poll_wait ()
164{
165 fd_set rfd;
166 FD_ZERO(&rfd);
167 FD_SET(respipe[0], &rfd);
168
169 select (respipe[0] + 1, &rfd, 0, 0, 0);
170}
171
159static int 172static int
160poll_cb (pTHX) 173poll_cb (pTHX)
161{ 174{
162 dSP; 175 dSP;
163 int count = 0; 176 int count = 0;
164 aio_req req; 177 aio_req req;
165 178
166 while (read (respipe[0], (void *)&req, sizeof (req)) == sizeof (req)) 179 while (read (respipe[0], (void *)&req, sizeof (req)) == sizeof (req))
167 { 180 {
181 nreqs--;
182
168 if (req->type == REQ_QUIT) 183 if (req->type == REQ_QUIT)
169 { 184 {
170 Safefree (req->thread); 185 Safefree (req->thread);
171 started--; 186 started--;
172 } 187 }
199 214
200 if (req->callback) 215 if (req->callback)
201 SvREFCNT_dec (req->callback); 216 SvREFCNT_dec (req->callback);
202 217
203 errno = errorno; 218 errno = errorno;
204 nreqs--;
205 count++; 219 count++;
206 } 220 }
207 221
208 Safefree (req); 222 Safefree (req);
209 } 223 }
248 _syscall3(int,write,int,fd,char *,buf,size_t,count) 262 _syscall3(int,write,int,fd,char *,buf,size_t,count)
249 263
250 _syscall3(int,open,char *,pathname,int,flags,mode_t,mode) 264 _syscall3(int,open,char *,pathname,int,flags,mode_t,mode)
251 _syscall1(int,close,int,fd) 265 _syscall1(int,close,int,fd)
252 266
267#define arch64 (__ia64 || __alpha)
268
253#ifdef __NR_pread64 269#ifdef __NR_pread64 && !arch64
254 _syscall5(int,pread64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) 270 _syscall5(int,pread64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi)
255 _syscall5(int,pwrite64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) 271 _syscall5(int,pwrite64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi)
256#elif __NR_pread 272#elif __NR_pread
257 _syscall4(int,pread,int,fd,char *,buf,size_t,count,offset_t,offset) 273 _syscall4(int,pread,int,fd,char *,buf,size_t,count,offset_t,offset)
258 _syscall4(int,pwrite,int,fd,char *,buf,size_t,count,offset_t,offset) 274 _syscall4(int,pwrite,int,fd,char *,buf,size_t,count,offset_t,offset)
259#else 275#else
260# error "neither pread nor pread64 defined" 276# error "neither pread nor pread64 defined"
261#endif 277#endif
262 278
263 279
264#ifdef __NR_stat64 280#ifdef __NR_stat64 && !arch64
265 _syscall2(int,stat64, const char *, filename, struct stat64 *, buf) 281 _syscall2(int,stat64, const char *, filename, struct stat64 *, buf)
266 _syscall2(int,lstat64, const char *, filename, struct stat64 *, buf) 282 _syscall2(int,lstat64, const char *, filename, struct stat64 *, buf)
267 _syscall2(int,fstat64, int, fd, struct stat64 *, buf) 283 _syscall2(int,fstat64, int, fd, struct stat64 *, buf)
268#elif __NR_stat 284#elif __NR_stat
269 _syscall2(int,stat, const char *, filename, struct stat *, buf) 285 _syscall2(int,stat, const char *, filename, struct stat *, buf)
361 cur--; 377 cur--;
362 } 378 }
363 379
364 while (started > nthreads) 380 while (started > nthreads)
365 { 381 {
366 fd_set rfd; 382 poll_wait ();
367 FD_ZERO(&rfd);
368 FD_SET(respipe[0], &rfd);
369
370 select (respipe[0] + 1, &rfd, 0, 0, 0);
371 poll_cb (aTHX); 383 poll_cb (aTHX);
372 } 384 }
373 385
374void 386void
375aio_open(pathname,flags,mode,callback) 387aio_open(pathname,flags,mode,callback)
508 CODE: 520 CODE:
509 RETVAL = poll_cb (aTHX); 521 RETVAL = poll_cb (aTHX);
510 OUTPUT: 522 OUTPUT:
511 RETVAL 523 RETVAL
512 524
525void
526poll_wait()
527 PROTOTYPE:
528 CODE:
529 poll_wait ();
530
513int 531int
514nreqs() 532nreqs()
515 PROTOTYPE: 533 PROTOTYPE:
516 CODE: 534 CODE:
517 RETVAL = nreqs; 535 RETVAL = nreqs;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines