1 |
#include "EXTERN.h" |
2 |
#include "perl.h" |
3 |
#include "XSUB.h" |
4 |
|
5 |
#include <sys/types.h> |
6 |
#include <unistd.h> |
7 |
#include <sched.h> |
8 |
|
9 |
#define STACKSIZE 128 /* yeah */ |
10 |
|
11 |
#define REQ_EXIT 0 |
12 |
#define REQ_READ 1 |
13 |
#define REQ_WRITE 2 |
14 |
|
15 |
typedef struct { |
16 |
char stack[STACKSIZE]; |
17 |
} aio_thread; |
18 |
|
19 |
typedef struct { |
20 |
int type; |
21 |
aio_thread *thread; |
22 |
|
23 |
/* read/write */ |
24 |
int fd; |
25 |
off_t offset; |
26 |
size_t length; |
27 |
ssize_t done; |
28 |
int errorno; |
29 |
|
30 |
SV *data; |
31 |
void *dataptr; |
32 |
STRLEN offset; |
33 |
} aio_cb; |
34 |
|
35 |
typedef aio_cb *aio_req; |
36 |
|
37 |
static int started; |
38 |
static int reqpipe[2], respipe[2]; |
39 |
|
40 |
static void |
41 |
start_thread(void) |
42 |
{ |
43 |
aio_thread *thr = NEW ( |
44 |
__clone (aio_proc, |
45 |
} |
46 |
|
47 |
static void |
48 |
end_thread(void) |
49 |
{ |
50 |
aio_req req = 0; |
51 |
write (reqpipe[1], &req, sizeof (aio_req)); |
52 |
nthreads--; |
53 |
} |
54 |
|
55 |
MODULE = Linux::AIO PACKAGE = Linux::AIO |
56 |
|
57 |
BOOT: |
58 |
{ |
59 |
if (pipe (reqpipe) || pipe (respipe)) |
60 |
croak ("unable to initialize request or result pipe"); |
61 |
} |
62 |
|
63 |
void |
64 |
min_parallel(nthreads) |
65 |
int nthreads |
66 |
CODE: |
67 |
while (nthreads > started) |
68 |
start_thread (); |
69 |
|
70 |
void |
71 |
max_parallel(nthreads) |
72 |
int nthreads |
73 |
CODE: |
74 |
while (started > nthreads) |
75 |
end_thread (); |
76 |
|
77 |
void |
78 |
read(fh,offset,length,data,dataoffset,callback) |
79 |
CODE: |