Skip to content

Commit

Permalink
Merge pull request sass#854 from saper/fix/713
Browse files Browse the repository at this point in the history
Close sass#713 (handle->flags & UV_CLOSING) assertion failure
  • Loading branch information
xzyfer committed Apr 14, 2015
2 parents 028624c + ec4eb0c commit fce0993
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/callback_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CallbackBridge {
// We will expose a bridge object to the JS callback that wraps this instance so we don't loose context.
// This is the V8 constructor for such objects.
static Handle<Function> get_wrapper_constructor();
static void async_gone(uv_handle_t *handle);
static NAN_METHOD(New);
static NAN_METHOD(ReturnCallback);
static Persistent<Function> wrapper_constructor;
Expand All @@ -45,7 +46,7 @@ class CallbackBridge {

std::mutex cv_mutex;
std::condition_variable condition_variable;
uv_async_t async;
uv_async_t *async;
std::vector<L> argv;
bool has_returned;
T return_value;
Expand All @@ -58,8 +59,9 @@ template <typename T, typename L>
CallbackBridge<T, L>::CallbackBridge(NanCallback* callback, bool is_sync) : callback(callback), is_sync(is_sync) {
// This assumes the main thread will be the one instantiating the bridge
if (!is_sync) {
uv_async_init(uv_default_loop(), &this->async, (uv_async_cb) dispatched_async_uv_callback);
this->async.data = (void*) this;
this->async = new uv_async_t;
this->async->data = (void*) this;
uv_async_init(uv_default_loop(), this->async, (uv_async_cb) dispatched_async_uv_callback);
}

NanAssignPersistent(wrapper, NanNew(CallbackBridge<T, L>::get_wrapper_constructor())->NewInstance());
Expand All @@ -72,7 +74,7 @@ CallbackBridge<T, L>::~CallbackBridge() {
NanDisposePersistent(this->wrapper);

if (!is_sync) {
uv_close((uv_handle_t*)&this->async, NULL);
uv_close((uv_handle_t*)this->async, &async_gone);
}
}

Expand All @@ -93,7 +95,7 @@ T CallbackBridge<T, L>::operator()(std::vector<void*> argv) {

std::unique_lock<std::mutex> lock(this->cv_mutex);
this->has_returned = false;
uv_async_send(&this->async);
uv_async_send(this->async);
this->condition_variable.wait(lock, [this] { return this->has_returned; });

return this->return_value;
Expand Down Expand Up @@ -162,4 +164,9 @@ NAN_METHOD(CallbackBridge<T COMMA L>::New) {
NanReturnValue(args.This());
}

template <typename T, typename L>
void CallbackBridge<T, L>::async_gone(uv_handle_t *handle) {
delete (uv_async_t *)handle;
}

#endif

0 comments on commit fce0993

Please sign in to comment.