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