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.9 by root, Thu Aug 16 18:58:34 2001 UTC vs.
Revision 1.12 by root, Tue Dec 25 02:33:48 2001 UTC

6#include <unistd.h> 6#include <unistd.h>
7#include <fcntl.h> 7#include <fcntl.h>
8#include <signal.h> 8#include <signal.h>
9#include <sched.h> 9#include <sched.h>
10 10
11typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */
12
11#define STACKSIZE 1024 /* yeah */ 13#define STACKSIZE 1024 /* yeah */
12 14
13enum { REQ_QUIT, REQ_READ, REQ_WRITE, REQ_OPEN }; 15enum { REQ_QUIT, REQ_READ, REQ_WRITE, REQ_OPEN, REQ_CLOSE };
14 16
15typedef struct { 17typedef struct {
16 char stack[STACKSIZE]; 18 char stack[STACKSIZE];
17} aio_thread; 19} aio_thread;
18 20
170{ 172{
171 aio_thread *thr = thr_arg; 173 aio_thread *thr = thr_arg;
172 aio_req req; 174 aio_req req;
173 int errno; 175 int errno;
174 176
177 /* we rely on gcc's ability to create closures. */
178 _syscall3(int,lseek,int,fd,off_t,offset,int,whence)
179 _syscall3(int,read,int,fd,char *,buf,off_t,count)
180 _syscall3(int,write,int,fd,char *,buf,off_t,count)
181 _syscall3(int,open,char *,pathname,int,flags,mode_t,mode)
182 _syscall1(int,close,int,fd)
183
175 sigprocmask (SIG_SETMASK, &fullsigset, 0); 184 sigprocmask (SIG_SETMASK, &fullsigset, 0);
176
177 /* we rely on gcc's ability to create closures. */
178 _syscall3(int,lseek,int,fd,off_t,offset,int,whence);
179 _syscall3(int,read,int,fd,char *,buf,off_t,count);
180 _syscall3(int,write,int,fd,char *,buf,off_t,count);
181 _syscall3(int,open,char *,pathname,int,flags,mode_t,mode);
182 185
183 /* then loop */ 186 /* then loop */
184 while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req)) 187 while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req))
185 { 188 {
186 req->thread = thr; 189 req->thread = thr;
197 } 200 }
198 } 201 }
199 else if (req->type == REQ_OPEN) 202 else if (req->type == REQ_OPEN)
200 { 203 {
201 req->result = open (req->dataptr, req->fd, req->mode); 204 req->result = open (req->dataptr, req->fd, req->mode);
205 }
206 else if (req->type == REQ_CLOSE)
207 {
208 req->result = close (req->fd);
202 } 209 }
203 else 210 else
204 { 211 {
205 write (respipe[1], (void *)&req, sizeof (req)); 212 write (respipe[1], (void *)&req, sizeof (req));
206 break; 213 break;
252 259
253 poll_cb (); 260 poll_cb ();
254 while (started > nthreads) 261 while (started > nthreads)
255 { 262 {
256 sched_yield (); 263 sched_yield ();
264 fcntl (respipe[0], F_SETFL, 0);
257 poll_cb (); 265 poll_cb ();
266 fcntl (respipe[0], F_SETFL, O_NONBLOCK);
258 } 267 }
259 268
260void 269void
261aio_read(fh,offset,length,data,dataoffset,callback) 270aio_read(fh,offset,length,data,dataoffset,callback)
262 PerlIO * fh 271 InOutStream fh
263 UV offset 272 UV offset
264 STRLEN length 273 IV length
265 SV * data 274 SV * data
266 STRLEN dataoffset 275 IV dataoffset
267 SV * callback 276 SV * callback
268 PROTOTYPE: $$$$$$ 277 PROTOTYPE: $$$$$$
269 ALIAS: 278 ALIAS:
270 aio_write = 1 279 aio_write = 1
271 CODE: 280 CODE:
294 req->mode = mode; 303 req->mode = mode;
295 req->callback = SvREFCNT_inc (callback); 304 req->callback = SvREFCNT_inc (callback);
296 305
297 send_req (req); 306 send_req (req);
298 307
308void
309aio_close(fh,callback)
310 InOutStream fh
311 SV * callback
312 PROTOTYPE: $
313 CODE:
314 aio_req req;
315
316 New (0, req, 1, aio_cb);
317
318 if (!req)
319 croak ("out of memory during aio_req allocation");
320
321 req->type = REQ_CLOSE;
322 req->fd = PerlIO_fileno (fh);
323 req->callback = SvREFCNT_inc (callback);
324
325 send_req (req);
326
299int 327int
300poll_fileno() 328poll_fileno()
301 PROTOTYPE: 329 PROTOTYPE:
302 CODE: 330 CODE:
303 RETVAL = respipe[0]; 331 RETVAL = respipe[0];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines