… | |
… | |
8 | #include <sys/stat.h> |
8 | #include <sys/stat.h> |
9 | #include <unistd.h> |
9 | #include <unistd.h> |
10 | #include <fcntl.h> |
10 | #include <fcntl.h> |
11 | #include <signal.h> |
11 | #include <signal.h> |
12 | #include <sched.h> |
12 | #include <sched.h> |
|
|
13 | #include <endian.h> |
13 | |
14 | |
14 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
15 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
15 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
16 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
16 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
17 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
17 | |
18 | |
18 | #ifndef __NR_pread64 |
19 | #if __i386 || __amd64 |
19 | # define __NR_pread64 __NR_pread |
20 | # define STACKSIZE ( 256 * sizeof (long)) |
|
|
21 | #elif __ia64 |
|
|
22 | # define STACKSIZE (8192 * sizeof (long)) |
|
|
23 | #else |
|
|
24 | # define STACKSIZE ( 512 * sizeof (long)) |
20 | #endif |
25 | #endif |
21 | #ifndef __NR_pwrite64 |
|
|
22 | # define __NR_pwrite64 __NR_pwrite |
|
|
23 | #endif |
|
|
24 | |
26 | |
25 | #define STACKSIZE 1024 /* yeah */ |
27 | enum { |
26 | |
28 | REQ_QUIT, |
27 | enum { REQ_QUIT, REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE, REQ_STAT, REQ_LSTAT, REQ_FSTAT}; |
29 | REQ_OPEN, REQ_CLOSE, |
|
|
30 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
|
|
31 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK, |
|
|
32 | REQ_FSYNC, REQ_FDATASYNC, |
|
|
33 | }; |
28 | |
34 | |
29 | typedef struct { |
35 | typedef struct { |
30 | char stack[STACKSIZE]; |
36 | char stack[STACKSIZE]; |
31 | } aio_thread; |
37 | } aio_thread; |
32 | |
38 | |
33 | typedef struct { |
39 | typedef struct aio_cb { |
|
|
40 | struct aio_cb *next; |
|
|
41 | |
34 | int type; |
42 | int type; |
35 | aio_thread *thread; |
43 | aio_thread *thread; |
36 | |
44 | |
37 | int fd; |
45 | int fd; |
38 | off_t offset; |
46 | off_t offset; |
… | |
… | |
42 | int errorno; |
50 | int errorno; |
43 | SV *data, *callback; |
51 | SV *data, *callback; |
44 | void *dataptr; |
52 | void *dataptr; |
45 | STRLEN dataoffset; |
53 | STRLEN dataoffset; |
46 | |
54 | |
47 | struct stat64 *statdata; |
55 | Stat_t *statdata; |
48 | } aio_cb; |
56 | } aio_cb; |
49 | |
57 | |
50 | typedef aio_cb *aio_req; |
58 | typedef aio_cb *aio_req; |
51 | |
59 | |
52 | static int started; |
60 | static int started; |
53 | static int nreqs; |
61 | static int nreqs; |
54 | static int reqpipe[2], respipe[2]; |
62 | static int reqpipe[2], respipe[2]; |
55 | |
63 | |
|
|
64 | static aio_req qs, qe; /* queue start, queue end */ |
|
|
65 | |
56 | static int aio_proc(void *arg); |
66 | static int aio_proc(void *arg); |
57 | |
67 | |
58 | static void |
68 | static void |
59 | start_thread(void) |
69 | start_thread (void) |
60 | { |
70 | { |
61 | aio_thread *thr; |
71 | aio_thread *thr; |
62 | |
72 | |
63 | New (0, thr, 1, aio_thread); |
73 | New (0, thr, 1, aio_thread); |
64 | |
74 | |
65 | if (clone (aio_proc, |
75 | if (clone (aio_proc, |
66 | &(thr->stack[STACKSIZE]), |
76 | &(thr->stack[STACKSIZE - 16]), |
67 | CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND, |
77 | CLONE_VM|CLONE_FS|CLONE_FILES, |
68 | thr) >= 0) |
78 | thr) >= 0) |
69 | started++; |
79 | started++; |
70 | else |
80 | else |
71 | Safefree (thr); |
81 | Safefree (thr); |
72 | } |
82 | } |
73 | |
83 | |
74 | static void |
84 | static void |
|
|
85 | send_reqs (void) |
|
|
86 | { |
|
|
87 | /* this write is atomic */ |
|
|
88 | while (qs && write (reqpipe[1], &qs, sizeof qs) == sizeof qs) |
|
|
89 | { |
|
|
90 | qs = qs->next; |
|
|
91 | if (!qs) qe = 0; |
|
|
92 | } |
|
|
93 | } |
|
|
94 | |
|
|
95 | static void |
|
|
96 | send_req (aio_req req) |
|
|
97 | { |
|
|
98 | nreqs++; |
|
|
99 | req->next = 0; |
|
|
100 | |
|
|
101 | if (qe) |
|
|
102 | { |
|
|
103 | qe->next = req; |
|
|
104 | qe = req; |
|
|
105 | } |
|
|
106 | else |
|
|
107 | qe = qs = req; |
|
|
108 | |
|
|
109 | send_reqs (); |
|
|
110 | } |
|
|
111 | |
|
|
112 | static void |
75 | end_thread(void) |
113 | end_thread (void) |
76 | { |
114 | { |
77 | aio_req req; |
115 | aio_req req; |
78 | New (0, req, 1, aio_cb); |
116 | New (0, req, 1, aio_cb); |
79 | req->type = REQ_QUIT; |
117 | req->type = REQ_QUIT; |
80 | write (reqpipe[1], &req, sizeof (aio_req)); |
|
|
81 | } |
|
|
82 | |
118 | |
83 | static void |
119 | send_req (req); |
84 | send_req (aio_req req) |
|
|
85 | { |
|
|
86 | nreqs++; |
|
|
87 | write (reqpipe[1], &req, sizeof (aio_req)); |
|
|
88 | } |
120 | } |
89 | |
121 | |
90 | static void |
122 | static void |
91 | read_write (pTHX_ |
123 | read_write (pTHX_ |
92 | int dowrite, int fd, off_t offset, size_t length, |
124 | int dowrite, int fd, off_t offset, size_t length, |
93 | SV *data, STRLEN dataoffset, SV*callback) |
125 | SV *data, STRLEN dataoffset, SV *callback) |
94 | { |
126 | { |
95 | aio_req req; |
127 | aio_req req; |
96 | STRLEN svlen; |
128 | STRLEN svlen; |
97 | char *svptr = SvPV (data, svlen); |
129 | char *svptr = SvPV (data, svlen); |
98 | |
130 | |
… | |
… | |
134 | req->callback = SvREFCNT_inc (callback); |
166 | req->callback = SvREFCNT_inc (callback); |
135 | |
167 | |
136 | send_req (req); |
168 | send_req (req); |
137 | } |
169 | } |
138 | |
170 | |
|
|
171 | static void |
|
|
172 | poll_wait () |
|
|
173 | { |
|
|
174 | fd_set rfd; |
|
|
175 | FD_ZERO(&rfd); |
|
|
176 | FD_SET(respipe[0], &rfd); |
|
|
177 | |
|
|
178 | select (respipe[0] + 1, &rfd, 0, 0, 0); |
|
|
179 | } |
|
|
180 | |
139 | static int |
181 | static int |
140 | poll_cb (pTHX) |
182 | poll_cb (pTHX) |
141 | { |
183 | { |
142 | dSP; |
184 | dSP; |
143 | int count = 0; |
185 | int count = 0; |
144 | aio_req req; |
186 | aio_req req; |
145 | |
187 | |
146 | while (read (respipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
188 | while (read (respipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
147 | { |
189 | { |
|
|
190 | nreqs--; |
|
|
191 | |
148 | if (req->type == REQ_QUIT) |
192 | if (req->type == REQ_QUIT) |
149 | { |
193 | { |
150 | Safefree (req->thread); |
194 | Safefree (req->thread); |
151 | started--; |
195 | started--; |
152 | } |
196 | } |
… | |
… | |
162 | if (req->data) |
206 | if (req->data) |
163 | SvREFCNT_dec (req->data); |
207 | SvREFCNT_dec (req->data); |
164 | |
208 | |
165 | if (req->type == REQ_STAT || req->type == REQ_LSTAT || req->type == REQ_FSTAT) |
209 | if (req->type == REQ_STAT || req->type == REQ_LSTAT || req->type == REQ_FSTAT) |
166 | { |
210 | { |
167 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
211 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
168 | PL_laststatval = req->result; |
212 | PL_laststatval = req->result; |
169 | PL_statcache.st_dev = req->statdata->st_dev; |
213 | PL_statcache = *(req->statdata); |
170 | PL_statcache.st_ino = req->statdata->st_ino; |
|
|
171 | PL_statcache.st_mode = req->statdata->st_mode; |
|
|
172 | PL_statcache.st_nlink = req->statdata->st_nlink; |
|
|
173 | PL_statcache.st_uid = req->statdata->st_uid; |
|
|
174 | PL_statcache.st_gid = req->statdata->st_gid; |
|
|
175 | PL_statcache.st_rdev = req->statdata->st_rdev; |
|
|
176 | PL_statcache.st_size = req->statdata->st_size; |
|
|
177 | PL_statcache.st_atime = req->statdata->st_atime; |
|
|
178 | PL_statcache.st_mtime = req->statdata->st_mtime; |
|
|
179 | PL_statcache.st_ctime = req->statdata->st_ctime; |
|
|
180 | PL_statcache.st_blksize = req->statdata->st_blksize; |
|
|
181 | PL_statcache.st_blocks = req->statdata->st_blocks; |
|
|
182 | |
214 | |
183 | Safefree (req->statdata); |
215 | Safefree (req->statdata); |
184 | } |
216 | } |
185 | |
217 | |
186 | PUSHMARK (SP); |
218 | PUSHMARK (SP); |
… | |
… | |
191 | |
223 | |
192 | if (req->callback) |
224 | if (req->callback) |
193 | SvREFCNT_dec (req->callback); |
225 | SvREFCNT_dec (req->callback); |
194 | |
226 | |
195 | errno = errorno; |
227 | errno = errorno; |
196 | nreqs--; |
|
|
197 | count++; |
228 | count++; |
198 | } |
229 | } |
199 | |
230 | |
200 | Safefree (req); |
231 | Safefree (req); |
201 | } |
232 | } |
202 | |
233 | |
|
|
234 | if (qs) |
|
|
235 | send_reqs (); |
|
|
236 | |
203 | return count; |
237 | return count; |
204 | } |
238 | } |
205 | |
239 | |
206 | static sigset_t fullsigset; |
240 | static sigset_t fullsigset; |
207 | |
241 | |
208 | #undef errno |
242 | #undef errno |
209 | #include <asm/unistd.h> |
243 | #include <asm/unistd.h> |
|
|
244 | #include <linux/types.h> |
|
|
245 | #include <sys/prctl.h> |
|
|
246 | |
|
|
247 | #if __alpha || __ia64 || __hppa || __v850__ |
|
|
248 | # define stat kernelstat |
|
|
249 | # define stat64 kernelstat64 |
|
|
250 | # include <asm/stat.h> |
|
|
251 | # undef stat |
|
|
252 | # undef stat64 |
|
|
253 | #else |
|
|
254 | # define kernelstat stat |
|
|
255 | # define kernelstat64 stat64 |
|
|
256 | #endif |
|
|
257 | |
|
|
258 | #define COPY_STATDATA \ |
|
|
259 | req->statdata->st_dev = statdata.st_dev; \ |
|
|
260 | req->statdata->st_ino = statdata.st_ino; \ |
|
|
261 | req->statdata->st_mode = statdata.st_mode; \ |
|
|
262 | req->statdata->st_nlink = statdata.st_nlink; \ |
|
|
263 | req->statdata->st_uid = statdata.st_uid; \ |
|
|
264 | req->statdata->st_gid = statdata.st_gid; \ |
|
|
265 | req->statdata->st_rdev = statdata.st_rdev; \ |
|
|
266 | req->statdata->st_size = statdata.st_size; \ |
|
|
267 | req->statdata->st_atime = statdata.st_atime; \ |
|
|
268 | req->statdata->st_mtime = statdata.st_mtime; \ |
|
|
269 | req->statdata->st_ctime = statdata.st_ctime; \ |
|
|
270 | req->statdata->st_blksize = statdata.st_blksize; \ |
|
|
271 | req->statdata->st_blocks = statdata.st_blocks; \ |
210 | |
272 | |
211 | static int |
273 | static int |
212 | aio_proc(void *thr_arg) |
274 | aio_proc (void *thr_arg) |
213 | { |
275 | { |
214 | aio_thread *thr = thr_arg; |
276 | aio_thread *thr = thr_arg; |
215 | aio_req req; |
277 | aio_req req; |
216 | int errno; |
278 | int errno; |
217 | |
279 | |
218 | /* this is very much x86 and kernel-specific :(:(:( */ |
280 | /* this is very much kernel-specific :(:(:( */ |
219 | /* we rely on gcc's ability to create closures. */ |
281 | /* we rely on gcc's ability to create closures. */ |
220 | _syscall3(int,read,int,fd,char *,buf,size_t,count) |
282 | _syscall3(__kernel_size_t, read , unsigned int, fd, char *, buf, __kernel_size_t, count) |
221 | _syscall3(int,write,int,fd,char *,buf,size_t,count) |
283 | _syscall3(__kernel_size_t, write, unsigned int, fd, char *, buf, __kernel_size_t, count) |
222 | |
284 | |
223 | _syscall3(int,open,char *,pathname,int,flags,mode_t,mode) |
285 | _syscall3(long, open, char *, pathname, int, flags, int, mode) |
224 | _syscall1(int,close,int,fd) |
286 | _syscall1(long, close, unsigned int, fd) |
|
|
287 | _syscall1(long, unlink, char *, filename); |
|
|
288 | _syscall1(long, fsync, unsigned int, fd); |
225 | |
289 | |
226 | _syscall5(int,pread64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
290 | #ifndef __NR_fdatasync |
227 | _syscall5(int,pwrite64,int,fd,char *,buf,size_t,count,unsigned int,offset_lo,unsigned int,offset_hi) |
291 | # define __NR_fdatasync __NR_fsync |
|
|
292 | #endif |
|
|
293 | _syscall1(long, fdatasync, unsigned int, fd); |
228 | |
294 | |
|
|
295 | #if BYTE_ORDER == LITTLE_ENDIAN |
|
|
296 | # define LOFF_ARG(off) (off & 0xffffffff), (off >> 32) |
|
|
297 | #elif BYTE_ORDER == BIG_ENDIAN |
|
|
298 | # define LOFF_ARG(off) (off >> 32), (off & 0xffffffff) |
|
|
299 | #endif |
|
|
300 | |
|
|
301 | #ifndef __NR_pread64 |
|
|
302 | # define __NR_pread64 __NR_pread |
|
|
303 | # define __NR_pwrite64 __NR_write |
|
|
304 | #endif |
|
|
305 | _syscall5(__kernel_ssize_t, pread64 , unsigned int, fd, char *, buf, |
|
|
306 | __kernel_size_t, count, unsigned int, offset_lh, unsigned int, offset_hl) |
|
|
307 | _syscall5(__kernel_ssize_t, pwrite64, unsigned int, fd, char *, buf, |
|
|
308 | __kernel_size_t, count, unsigned int, offset_lh, unsigned int, offset_hl) |
|
|
309 | _syscall4(long, readahead, unsigned int, fd, unsigned int, offset_lh, unsigned int, offset_hl, __kernel_size_t, count); |
|
|
310 | |
|
|
311 | #if __NR_stat64 |
229 | _syscall2(int,stat64, const char *, filename, struct stat64 *, buf) |
312 | _syscall2(long, stat64 , const char *, filename, struct kernelstat64 *, buf) |
230 | _syscall2(int,lstat64, const char *, filename, struct stat64 *, buf) |
313 | _syscall2(long, lstat64, const char *, filename, struct kernelstat64 *, buf) |
231 | _syscall2(int,fstat64, int, fd, struct stat64 *, buf) |
314 | _syscall2(long, fstat64, int , fd , struct kernelstat64 *, buf) |
|
|
315 | #elif __NR_stat |
|
|
316 | _syscall2(long, stat , const char *, filename, struct kernelstat *, buf) |
|
|
317 | _syscall2(long, lstat, const char *, filename, struct kernelstat *, buf) |
|
|
318 | _syscall2(long, fstat, int , fd , struct kernelstat *, buf) |
|
|
319 | #else |
|
|
320 | # error "neither stat64 nor stat defined" |
|
|
321 | #endif |
232 | |
322 | |
|
|
323 | /* the following two calls might clobber errno */ |
233 | sigprocmask (SIG_SETMASK, &fullsigset, 0); |
324 | sigprocmask (SIG_SETMASK, &fullsigset, 0); |
|
|
325 | prctl (PR_SET_PDEATHSIG, SIGKILL); |
234 | |
326 | |
235 | /* then loop */ |
327 | /* then loop */ |
236 | while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
328 | while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
237 | { |
329 | { |
238 | req->thread = thr; |
330 | req->thread = thr; |
239 | errno = 0; /* strictly unnecessary */ |
331 | errno = 0; /* strictly unnecessary */ |
240 | |
332 | |
241 | if (req->type == REQ_READ) |
333 | switch (req->type) |
242 | req->result = pread64 (req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); |
|
|
243 | else if (req->type == REQ_WRITE) |
|
|
244 | req->result = pwrite64(req->fd, req->dataptr, req->length, req->offset & 0xffffffff, req->offset >> 32); |
|
|
245 | else if (req->type == REQ_OPEN) |
|
|
246 | req->result = open (req->dataptr, req->fd, req->mode); |
|
|
247 | else if (req->type == REQ_CLOSE) |
|
|
248 | req->result = close (req->fd); |
|
|
249 | else if (req->type == REQ_STAT) |
|
|
250 | req->result = stat64 (req->dataptr, req->statdata); |
|
|
251 | else if (req->type == REQ_LSTAT) |
|
|
252 | req->result = lstat64 (req->dataptr, req->statdata); |
|
|
253 | else if (req->type == REQ_FSTAT) |
|
|
254 | req->result = fstat64 (req->fd, req->statdata); |
|
|
255 | else |
|
|
256 | { |
334 | { |
|
|
335 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, LOFF_ARG (req->offset)); break; |
|
|
336 | case REQ_WRITE: req->result = pwrite64 (req->fd, req->dataptr, req->length, LOFF_ARG (req->offset)); break; |
|
|
337 | case REQ_READAHEAD: req->result = readahead (req->fd, LOFF_ARG (req->offset), req->length); break; |
|
|
338 | |
|
|
339 | #if __NR_stat64 |
|
|
340 | struct kernelstat64 statdata; |
|
|
341 | case REQ_STAT: req->result = stat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
342 | case REQ_LSTAT: req->result = lstat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
343 | case REQ_FSTAT: req->result = fstat64 (req->fd , &statdata); COPY_STATDATA; break; |
|
|
344 | #else |
|
|
345 | struct kernelstat statdata; |
|
|
346 | case REQ_STAT: req->result = stat (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
347 | case REQ_LSTAT: req->result = lstat (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
348 | case REQ_FSTAT: req->result = fstat (req->fd , &statdata); COPY_STATDATA; break; |
|
|
349 | #endif |
|
|
350 | |
|
|
351 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
|
|
352 | case REQ_CLOSE: req->result = close (req->fd); break; |
|
|
353 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
|
|
354 | |
|
|
355 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
|
|
356 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
|
|
357 | |
|
|
358 | case REQ_QUIT: |
257 | write (respipe[1], (void *)&req, sizeof (req)); |
359 | write (respipe[1], (void *)&req, sizeof (req)); |
|
|
360 | return 0; |
|
|
361 | |
|
|
362 | default: |
|
|
363 | req->result = ENOSYS; |
258 | break; |
364 | break; |
259 | } |
365 | } |
260 | |
366 | |
261 | req->errorno = errno; |
367 | req->errorno = errno; |
262 | write (respipe[1], (void *)&req, sizeof (req)); |
368 | write (respipe[1], (void *)&req, sizeof (req)); |
263 | } |
369 | } |
… | |
… | |
275 | sigdelset (&fullsigset, SIGABRT); |
381 | sigdelset (&fullsigset, SIGABRT); |
276 | sigdelset (&fullsigset, SIGINT); |
382 | sigdelset (&fullsigset, SIGINT); |
277 | |
383 | |
278 | if (pipe (reqpipe) || pipe (respipe)) |
384 | if (pipe (reqpipe) || pipe (respipe)) |
279 | croak ("unable to initialize request or result pipe"); |
385 | croak ("unable to initialize request or result pipe"); |
|
|
386 | |
|
|
387 | if (fcntl (reqpipe[1], F_SETFL, O_NONBLOCK)) |
|
|
388 | croak ("cannot set result pipe to nonblocking mode"); |
280 | |
389 | |
281 | if (fcntl (respipe[0], F_SETFL, O_NONBLOCK)) |
390 | if (fcntl (respipe[0], F_SETFL, O_NONBLOCK)) |
282 | croak ("cannot set result pipe to nonblocking mode"); |
391 | croak ("cannot set result pipe to nonblocking mode"); |
283 | } |
392 | } |
284 | |
393 | |
… | |
… | |
293 | void |
402 | void |
294 | max_parallel(nthreads) |
403 | max_parallel(nthreads) |
295 | int nthreads |
404 | int nthreads |
296 | PROTOTYPE: $ |
405 | PROTOTYPE: $ |
297 | CODE: |
406 | CODE: |
|
|
407 | { |
298 | int cur = started; |
408 | int cur = started; |
299 | while (cur > nthreads) |
409 | while (cur > nthreads) |
300 | { |
410 | { |
301 | end_thread (); |
411 | end_thread (); |
302 | cur--; |
412 | cur--; |
303 | } |
413 | } |
304 | |
414 | |
305 | while (started > nthreads) |
415 | while (started > nthreads) |
306 | { |
416 | { |
307 | fd_set rfd; |
417 | poll_wait (); |
308 | FD_ZERO(&rfd); |
|
|
309 | FD_SET(respipe[0], &rfd); |
|
|
310 | |
|
|
311 | select (respipe[0] + 1, &rfd, 0, 0, 0); |
|
|
312 | poll_cb (aTHX); |
418 | poll_cb (aTHX); |
313 | } |
419 | } |
|
|
420 | } |
314 | |
421 | |
315 | void |
422 | void |
316 | aio_open(pathname,flags,mode,callback) |
423 | aio_open(pathname,flags,mode,callback) |
317 | SV * pathname |
424 | SV * pathname |
318 | int flags |
425 | int flags |
319 | int mode |
426 | int mode |
320 | SV * callback |
427 | SV * callback |
321 | PROTOTYPE: $$$$ |
428 | PROTOTYPE: $$$$ |
322 | CODE: |
429 | CODE: |
|
|
430 | { |
323 | aio_req req; |
431 | aio_req req; |
324 | |
432 | |
325 | Newz (0, req, 1, aio_cb); |
433 | Newz (0, req, 1, aio_cb); |
326 | |
434 | |
327 | if (!req) |
435 | if (!req) |
… | |
… | |
333 | req->fd = flags; |
441 | req->fd = flags; |
334 | req->mode = mode; |
442 | req->mode = mode; |
335 | req->callback = SvREFCNT_inc (callback); |
443 | req->callback = SvREFCNT_inc (callback); |
336 | |
444 | |
337 | send_req (req); |
445 | send_req (req); |
|
|
446 | } |
338 | |
447 | |
339 | void |
448 | void |
340 | aio_close(fh,callback) |
449 | aio_close(fh,callback) |
341 | InputStream fh |
450 | InputStream fh |
342 | SV * callback |
451 | SV * callback |
343 | PROTOTYPE: $$ |
452 | PROTOTYPE: $$ |
|
|
453 | ALIAS: |
|
|
454 | aio_close = REQ_CLOSE |
|
|
455 | aio_fsync = REQ_FSYNC |
|
|
456 | aio_fdatasync = REQ_FDATASYNC |
344 | CODE: |
457 | CODE: |
|
|
458 | { |
345 | aio_req req; |
459 | aio_req req; |
346 | |
460 | |
347 | Newz (0, req, 1, aio_cb); |
461 | Newz (0, req, 1, aio_cb); |
348 | |
462 | |
349 | if (!req) |
463 | if (!req) |
350 | croak ("out of memory during aio_req allocation"); |
464 | croak ("out of memory during aio_req allocation"); |
351 | |
465 | |
352 | req->type = REQ_CLOSE; |
466 | req->type = ix; |
353 | req->fd = PerlIO_fileno (fh); |
467 | req->fd = PerlIO_fileno (fh); |
354 | req->callback = SvREFCNT_inc (callback); |
468 | req->callback = SvREFCNT_inc (callback); |
355 | |
469 | |
356 | send_req (req); |
470 | send_req (req); |
|
|
471 | } |
357 | |
472 | |
358 | void |
473 | void |
359 | aio_read(fh,offset,length,data,dataoffset,callback) |
474 | aio_read(fh,offset,length,data,dataoffset,callback) |
360 | InputStream fh |
475 | InputStream fh |
361 | UV offset |
476 | UV offset |
… | |
… | |
378 | PROTOTYPE: $$$$$$ |
493 | PROTOTYPE: $$$$$$ |
379 | CODE: |
494 | CODE: |
380 | read_write (aTHX_ 1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
495 | read_write (aTHX_ 1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
381 | |
496 | |
382 | void |
497 | void |
|
|
498 | aio_readahead(fh,offset,length,callback) |
|
|
499 | InputStream fh |
|
|
500 | UV offset |
|
|
501 | IV length |
|
|
502 | SV * callback |
|
|
503 | PROTOTYPE: $$$$ |
|
|
504 | CODE: |
|
|
505 | { |
|
|
506 | aio_req req; |
|
|
507 | |
|
|
508 | if (length < 0) |
|
|
509 | croak ("length must not be negative"); |
|
|
510 | |
|
|
511 | Newz (0, req, 1, aio_cb); |
|
|
512 | |
|
|
513 | if (!req) |
|
|
514 | croak ("out of memory during aio_req allocation"); |
|
|
515 | |
|
|
516 | req->type = REQ_READAHEAD; |
|
|
517 | req->fd = PerlIO_fileno (fh); |
|
|
518 | req->offset = offset; |
|
|
519 | req->length = length; |
|
|
520 | req->callback = SvREFCNT_inc (callback); |
|
|
521 | |
|
|
522 | send_req (req); |
|
|
523 | } |
|
|
524 | |
|
|
525 | void |
383 | aio_stat(fh_or_path,callback) |
526 | aio_stat(fh_or_path,callback) |
384 | SV * fh_or_path |
527 | SV * fh_or_path |
385 | SV * callback |
528 | SV * callback |
386 | PROTOTYPE: $$ |
529 | PROTOTYPE: $$ |
387 | ALIAS: |
530 | ALIAS: |
388 | aio_lstat = 1 |
531 | aio_lstat = 1 |
389 | CODE: |
532 | CODE: |
|
|
533 | { |
390 | aio_req req; |
534 | aio_req req; |
391 | |
535 | |
392 | Newz (0, req, 1, aio_cb); |
536 | Newz (0, req, 1, aio_cb); |
393 | |
537 | |
394 | if (!req) |
538 | if (!req) |
395 | croak ("out of memory during aio_req allocation"); |
539 | croak ("out of memory during aio_req allocation"); |
396 | |
540 | |
397 | New (0, req->statdata, 1, struct stat64); |
541 | New (0, req->statdata, 1, Stat_t); |
398 | |
542 | |
399 | if (!req->statdata) |
543 | if (!req->statdata) |
400 | croak ("out of memory during aio_req->statdata allocation"); |
544 | croak ("out of memory during aio_req->statdata allocation"); |
401 | |
545 | |
402 | if (SvPOK (fh_or_path)) |
546 | if (SvPOK (fh_or_path)) |
… | |
… | |
412 | } |
556 | } |
413 | |
557 | |
414 | req->callback = SvREFCNT_inc (callback); |
558 | req->callback = SvREFCNT_inc (callback); |
415 | |
559 | |
416 | send_req (req); |
560 | send_req (req); |
|
|
561 | } |
|
|
562 | |
|
|
563 | void |
|
|
564 | aio_unlink(pathname,callback) |
|
|
565 | SV * pathname |
|
|
566 | SV * callback |
|
|
567 | PROTOTYPE: $$ |
|
|
568 | CODE: |
|
|
569 | { |
|
|
570 | aio_req req; |
|
|
571 | |
|
|
572 | Newz (0, req, 1, aio_cb); |
|
|
573 | |
|
|
574 | if (!req) |
|
|
575 | croak ("out of memory during aio_req allocation"); |
|
|
576 | |
|
|
577 | req->type = REQ_UNLINK; |
|
|
578 | req->data = newSVsv (pathname); |
|
|
579 | req->dataptr = SvPV_nolen (req->data); |
|
|
580 | req->callback = SvREFCNT_inc (callback); |
|
|
581 | |
|
|
582 | send_req (req); |
|
|
583 | } |
417 | |
584 | |
418 | int |
585 | int |
419 | poll_fileno() |
586 | poll_fileno() |
420 | PROTOTYPE: |
587 | PROTOTYPE: |
421 | CODE: |
588 | CODE: |
… | |
… | |
429 | CODE: |
596 | CODE: |
430 | RETVAL = poll_cb (aTHX); |
597 | RETVAL = poll_cb (aTHX); |
431 | OUTPUT: |
598 | OUTPUT: |
432 | RETVAL |
599 | RETVAL |
433 | |
600 | |
|
|
601 | void |
|
|
602 | poll_wait() |
|
|
603 | PROTOTYPE: |
|
|
604 | CODE: |
|
|
605 | poll_wait (); |
|
|
606 | |
434 | int |
607 | int |
435 | nreqs() |
608 | nreqs() |
436 | PROTOTYPE: |
609 | PROTOTYPE: |
437 | CODE: |
610 | CODE: |
438 | RETVAL = nreqs; |
611 | RETVAL = nreqs; |