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.13 by root, Mon Apr 1 20:30:08 2002 UTC vs.
Revision 1.15 by root, Sat May 18 21:48:36 2002 UTC

22} aio_thread; 22} aio_thread;
23 23
24typedef struct { 24typedef struct {
25 int type; 25 int type;
26 aio_thread *thread; 26 aio_thread *thread;
27
28 SV *savesv;
29 27
30 int fd; 28 int fd;
31 off_t offset; 29 off_t offset;
32 size_t length; 30 size_t length;
33 ssize_t result; 31 ssize_t result;
110 } 108 }
111 109
112 if (length < 0) 110 if (length < 0)
113 croak ("length must not be negative"); 111 croak ("length must not be negative");
114 112
115 New (0, req, 1, aio_cb); 113 Newz (0, req, 1, aio_cb);
116 114
117 if (!req) 115 if (!req)
118 croak ("out of memory during aio_req allocation"); 116 croak ("out of memory during aio_req allocation");
119 117
120 req->type = dowrite ? REQ_WRITE : REQ_READ; 118 req->type = dowrite ? REQ_WRITE : REQ_READ;
145 else 143 else
146 { 144 {
147 int errorno = errno; 145 int errorno = errno;
148 errno = req->errorno; 146 errno = req->errorno;
149 147
150 if (req->savesv)
151 SvREFCNT_dec (req->savesv);
152
153 if (req->type == REQ_READ) 148 if (req->type == REQ_READ)
154 SvCUR_set (req->data, req->dataoffset 149 SvCUR_set (req->data, req->dataoffset
155 + req->result > 0 ? req->result : 0); 150 + req->result > 0 ? req->result : 0);
151
152 if (req->data)
153 SvREFCNT_dec (req->data);
156 154
157 if (req->type == REQ_STAT || req->type == REQ_LSTAT || req->type == REQ_FSTAT) 155 if (req->type == REQ_STAT || req->type == REQ_LSTAT || req->type == REQ_FSTAT)
158 { 156 {
159 PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; 157 PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT;
160 PL_laststatval = req->result; 158 PL_laststatval = req->result;
179 XPUSHs (sv_2mortal (newSViv (req->result))); 177 XPUSHs (sv_2mortal (newSViv (req->result)));
180 PUTBACK; 178 PUTBACK;
181 call_sv (req->callback, G_VOID); 179 call_sv (req->callback, G_VOID);
182 SPAGAIN; 180 SPAGAIN;
183 181
184 SvREFCNT_dec (req->data); 182 if (req->callback)
185 SvREFCNT_dec (req->callback); 183 SvREFCNT_dec (req->callback);
186 184
187 errno = errorno; 185 errno = errorno;
188 nreqs--; 186 nreqs--;
189 count++; 187 count++;
190 } 188 }
205{ 203{
206 aio_thread *thr = thr_arg; 204 aio_thread *thr = thr_arg;
207 aio_req req; 205 aio_req req;
208 int errno; 206 int errno;
209 207
208 /* this is very much x86 and kernel-specific :(:(:( */
210 /* we rely on gcc's ability to create closures. */ 209 /* we rely on gcc's ability to create closures. */
211 _syscall3(int,read,int,fd,char *,buf,size_t,count) 210 _syscall3(int,read,int,fd,char *,buf,size_t,count)
212 _syscall3(int,write,int,fd,char *,buf,size_t,count) 211 _syscall3(int,write,int,fd,char *,buf,size_t,count)
213 212
214 _syscall3(int,open,char *,pathname,int,flags,mode_t,mode) 213 _syscall3(int,open,char *,pathname,int,flags,mode_t,mode)
215 _syscall1(int,close,int,fd) 214 _syscall1(int,close,int,fd)
216 215
217 _syscall4(int,pread,int,fd,char *,buf,size_t,count,off_t,offset) 216 _syscall5(int,pread,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi)
218 _syscall4(int,pwrite,int,fd,char *,buf,size_t,count,off_t,offset) 217 _syscall5(int,pwrite,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi)
219 218
220 _syscall2(int,stat64, const char *, filename, struct stat64 *, buf) 219 _syscall2(int,stat64, const char *, filename, struct stat64 *, buf)
221 _syscall2(int,lstat64, const char *, filename, struct stat64 *, buf) 220 _syscall2(int,lstat64, const char *, filename, struct stat64 *, buf)
222 _syscall2(int,fstat64, int, fd, struct stat64 *, buf) 221 _syscall2(int,fstat64, int, fd, struct stat64 *, buf)
223 222
225 224
226 /* then loop */ 225 /* then loop */
227 while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req)) 226 while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req))
228 { 227 {
229 req->thread = thr; 228 req->thread = thr;
230 errno = 0; 229 errno = 0; /* strictly unnecessary */
231 230
232 if (req->type == REQ_READ) 231 if (req->type == REQ_READ)
233 req->result = pread (req->fd, req->dataptr, req->length, req->offset); 232 req->result = pread (req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32);
234 else if (req->type == REQ_WRITE) 233 else if (req->type == REQ_WRITE)
235 req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); 234 req->result = pwrite(req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32);
236 else if (req->type == REQ_OPEN) 235 else if (req->type == REQ_OPEN)
237 req->result = open (req->dataptr, req->fd, req->mode); 236 req->result = open (req->dataptr, req->fd, req->mode);
238 else if (req->type == REQ_CLOSE) 237 else if (req->type == REQ_CLOSE)
239 req->result = close (req->fd); 238 req->result = close (req->fd);
240 else if (req->type == REQ_STAT) 239 else if (req->type == REQ_STAT)
291 { 290 {
292 end_thread (); 291 end_thread ();
293 cur--; 292 cur--;
294 } 293 }
295 294
296 poll_cb ();
297 while (started > nthreads) 295 while (started > nthreads)
298 { 296 {
299 sched_yield (); 297 fd_set rfd;
300 fcntl (respipe[0], F_SETFL, 0); 298 FD_ZERO(&rfd);
299 FD_SET(respipe[0], &rfd);
300
301 select (respipe[0] + 1, &rfd, 0, 0, 0);
301 poll_cb (); 302 poll_cb ();
302 fcntl (respipe[0], F_SETFL, O_NONBLOCK);
303 } 303 }
304 304
305void 305void
306aio_open(pathname,flags,mode,callback) 306aio_open(pathname,flags,mode,callback)
307 SV * pathname 307 SV * pathname
310 SV * callback 310 SV * callback
311 PROTOTYPE: $$$$ 311 PROTOTYPE: $$$$
312 CODE: 312 CODE:
313 aio_req req; 313 aio_req req;
314 314
315 New (0, req, 1, aio_cb); 315 Newz (0, req, 1, aio_cb);
316 316
317 if (!req) 317 if (!req)
318 croak ("out of memory during aio_req allocation"); 318 croak ("out of memory during aio_req allocation");
319 319
320 req->type = REQ_OPEN; 320 req->type = REQ_OPEN;
321 req->savesv = newSVsv (pathname); 321 req->data = newSVsv (pathname);
322 req->dataptr = SvPV_nolen (req->savesv); 322 req->dataptr = SvPV_nolen (req->data);
323 req->fd = flags; 323 req->fd = flags;
324 req->mode = mode; 324 req->mode = mode;
325 req->callback = SvREFCNT_inc (callback); 325 req->callback = SvREFCNT_inc (callback);
326 326
327 send_req (req); 327 send_req (req);
328 328
329void 329void
330aio_close(fh,callback) 330aio_close(fh,callback)
331 InputStream fh 331 InputStream fh
332 SV * callback 332 SV * callback
333 PROTOTYPE: $ 333 PROTOTYPE: $$
334 CODE: 334 CODE:
335 aio_req req; 335 aio_req req;
336 336
337 New (0, req, 1, aio_cb); 337 Newz (0, req, 1, aio_cb);
338 338
339 if (!req) 339 if (!req)
340 croak ("out of memory during aio_req allocation"); 340 croak ("out of memory during aio_req allocation");
341 341
342 req->type = REQ_CLOSE; 342 req->type = REQ_CLOSE;
377 ALIAS: 377 ALIAS:
378 aio_lstat = 1 378 aio_lstat = 1
379 CODE: 379 CODE:
380 aio_req req; 380 aio_req req;
381 381
382 New (0, req, 1, aio_cb); 382 Newz (0, req, 1, aio_cb);
383 383
384 if (!req) 384 if (!req)
385 croak ("out of memory during aio_req allocation"); 385 croak ("out of memory during aio_req allocation");
386 386
387 New (0, req->statdata, 1, struct stat64); 387 New (0, req->statdata, 1, struct stat64);
390 croak ("out of memory during aio_req->statdata allocation"); 390 croak ("out of memory during aio_req->statdata allocation");
391 391
392 if (SvPOK (fh_or_path)) 392 if (SvPOK (fh_or_path))
393 { 393 {
394 req->type = ix ? REQ_LSTAT : REQ_STAT; 394 req->type = ix ? REQ_LSTAT : REQ_STAT;
395 req->savesv = newSVsv (fh_or_path); 395 req->data = newSVsv (fh_or_path);
396 req->dataptr = SvPV_nolen (req->savesv); 396 req->dataptr = SvPV_nolen (req->data);
397 } 397 }
398 else 398 else
399 { 399 {
400 req->type = REQ_FSTAT; 400 req->type = REQ_FSTAT;
401 req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); 401 req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines