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.54 by root, Mon Oct 23 00:34:36 2006 UTC vs.
Revision 1.58 by root, Mon Oct 23 18:48:08 2006 UTC

83 int type; 83 int type;
84 int fd, fd2; 84 int fd, fd2;
85 int errorno; 85 int errorno;
86 STRLEN dataoffset; 86 STRLEN dataoffset;
87 mode_t mode; /* open */ 87 mode_t mode; /* open */
88 unsigned char pri;
88 unsigned char cancelled; 89 unsigned char flags;
89} aio_cb; 90} aio_cb;
91
92enum {
93 FLAG_CANCELLED = 0x01,
94};
90 95
91typedef aio_cb *aio_req; 96typedef aio_cb *aio_req;
92typedef aio_cb *aio_req_ornot; 97typedef aio_cb *aio_req_ornot;
93 98
94static int started, wanted; 99static int started, wanted;
130 return mg ? (aio_req)mg->mg_ptr : 0; 135 return mg ? (aio_req)mg->mg_ptr : 0;
131} 136}
132 137
133static void aio_grp_feed (aio_req grp) 138static void aio_grp_feed (aio_req grp)
134{ 139{
135 while (grp->length < grp->fd2) 140 while (grp->length < grp->fd2 && !(grp->flags & FLAG_CANCELLED))
136 { 141 {
137 int old_len = grp->length; 142 int old_len = grp->length;
138 143
139 if (grp->fh2 && SvOK (grp->fh2)) 144 if (grp->fh2 && SvOK (grp->fh2))
140 { 145 {
191static void req_invoke (aio_req req) 196static void req_invoke (aio_req req)
192{ 197{
193 dSP; 198 dSP;
194 int errorno = errno; 199 int errorno = errno;
195 200
196 if (req->cancelled || !SvOK (req->callback)) 201 if (req->flags & FLAG_CANCELLED || !SvOK (req->callback))
197 return; 202 return;
198 203
199 errno = req->errorno; 204 errno = req->errorno;
200 205
201 ENTER; 206 ENTER;
321 Safefree (req); 326 Safefree (req);
322} 327}
323 328
324static void req_cancel (aio_req req) 329static void req_cancel (aio_req req)
325{ 330{
326 req->cancelled = 1; 331 req->flags |= FLAG_CANCELLED;
327 332
328 if (req->type == REQ_GROUP) 333 if (req->type == REQ_GROUP)
329 { 334 {
330 aio_req sub; 335 aio_req sub;
331 336
786 791
787 pthread_mutex_unlock (&reqlock); 792 pthread_mutex_unlock (&reqlock);
788 793
789 errno = 0; /* strictly unnecessary */ 794 errno = 0; /* strictly unnecessary */
790 795
791 if (!req->cancelled) 796 if (!(req->flags & FLAG_CANCELLED))
792 switch (type = req->type) /* remember type for QUIT check */ 797 switch (type = req->type) /* remember type for QUIT check */
793 { 798 {
794 case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; 799 case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break;
795 case REQ_WRITE: req->result = pwrite (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;
796 801
821 tv.tv_usec = req->fd2; 826 tv.tv_usec = req->fd2;
822 827
823 req->result = select (0, 0, 0, 0, &tv); 828 req->result = select (0, 0, 0, 0, &tv);
824 } 829 }
825 830
826 case REQ_GROUP: /*TODO: should not be handled here */ 831 case REQ_GROUP:
827 case REQ_NOP: /*TODO: should not be handled here */ 832 case REQ_NOP:
828 case REQ_QUIT: 833 case REQ_QUIT:
829 break; 834 break;
830 835
831 default: 836 default:
832 req->result = ENOSYS; 837 req->result = ENOSYS;
1287cancel (aio_req_ornot req) 1292cancel (aio_req_ornot req)
1288 PROTOTYPE: 1293 PROTOTYPE:
1289 CODE: 1294 CODE:
1290 req_cancel (req); 1295 req_cancel (req);
1291 1296
1297void
1298cb (aio_req req, SV *callback=&PL_sv_undef)
1299 CODE:
1300 SvREFCNT_dec (req->callback);
1301 req->callback = newSVsv (callback);
1302
1292MODULE = IO::AIO PACKAGE = IO::AIO::GRP 1303MODULE = IO::AIO PACKAGE = IO::AIO::GRP
1293 1304
1294void 1305void
1295add (aio_req grp, ...) 1306add (aio_req grp, ...)
1296 PPCODE: 1307 PPCODE:
1337 SvREFCNT_dec (grp->data); 1348 SvREFCNT_dec (grp->data);
1338 grp->data = (SV *)av; 1349 grp->data = (SV *)av;
1339} 1350}
1340 1351
1341void 1352void
1342lock (aio_req grp)
1343 CODE:
1344 ++grp->length;
1345
1346void
1347unlock (aio_req grp)
1348 CODE:
1349 aio_grp_dec (grp);
1350
1351void
1352feeder_limit (aio_req grp, int limit) 1353feed_limit (aio_req grp, int limit)
1353 CODE: 1354 CODE:
1354 grp->fd2 = limit; 1355 grp->fd2 = limit;
1355 aio_grp_feed (grp); 1356 aio_grp_feed (grp);
1356 1357
1357void 1358void
1358set_feeder (aio_req grp, SV *callback=&PL_sv_undef) 1359feed (aio_req grp, SV *callback=&PL_sv_undef)
1359 CODE: 1360 CODE:
1360{ 1361{
1361 SvREFCNT_dec (grp->fh2); 1362 SvREFCNT_dec (grp->fh2);
1362 grp->fh2 = newSVsv (callback); 1363 grp->fh2 = newSVsv (callback);
1363 1364

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines