ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.59 by root, Mon Oct 23 18:56:27 2006 UTC vs.
Revision 1.60 by root, Mon Oct 23 20:05:27 2006 UTC

66 66
67typedef struct aio_cb 67typedef struct aio_cb
68{ 68{
69 struct aio_cb *volatile next; 69 struct aio_cb *volatile next;
70 70
71 struct aio_cb *grp, *grp_prev, *grp_next, *grp_first;
72
73 SV *self; /* the perl counterpart of this request, if any */
74
75 SV *data, *callback; 71 SV *data, *callback;
76 SV *fh, *fh2; 72 SV *fh, *fh2;
77 void *dataptr, *data2ptr; 73 void *dataptr, *data2ptr;
78 Stat_t *statdata; 74 Stat_t *statdata;
79 off_t offset; 75 off_t offset;
80 size_t length; 76 size_t length;
81 ssize_t result; 77 ssize_t result;
82 78
79 STRLEN dataoffset;
83 int type; 80 int type;
84 int fd, fd2; 81 int fd, fd2;
85 int errorno; 82 int errorno;
86 STRLEN dataoffset;
87 mode_t mode; /* open */ 83 mode_t mode; /* open */
84
85 unsigned char flags;
88 unsigned char pri; 86 unsigned char pri;
89 unsigned char flags; 87
88 SV *self; /* the perl counterpart of this request, if any */
89 struct aio_cb *grp, *grp_prev, *grp_next, *grp_first;
90} aio_cb; 90} aio_cb;
91 91
92enum { 92enum {
93 FLAG_CANCELLED = 0x01, 93 FLAG_CANCELLED = 0x01,
94}; 94};
95 95
96typedef aio_cb *aio_req; 96typedef aio_cb *aio_req;
97typedef aio_cb *aio_req_ornot; 97typedef aio_cb *aio_req_ornot;
98
99enum {
100 PRI_MIN = 4,
101 PRI_MAX = -4,
102
103 DEFAULT_PRI = 0,
104 PRI_BIAS = PRI_MIN,
105};
106
107static int next_pri = DEFAULT_PRI + PRI_BIAS;
98 108
99static int started, wanted; 109static int started, wanted;
100static volatile int nreqs; 110static volatile int nreqs;
101static int max_outstanding = 1<<30; 111static int max_outstanding = 1<<30;
102static int respipe [2]; 112static int respipe [2];
181 } 191 }
182} 192}
183 193
184static void poll_wait () 194static void poll_wait ()
185{ 195{
186 if (nreqs && !ress) 196 while (nreqs)
187 { 197 {
198 aio_req req;
199 pthread_mutex_lock (&reslock);
200 req = ress;
201 pthread_mutex_unlock (&reslock);
202
203 if (req)
204 return;
205
188 fd_set rfd; 206 fd_set rfd;
189 FD_ZERO(&rfd); 207 FD_ZERO(&rfd);
190 FD_SET(respipe [0], &rfd); 208 FD_SET(respipe [0], &rfd);
191 209
192 select (respipe [0] + 1, &rfd, 0, 0, 0); 210 select (respipe [0] + 1, &rfd, 0, 0, 0);
790 } 808 }
791 809
792 pthread_mutex_unlock (&reqlock); 810 pthread_mutex_unlock (&reqlock);
793 811
794 errno = 0; /* strictly unnecessary */ 812 errno = 0; /* strictly unnecessary */
813 type = req->type; /* remember type for QUIT check */
795 814
796 if (!(req->flags & FLAG_CANCELLED)) 815 if (!(req->flags & FLAG_CANCELLED))
797 switch (type = req->type) /* remember type for QUIT check */ 816 switch (type)
798 { 817 {
799 case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; 818 case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break;
800 case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; 819 case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break;
801 820
802 case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; 821 case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break;
921 atfork_parent (); 940 atfork_parent ();
922} 941}
923 942
924#define dREQ \ 943#define dREQ \
925 aio_req req; \ 944 aio_req req; \
945 int req_pri = next_pri; \
946 next_pri = DEFAULT_PRI + PRI_BIAS; \
926 \ 947 \
927 if (SvOK (callback) && !SvROK (callback)) \ 948 if (SvOK (callback) && !SvROK (callback)) \
928 croak ("callback must be undef or of reference type"); \ 949 croak ("callback must be undef or of reference type"); \
929 \ 950 \
930 Newz (0, req, 1, aio_cb); \ 951 Newz (0, req, 1, aio_cb); \
931 if (!req) \ 952 if (!req) \
932 croak ("out of memory during aio_req allocation"); \ 953 croak ("out of memory during aio_req allocation"); \
933 \ 954 \
934 req->callback = newSVsv (callback) 955 req->callback = newSVsv (callback); \
956 req->pri = req_pri
935 957
936#define REQ_SEND \ 958#define REQ_SEND \
937 req_send (req); \ 959 req_send (req); \
938 \ 960 \
939 if (GIMME_V != G_VOID) \ 961 if (GIMME_V != G_VOID) \
1214 SV * callback 1236 SV * callback
1215 PROTOTYPE: ;$ 1237 PROTOTYPE: ;$
1216 PPCODE: 1238 PPCODE:
1217{ 1239{
1218 dREQ; 1240 dREQ;
1241
1219 req->type = REQ_GROUP; 1242 req->type = REQ_GROUP;
1220 req_send (req); 1243 req_send (req);
1244
1221 XPUSHs (req_sv (req, AIO_GRP_KLASS)); 1245 XPUSHs (req_sv (req, AIO_GRP_KLASS));
1222} 1246}
1223 1247
1224void 1248void
1225aio_nop (callback=&PL_sv_undef) 1249aio_nop (callback=&PL_sv_undef)
1230 1254
1231 req->type = REQ_NOP; 1255 req->type = REQ_NOP;
1232 1256
1233 REQ_SEND; 1257 REQ_SEND;
1234} 1258}
1259
1260#if 0
1261
1262void
1263aio_pri (int pri = DEFAULT_PRI)
1264 CODE:
1265 if (pri > PRI_MIN) pri = PRI_MIN;
1266 if (pri < PRI_MAX) pri = PRI_MAX;
1267 next_pri = pri + PRI_BIAS;
1268
1269#endif
1235 1270
1236void 1271void
1237flush () 1272flush ()
1238 PROTOTYPE: 1273 PROTOTYPE:
1239 CODE: 1274 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines