Skip to content

Commit

Permalink
fixes to support node >= v0.7.9
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TooTallNate committed Jun 19, 2012
1 parent d4fe338 commit 211f277
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/async.h
Expand Up @@ -2,6 +2,7 @@
#define NODE_SQLITE3_SRC_ASYNC_H

#include "threading.h"
#include <node_version.h>

#if defined(NODE_SQLITE3_BOOST_THREADING)
#include <boost/thread/mutex.hpp>
Expand Down Expand Up @@ -35,7 +36,11 @@ template <class Item, class Parent> class Async {
rows.swap(async->data);
NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex)
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());
#endif
async->callback(async->parent, rows[i]);
}
}
Expand All @@ -58,7 +63,11 @@ template <class Item, class Parent> class Async {

void add(Item* item) {
// 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());
#endif
NODE_SQLITE3_MUTEX_LOCK(&mutex);
data.push_back(item);
NODE_SQLITE3_MUTEX_UNLOCK(&mutex)
Expand Down
2 changes: 0 additions & 2 deletions src/database.h
Expand Up @@ -38,13 +38,11 @@ class Database : public ObjectWrap {
Baton(Database* db_, Handle<Function> cb_) :
db(db_), status(SQLITE_OK) {
db->Ref();
uv_ref(uv_default_loop());
request.data = this;
callback = Persistent<Function>::New(cb_);
}
virtual ~Baton() {
db->Unref();
uv_unref(uv_default_loop());
callback.Dispose();
}
};
Expand Down
2 changes: 0 additions & 2 deletions src/statement.h
Expand Up @@ -86,7 +86,6 @@ class Statement : public ObjectWrap {

Baton(Statement* stmt_, Handle<Function> cb_) : stmt(stmt_) {
stmt->Ref();
uv_ref(uv_default_loop());
request.data = this;
callback = Persistent<Function>::New(cb_);
}
Expand All @@ -96,7 +95,6 @@ class Statement : public ObjectWrap {
DELETE_FIELD(field);
}
stmt->Unref();
uv_unref(uv_default_loop());
callback.Dispose();
}
};
Expand Down

0 comments on commit 211f277

Please sign in to comment.