fs-native-extensions
Advanced tools
+2
-1
@@ -39,3 +39,4 @@ #ifndef FS_EXT_H | ||
| struct fs_ext_lock_s { | ||
| uv_work_t req; | ||
| uv_thread_t thread; | ||
| uv_async_t signal; | ||
@@ -42,0 +43,0 @@ uv_os_fd_t fd; |
+1
-1
| { | ||
| "name": "fs-native-extensions", | ||
| "version": "1.4.4", | ||
| "version": "1.4.5", | ||
| "description": "Native file system extensions for advanced file operations", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+68
-16
@@ -0,1 +1,2 @@ | ||
| #include <assert.h> | ||
| #include <stdint.h> | ||
@@ -22,17 +23,36 @@ #include <stdlib.h> | ||
| static void | ||
| fs_ext__lock_work(uv_work_t *req) { | ||
| fs_ext_lock_t *r = (fs_ext_lock_t *) req->data; | ||
| fs_ext__lock_close(uv_handle_t *handle) { | ||
| fs_ext_lock_t *r = (fs_ext_lock_t *) handle->data; | ||
| r->result = fs_ext__wait_for_lock(r->fd, r->offset, r->length, r->type); | ||
| if (r->cb) r->cb(r, r->result); | ||
| } | ||
| static void | ||
| fs_ext__lock_after_work(uv_work_t *req, int status) { | ||
| fs_ext_lock_t *r = (fs_ext_lock_t *) req->data; | ||
| fs_ext__lock_after_work(uv_async_t *signal) { | ||
| int err; | ||
| if (r->cb) r->cb(r, r->result); | ||
| fs_ext_lock_t *r = (fs_ext_lock_t *) signal->data; | ||
| err = uv_thread_join(&r->thread); | ||
| assert(err == 0); | ||
| uv_close((uv_handle_t *) signal, fs_ext__lock_close); | ||
| } | ||
| static void | ||
| fs_ext__lock_work(void *data) { | ||
| int err; | ||
| fs_ext_lock_t *r = (fs_ext_lock_t *) data; | ||
| r->result = fs_ext__wait_for_lock(r->fd, r->offset, r->length, r->type); | ||
| err = uv_async_send(&r->signal); | ||
| assert(err == 0); | ||
| } | ||
| int | ||
| fs_ext_wait_for_lock(uv_loop_t *loop, fs_ext_lock_t *req, uv_os_fd_t fd, uint64_t offset, size_t length, fs_ext_lock_type_t type, fs_ext_lock_cb cb) { | ||
| int err; | ||
| req->fd = fd; | ||
@@ -43,5 +63,11 @@ req->offset = offset; | ||
| req->cb = cb; | ||
| req->req.data = (void *) req; | ||
| req->signal.data = (void *) req; | ||
| return uv_queue_work(loop, &req->req, fs_ext__lock_work, fs_ext__lock_after_work); | ||
| err = uv_async_init(loop, &req->signal, fs_ext__lock_after_work); | ||
| assert(err == 0); | ||
| err = uv_thread_create(&req->thread, fs_ext__lock_work, (void *) req); | ||
| assert(err == 0); | ||
| return 0; | ||
| } | ||
@@ -61,6 +87,11 @@ | ||
| static void | ||
| fs_ext__downgrade_lock_work(uv_work_t *req) { | ||
| fs_ext_lock_t *r = (fs_ext_lock_t *) req->data; | ||
| fs_ext__downgrade_lock_work(void *data) { | ||
| int err; | ||
| fs_ext_lock_t *r = (fs_ext_lock_t *) data; | ||
| r->result = fs_ext__wait_for_downgrade_lock(r->fd, r->offset, r->length); | ||
| err = uv_async_send(&r->signal); | ||
| assert(err == 0); | ||
| } | ||
@@ -70,2 +101,4 @@ | ||
| fs_ext_wait_for_downgrade_lock(uv_loop_t *loop, fs_ext_lock_t *req, uv_os_fd_t fd, uint64_t offset, size_t length, fs_ext_lock_cb cb) { | ||
| int err; | ||
| req->fd = fd; | ||
@@ -76,12 +109,23 @@ req->offset = offset; | ||
| req->cb = cb; | ||
| req->req.data = (void *) req; | ||
| req->signal.data = (void *) req; | ||
| return uv_queue_work(loop, &req->req, fs_ext__downgrade_lock_work, fs_ext__lock_after_work); | ||
| err = uv_async_init(loop, &req->signal, fs_ext__lock_after_work); | ||
| assert(err == 0); | ||
| err = uv_thread_create(&req->thread, fs_ext__downgrade_lock_work, (void *) req); | ||
| assert(err == 0); | ||
| return 0; | ||
| } | ||
| static void | ||
| fs_ext__upgrade_lock_work(uv_work_t *req) { | ||
| fs_ext_lock_t *r = (fs_ext_lock_t *) req->data; | ||
| fs_ext__upgrade_lock_work(void *data) { | ||
| int err; | ||
| fs_ext_lock_t *r = (fs_ext_lock_t *) data; | ||
| r->result = fs_ext__wait_for_upgrade_lock(r->fd, r->offset, r->length); | ||
| err = uv_async_send(&r->signal); | ||
| assert(err == 0); | ||
| } | ||
@@ -102,2 +146,4 @@ | ||
| fs_ext_wait_for_upgrade_lock(uv_loop_t *loop, fs_ext_lock_t *req, uv_os_fd_t fd, uint64_t offset, size_t length, fs_ext_lock_cb cb) { | ||
| int err; | ||
| req->fd = fd; | ||
@@ -108,5 +154,11 @@ req->offset = offset; | ||
| req->cb = cb; | ||
| req->req.data = (void *) req; | ||
| req->signal.data = (void *) req; | ||
| return uv_queue_work(loop, &req->req, fs_ext__upgrade_lock_work, fs_ext__lock_after_work); | ||
| err = uv_async_init(loop, &req->signal, fs_ext__lock_after_work); | ||
| assert(err == 0); | ||
| err = uv_thread_create(&req->thread, fs_ext__upgrade_lock_work, (void *) req); | ||
| assert(err == 0); | ||
| return 0; | ||
| } | ||
@@ -113,0 +165,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1410441
1.2%