Commit 70766c74 by Mohamed Akram

Improve usage of libuv

parent bbec1fa1
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "threading.h" #include "threading.h"
#include <node_version.h> #include <node_version.h>
#include <napi.h>
#include <uv.h> #include <uv.h>
#if defined(NODE_SQLITE3_BOOST_THREADING) #if defined(NODE_SQLITE3_BOOST_THREADING)
...@@ -27,10 +28,12 @@ public: ...@@ -27,10 +28,12 @@ public:
: callback(cb_), parent(parent_) { : callback(cb_), parent(parent_) {
watcher.data = this; watcher.data = this;
NODE_SQLITE3_MUTEX_INIT NODE_SQLITE3_MUTEX_INIT
uv_async_init(uv_default_loop(), &watcher, reinterpret_cast<uv_async_cb>(listener)); uv_loop_t *loop;
napi_get_uv_event_loop(parent_->Env(), &loop);
uv_async_init(loop, &watcher, reinterpret_cast<uv_async_cb>(listener));
} }
static void listener(uv_async_t* handle, int status) { static void listener(uv_async_t* handle) {
Async* async = static_cast<Async*>(handle->data); Async* async = static_cast<Async*>(handle->data);
std::vector<Item*> rows; std::vector<Item*> rows;
NODE_SQLITE3_MUTEX_LOCK(&async->mutex) NODE_SQLITE3_MUTEX_LOCK(&async->mutex)
...@@ -52,7 +55,7 @@ public: ...@@ -52,7 +55,7 @@ public:
// Need to call the listener again to ensure all items have been // Need to call the listener again to ensure all items have been
// processed. Is this a bug in uv_async? Feels like uv_close // processed. Is this a bug in uv_async? Feels like uv_close
// should handle that. // should handle that.
listener(&watcher, 0); listener(&watcher);
uv_close((uv_handle_t*)&watcher, close); uv_close((uv_handle_t*)&watcher, close);
} }
......
...@@ -705,7 +705,7 @@ void Statement::CloseCallback(uv_handle_t* handle) { ...@@ -705,7 +705,7 @@ void Statement::CloseCallback(uv_handle_t* handle) {
delete async; delete async;
} }
void Statement::AsyncEach(uv_async_t* handle, int status) { void Statement::AsyncEach(uv_async_t* handle) {
Async* async = static_cast<Async*>(handle->data); Async* async = static_cast<Async*>(handle->data);
Napi::Env env = async->stmt->Env(); Napi::Env env = async->stmt->Env();
......
...@@ -173,7 +173,9 @@ public: ...@@ -173,7 +173,9 @@ public:
watcher.data = this; watcher.data = this;
NODE_SQLITE3_MUTEX_INIT NODE_SQLITE3_MUTEX_INIT
stmt->Ref(); stmt->Ref();
uv_async_init(uv_default_loop(), &watcher, async_cb); uv_loop_t *loop;
napi_get_uv_event_loop(stmt->Env(), &loop);
uv_async_init(loop, &watcher, async_cb);
} }
~Async() { ~Async() {
...@@ -214,7 +216,7 @@ protected: ...@@ -214,7 +216,7 @@ protected:
static void Work_Prepare(napi_env env, void* data); static void Work_Prepare(napi_env env, void* data);
static void Work_AfterPrepare(napi_env env, napi_status status, void* data); static void Work_AfterPrepare(napi_env env, napi_status status, void* data);
static void AsyncEach(uv_async_t* handle, int status); static void AsyncEach(uv_async_t* handle);
static void CloseCallback(uv_handle_t* handle); static void CloseCallback(uv_handle_t* handle);
static void Finalize_(Baton* baton); static void Finalize_(Baton* baton);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment