Skip to content

Commit

Permalink
node v0.7.9 compat
Browse files Browse the repository at this point in the history
There were some libuv API changes...
  • Loading branch information
TooTallNate committed May 29, 2012
1 parent 324465a commit 02588f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/callback_info.cc
Expand Up @@ -3,6 +3,7 @@
// http://www.bufferoverflow.ch/cgi-bin/dwww/usr/share/doc/libffi5/html/The-Closure-API.html

#include <node_buffer.h>
#include <node_version.h>
#include "ffi.h"

pthread_t CallbackInfo::g_mainthread;
Expand Down Expand Up @@ -130,6 +131,13 @@ void CallbackInfo::Invoke(ffi_cif *cif, void *retval, void **parameters, void *u
if (pthread_equal(pthread_self(), g_mainthread)) {
DispatchToV8(info, retval, parameters);
} else {
// hold the event loop open while this is executing
#if NODE_VERSION_AT_LEAST(0, 7, 9)
uv_ref((uv_handle_t *)&g_async);
#else
uv_ref(uv_default_loop());
#endif

// create a temporary storage area for our invokation parameters
ThreadedCallbackInvokation *inv = new ThreadedCallbackInvokation(info, retval, parameters);

Expand All @@ -144,6 +152,11 @@ void CallbackInfo::Invoke(ffi_cif *cif, void *retval, void **parameters, void *u
// wait for signal from calling thread
inv->WaitForExecution();

#if NODE_VERSION_AT_LEAST(0, 7, 9)
uv_unref((uv_handle_t *)&g_async);
#else
uv_unref(uv_default_loop());
#endif
delete inv;
}
}
Expand All @@ -163,5 +176,9 @@ void CallbackInfo::Initialize(Handle<Object> target) {
pthread_mutex_init(&g_queue_mutex, NULL);

// allow the event loop to exit while this is running
#if NODE_VERSION_AT_LEAST(0, 7, 9)
uv_unref((uv_handle_t *)&g_async);
#else
uv_unref(uv_default_loop());
#endif
}
2 changes: 0 additions & 2 deletions src/threaded_callback_invokation.cc
Expand Up @@ -7,11 +7,9 @@ ThreadedCallbackInvokation::ThreadedCallbackInvokation(callback_info *cbinfo, vo

pthread_mutex_init(&m_mutex, NULL);
pthread_cond_init(&m_cond, NULL);
uv_ref(uv_default_loop()); // hold the event loop open while this is executing
}

ThreadedCallbackInvokation::~ThreadedCallbackInvokation() {
uv_unref(uv_default_loop());
pthread_cond_destroy(&m_cond);
pthread_mutex_destroy(&m_mutex);
}
Expand Down

0 comments on commit 02588f7

Please sign in to comment.