diff --git a/include/uv-unix.h b/include/uv-unix.h index 6230b2a7..31335a92 100644 --- a/include/uv-unix.h +++ b/include/uv-unix.h @@ -162,6 +162,7 @@ typedef int uv_file; struct stat statbuf; \ eio_req* eio; -#define UV_WORK_PRIVATE_FIELDS +#define UV_WORK_PRIVATE_FIELDS \ + eio_req* eio; #endif /* UV_UNIX_H */ diff --git a/include/uv.h b/include/uv.h index 2efd4f68..63d93d12 100644 --- a/include/uv.h +++ b/include/uv.h @@ -819,7 +819,8 @@ struct uv_work_s { }; /* Queues a work request to execute asynchronously on the thread pool. */ -int uv_queue_work(uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb); +int uv_queue_work(uv_work_t* req, uv_work_cb work_cb, + uv_after_work_cb after_work_cb); typedef enum { diff --git a/src/unix/fs.c b/src/unix/fs.c index e245cb90..c0b3e222 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -567,8 +567,42 @@ int uv_fs_fchown(uv_fs_t* req, uv_file file, int uid, int gid, uv_fs_cb cb) { } +static void uv__work(eio_req* eio) { + uv_work_t* req = eio->data; + if (req->work_cb) { + req->work_cb(req); + } +} + + +static int uv__after_work(eio_req *eio) { + uv_work_t* req = eio->data; + uv_unref(); + if (req->after_work_cb) { + req->after_work_cb(req); + } + return 0; +} + + int uv_queue_work(uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb) { - assert(0 && "implement me"); - return -1; + void* data = req->data; + + uv_eio_init(); + + uv__req_init((uv_req_t*) req); + uv_ref(); + req->data = data; + req->work_cb = work_cb; + req->after_work_cb = after_work_cb; + + req->eio = eio_custom(uv__work, EIO_PRI_DEFAULT, uv__after_work, req); + + if (!req->eio) { + uv_err_new(NULL, ENOMEM); + return -1; + } + + return 0; }