Commit 0720fa87 by Adeel

Importer: Drops uv_mutex in favor of std::mutex.

It is not safe to use uv_cond_wait
outside of v8 thread (uv loop).
parent 0add9917
......@@ -81,12 +81,14 @@ struct Sass_Import** sass_importer(const char* file, const char* prev, void* coo
* can run uv_async_send without a push.
*/
std::unique_lock<std::mutex> lock(*ctx_w->importer_mutex);
ctx_w->file = file ? strdup(file) : 0;
ctx_w->prev = prev ? strdup(prev) : 0;
ctx_w->async.data = (void*)ctx_w;
uv_async_send(&ctx_w->async);
uv_cond_wait(&ctx_w->importer_condition_variable, &ctx_w->importer_mutex);
ctx_w->importer_condition_variable->wait(lock);
}
else {
NanScope();
......@@ -357,7 +359,7 @@ NAN_METHOD(ImportedCallback) {
sass_context_wrapper* ctx_w = imports_collection[index];
prepare_import_results(returned_value, ctx_w);
uv_cond_signal(&ctx_w->importer_condition_variable);
ctx_w->importer_condition_variable->notify_all();
if (try_catch.HasCaught()) {
node::FatalException(try_catch);
......
......@@ -24,8 +24,9 @@ extern "C" {
sass_context_wrapper* sass_make_context_wrapper() {
sass_context_wrapper* ctx_w = (sass_context_wrapper*)calloc(1, sizeof(sass_context_wrapper));
uv_mutex_init(&ctx_w->importer_mutex);
uv_cond_init(&ctx_w->importer_condition_variable);
ctx_w->importer_mutex = new std::mutex();
ctx_w->importer_condition_variable = new std::condition_variable();
return ctx_w;
}
......@@ -38,14 +39,14 @@ extern "C" {
sass_delete_file_context(ctx_w->fctx);
}
delete ctx_w->success_callback;
delete ctx_w->error_callback;
delete ctx_w->importer_callback;
delete ctx_w->file;
delete ctx_w->prev;
delete ctx_w->error_callback;
delete ctx_w->success_callback;
delete ctx_w->importer_callback;
uv_mutex_destroy(&ctx_w->importer_mutex);
uv_cond_destroy(&ctx_w->importer_condition_variable);
delete ctx_w->importer_mutex;
delete ctx_w->importer_condition_variable;
NanDisposePersistent(ctx_w->result);
......
#include <nan.h>
#include <condition_variable>
#include "libsass/sass_context.h"
#ifdef __cplusplus
......@@ -12,20 +13,27 @@ extern "C" {
void compile_it(uv_work_t* req);
struct sass_context_wrapper {
// binding related
bool is_sync;
void* cookie;
const char* prev;
const char* file;
std::mutex* importer_mutex;
std::condition_variable* importer_condition_variable;
// libsass related
Sass_Import** imports;
Sass_Data_Context* dctx;
Sass_File_Context* fctx;
Persistent<Object> result;
uv_work_t request;
uv_mutex_t importer_mutex;
uv_cond_t importer_condition_variable;
// libuv related
uv_async_t async;
const char* file;
const char* prev;
void* cookie;
bool is_sync;
Sass_Import** imports;
NanCallback* success_callback;
uv_work_t request;
// v8 and nan related
Persistent<Object> result;
NanCallback* error_callback;
NanCallback* success_callback;
NanCallback* importer_callback;
};
......
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