From 4a20a11d232faa75263b52efcc740cb2e1e54d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Wed, 22 Aug 2012 18:34:03 +0800 Subject: [PATCH 1/2] now builds with Node 0.8 --- src/async_uv.h | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/async_uv.h b/src/async_uv.h index b910ae6..a301412 100644 --- a/src/async_uv.h +++ b/src/async_uv.h @@ -1,11 +1,12 @@ #ifndef NODE_SQLITE3_SRC_ASYNC_H #define NODE_SQLITE3_SRC_ASYNC_H +#include // Generic uv_async handler. template class Async { typedef void (*Callback)(Parent* parent, Item* item); - + protected: uv_async_t watcher; pthread_mutex_t mutex; @@ -13,15 +14,15 @@ template class Async { Callback callback; public: Parent* parent; - + public: Async(Parent* parent_, Callback cb_) - : callback(cb_), parent(parent_) { + : callback(cb_), parent(parent_) { watcher.data = this; pthread_mutex_init(&mutex, NULL); uv_async_init(uv_default_loop(), &watcher, listener); } - + static void listener(uv_async_t* handle, int status) { Async* async = static_cast(handle->data); std::vector rows; @@ -29,11 +30,15 @@ template class Async { rows.swap(async->data); pthread_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]); } } - + static void close(uv_handle_t* handle) { assert(handle != NULL); assert(handle->data != NULL); @@ -41,7 +46,7 @@ template class Async { delete async; handle->data = NULL; } - + void finish() { // Need to call the listener again to ensure all items have been // processed. Is this a bug in uv_async? Feels like uv_close @@ -49,27 +54,31 @@ template class Async { listener(&watcher, 0); uv_close((uv_handle_t*)&watcher, close); } - + 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 pthread_mutex_lock(&mutex); data.push_back(item); pthread_mutex_unlock(&mutex); } - + void send() { uv_async_send(&watcher); } - + void send(Item* item) { add(item); send(); } - + ~Async() { pthread_mutex_destroy(&mutex); } }; -#endif +#endif \ No newline at end of file From dffe6dcf645d61399baa24ea6f6b86dff48287c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Wed, 22 Aug 2012 18:42:14 +0800 Subject: [PATCH 2/2] liberal engine dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cdfccfd..ad12f4c 100644 --- a/package.json +++ b/package.json @@ -5,5 +5,5 @@ "keywords": [], "author": "Jeroen Janssen ", "main": "./sdlmixer", - "engines": { "node": "0.4.x" } + "engine": "node >= 0.4.x" }