Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
unix: implement uv_queue_work
  • Loading branch information
ry committed Aug 30, 2011
1 parent 0e81406 commit 1a4ead5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/uv-unix.h
Expand Up @@ -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 */
3 changes: 2 additions & 1 deletion include/uv.h
Expand Up @@ -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 {
Expand Down
38 changes: 36 additions & 2 deletions src/unix/fs.c
Expand Up @@ -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;
}

0 comments on commit 1a4ead5

Please sign in to comment.