Commit 211f277a by Nathan Rajlich

fixes to support node >= v0.7.9

Use the new uv_ref()/uv_unref() API for node >= v0.7.9, and remove a couple
unnecessary instances of uv_ref()/uv_unref() where only uv_queue_work() was
being used.
parent d4fe3387
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define NODE_SQLITE3_SRC_ASYNC_H #define NODE_SQLITE3_SRC_ASYNC_H
#include "threading.h" #include "threading.h"
#include <node_version.h>
#if defined(NODE_SQLITE3_BOOST_THREADING) #if defined(NODE_SQLITE3_BOOST_THREADING)
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
...@@ -35,7 +36,11 @@ public: ...@@ -35,7 +36,11 @@ public:
rows.swap(async->data); rows.swap(async->data);
NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex) NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex)
for (unsigned int i = 0, size = rows.size(); i < size; i++) { for (unsigned int i = 0, size = rows.size(); i < size; i++) {
#if NODE_VERSION_AT_LEAST(0, 7, 9)
uv_unref((uv_handle_t *)&async->watcher);
#else
uv_unref(uv_default_loop()); uv_unref(uv_default_loop());
#endif
async->callback(async->parent, rows[i]); async->callback(async->parent, rows[i]);
} }
} }
...@@ -58,7 +63,11 @@ public: ...@@ -58,7 +63,11 @@ public:
void add(Item* item) { void add(Item* item) {
// Make sure node runs long enough to deliver the messages. // Make sure node runs long enough to deliver the messages.
#if NODE_VERSION_AT_LEAST(0, 7, 9)
uv_ref((uv_handle_t *)&watcher);
#else
uv_ref(uv_default_loop()); uv_ref(uv_default_loop());
#endif
NODE_SQLITE3_MUTEX_LOCK(&mutex); NODE_SQLITE3_MUTEX_LOCK(&mutex);
data.push_back(item); data.push_back(item);
NODE_SQLITE3_MUTEX_UNLOCK(&mutex) NODE_SQLITE3_MUTEX_UNLOCK(&mutex)
......
...@@ -38,13 +38,11 @@ public: ...@@ -38,13 +38,11 @@ public:
Baton(Database* db_, Handle<Function> cb_) : Baton(Database* db_, Handle<Function> cb_) :
db(db_), status(SQLITE_OK) { db(db_), status(SQLITE_OK) {
db->Ref(); db->Ref();
uv_ref(uv_default_loop());
request.data = this; request.data = this;
callback = Persistent<Function>::New(cb_); callback = Persistent<Function>::New(cb_);
} }
virtual ~Baton() { virtual ~Baton() {
db->Unref(); db->Unref();
uv_unref(uv_default_loop());
callback.Dispose(); callback.Dispose();
} }
}; };
......
...@@ -86,7 +86,6 @@ public: ...@@ -86,7 +86,6 @@ public:
Baton(Statement* stmt_, Handle<Function> cb_) : stmt(stmt_) { Baton(Statement* stmt_, Handle<Function> cb_) : stmt(stmt_) {
stmt->Ref(); stmt->Ref();
uv_ref(uv_default_loop());
request.data = this; request.data = this;
callback = Persistent<Function>::New(cb_); callback = Persistent<Function>::New(cb_);
} }
...@@ -96,7 +95,6 @@ public: ...@@ -96,7 +95,6 @@ public:
DELETE_FIELD(field); DELETE_FIELD(field);
} }
stmt->Unref(); stmt->Unref();
uv_unref(uv_default_loop());
callback.Dispose(); callback.Dispose();
} }
}; };
......
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