windows: add POST macro to fs functions

This commit adds a POST macro to the Windows fs functions,
similar to the one used on Unix platforms.

PR-URL: https://github.com/libuv/libuv/pull/1509
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
cjihrig 2017-09-02 15:12:46 -04:00
parent e539fc412f
commit 9a4468f47a
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5

View File

@ -51,11 +51,18 @@
} \
while (0)
#define QUEUE_FS_TP_JOB(loop, req) \
do { \
uv__req_register(loop, req); \
uv__work_submit((loop), &(req)->work_req, uv__fs_work, uv__fs_done); \
} while (0)
#define POST \
do { \
if (cb != NULL) { \
uv__req_register(loop, req); \
uv__work_submit(loop, &req->work_req, uv__fs_work, uv__fs_done); \
return 0; \
} else { \
uv__fs_work(&req->work_req); \
return req->result; \
} \
} \
while (0)
#define SET_REQ_RESULT(req, result_value) \
do { \
@ -1988,28 +1995,14 @@ int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
req->fs.info.file_flags = flags;
req->fs.info.mode = mode;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__open(req);
return req->result;
}
POST;
}
int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
INIT(UV_FS_CLOSE);
req->file.fd = fd;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__close(req);
return req->result;
}
POST;
}
@ -2038,14 +2031,7 @@ int uv_fs_read(uv_loop_t* loop,
memcpy(req->fs.info.bufs, bufs, nbufs * sizeof(*bufs));
req->fs.info.offset = offset;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__read(req);
return req->result;
}
POST;
}
@ -2074,14 +2060,7 @@ int uv_fs_write(uv_loop_t* loop,
memcpy(req->fs.info.bufs, bufs, nbufs * sizeof(*bufs));
req->fs.info.offset = offset;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__write(req);
return req->result;
}
POST;
}
@ -2095,13 +2074,7 @@ int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
return uv_translate_sys_error(err);
}
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__unlink(req);
return req->result;
}
POST;
}
@ -2116,14 +2089,7 @@ int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
}
req->fs.info.mode = mode;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__mkdir(req);
return req->result;
}
POST;
}
@ -2136,13 +2102,7 @@ int uv_fs_mkdtemp(uv_loop_t* loop, uv_fs_t* req, const char* tpl,
if (err)
return uv_translate_sys_error(err);
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__mkdtemp(req);
return req->result;
}
POST;
}
@ -2155,13 +2115,7 @@ int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
return uv_translate_sys_error(err);
}
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__rmdir(req);
return req->result;
}
POST;
}
@ -2176,14 +2130,7 @@ int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
}
req->fs.info.file_flags = flags;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__scandir(req);
return req->result;
}
POST;
}
@ -2197,13 +2144,7 @@ int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path,
return uv_translate_sys_error(err);
}
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__link(req);
return req->result;
}
POST;
}
@ -2218,14 +2159,7 @@ int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
}
req->fs.info.file_flags = flags;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__symlink(req);
return req->result;
}
POST;
}
@ -2239,13 +2173,7 @@ int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
return uv_translate_sys_error(err);
}
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__readlink(req);
return req->result;
}
POST;
}
@ -2264,13 +2192,7 @@ int uv_fs_realpath(uv_loop_t* loop, uv_fs_t* req, const char* path,
return uv_translate_sys_error(err);
}
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__realpath(req);
return req->result;
}
POST;
}
@ -2284,27 +2206,14 @@ int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_uid_t uid,
return uv_translate_sys_error(err);
}
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__chown(req);
return req->result;
}
POST;
}
int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_uid_t uid,
uv_gid_t gid, uv_fs_cb cb) {
INIT(UV_FS_FCHOWN);
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__fchown(req);
return req->result;
}
POST;
}
@ -2317,13 +2226,7 @@ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
return uv_translate_sys_error(err);
}
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__stat(req);
return req->result;
}
POST;
}
@ -2336,27 +2239,14 @@ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
return uv_translate_sys_error(err);
}
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__lstat(req);
return req->result;
}
POST;
}
int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
INIT(UV_FS_FSTAT);
req->file.fd = fd;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__fstat(req);
return req->result;
}
POST;
}
@ -2370,41 +2260,21 @@ int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path,
return uv_translate_sys_error(err);
}
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__rename(req);
return req->result;
}
POST;
}
int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
INIT(UV_FS_FSYNC);
req->file.fd = fd;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__fsync(req);
return req->result;
}
POST;
}
int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
INIT(UV_FS_FDATASYNC);
req->file.fd = fd;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__fdatasync(req);
return req->result;
}
POST;
}
@ -2413,14 +2283,7 @@ int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file fd,
INIT(UV_FS_FTRUNCATE);
req->file.fd = fd;
req->fs.info.offset = offset;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__ftruncate(req);
return req->result;
}
POST;
}
@ -2443,14 +2306,7 @@ int uv_fs_copyfile(uv_loop_t* loop,
return uv_translate_sys_error(err);
req->fs.info.file_flags = flags;
if (cb != NULL) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
}
fs__copyfile(req);
return req->result;
POST;
}
@ -2461,14 +2317,7 @@ int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file fd_out,
req->fs.info.fd_out = fd_out;
req->fs.info.offset = in_offset;
req->fs.info.bufsml[0].len = length;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__sendfile(req);
return req->result;
}
POST;
}
@ -2485,14 +2334,7 @@ int uv_fs_access(uv_loop_t* loop,
return uv_translate_sys_error(err);
req->fs.info.mode = flags;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
}
fs__access(req);
return req->result;
POST;
}
@ -2507,14 +2349,7 @@ int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
}
req->fs.info.mode = mode;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__chmod(req);
return req->result;
}
POST;
}
@ -2523,14 +2358,7 @@ int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file fd, int mode,
INIT(UV_FS_FCHMOD);
req->file.fd = fd;
req->fs.info.mode = mode;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__fchmod(req);
return req->result;
}
POST;
}
@ -2546,14 +2374,7 @@ int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime,
req->fs.time.atime = atime;
req->fs.time.mtime = mtime;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__utime(req);
return req->result;
}
POST;
}
@ -2563,12 +2384,5 @@ int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file fd, double atime,
req->file.fd = fd;
req->fs.time.atime = atime;
req->fs.time.mtime = mtime;
if (cb) {
QUEUE_FS_TP_JOB(loop, req);
return 0;
} else {
fs__futime(req);
return req->result;
}
POST;
}