--- IO-AIO/AIO.xs 2011/09/29 10:01:35 1.202 +++ IO-AIO/AIO.xs 2011/09/29 23:06:24 1.203 @@ -373,7 +373,7 @@ static SV * newSVaio_wd (aio_wd wd) { - return sv_bless (newRV_noinc (newSViv ((long)wd)), aio_wd_stash); + return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash); } static aio_req @@ -473,7 +473,7 @@ switch (req->type) { case EIO_WD_OPEN: - PUSHs (sv_2mortal (newSVaio_wd (req->wd))); + PUSHs (req->result ? &PL_sv_undef : sv_2mortal (newSVaio_wd (req->wd))); break; case EIO_READDIR: @@ -811,20 +811,28 @@ return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; } +static aio_req ecb_noinline +dreq (SV *callback) +{ + SV *cb_cv; + aio_req req; + int req_pri = next_pri; + next_pri = EIO_PRI_DEFAULT; + + cb_cv = get_cb (callback); + + Newz (0, req, 1, eio_req); + if (!req) + croak ("out of memory during eio_req allocation"); + + req->callback = SvREFCNT_inc (cb_cv); + req->pri = req_pri; + + return req; +} + #define dREQ \ - SV *cb_cv; \ - aio_req req; \ - int req_pri = next_pri; \ - next_pri = EIO_PRI_DEFAULT; \ - \ - cb_cv = get_cb (callback); \ - \ - Newz (0, req, 1, eio_req); \ - if (!req) \ - croak ("out of memory during eio_req allocation"); \ - \ - req->callback = SvREFCNT_inc (cb_cv); \ - req->pri = req_pri + aio_req req = dreq (callback); \ #define REQ_SEND \ PUTBACK; \ @@ -1298,8 +1306,8 @@ { dREQ; - req->sv1 = newSVsv (fh_or_path); req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); + REQ_SEND; } @@ -1789,11 +1797,15 @@ { aio_wd wd = SvAIO_WD (self); #if HAVE_AT - SV *callback = &PL_sv_undef; - dREQ; /* clobbers next_pri :/ */ - req->type = EIO_WD_CLOSE; - req->wd = wd; - REQ_SEND; + { + SV *callback = &PL_sv_undef; + dREQ; /* clobbers next_pri :/ */ + next_pri = req->pri; /* restore next_pri */ + req->pri = EIO_PRI_MAX; /* better use max. priority to conserve fds */ + req->type = EIO_WD_CLOSE; + req->wd = wd; + REQ_SEND; + } #else eio_wd_close_sync (wd); #endif