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 ...@@ -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. * 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->file = file ? strdup(file) : 0;
ctx_w->prev = prev ? strdup(prev) : 0; ctx_w->prev = prev ? strdup(prev) : 0;
ctx_w->async.data = (void*)ctx_w; ctx_w->async.data = (void*)ctx_w;
uv_async_send(&ctx_w->async); 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 { else {
NanScope(); NanScope();
...@@ -357,7 +359,7 @@ NAN_METHOD(ImportedCallback) { ...@@ -357,7 +359,7 @@ NAN_METHOD(ImportedCallback) {
sass_context_wrapper* ctx_w = imports_collection[index]; sass_context_wrapper* ctx_w = imports_collection[index];
prepare_import_results(returned_value, ctx_w); 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()) { if (try_catch.HasCaught()) {
node::FatalException(try_catch); node::FatalException(try_catch);
......
...@@ -24,8 +24,9 @@ extern "C" { ...@@ -24,8 +24,9 @@ extern "C" {
sass_context_wrapper* sass_make_context_wrapper() { sass_context_wrapper* sass_make_context_wrapper() {
sass_context_wrapper* ctx_w = (sass_context_wrapper*)calloc(1, sizeof(sass_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; return ctx_w;
} }
...@@ -38,14 +39,14 @@ extern "C" { ...@@ -38,14 +39,14 @@ extern "C" {
sass_delete_file_context(ctx_w->fctx); 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->file;
delete ctx_w->prev; 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); delete ctx_w->importer_mutex;
uv_cond_destroy(&ctx_w->importer_condition_variable); delete ctx_w->importer_condition_variable;
NanDisposePersistent(ctx_w->result); NanDisposePersistent(ctx_w->result);
......
#include <nan.h> #include <nan.h>
#include <condition_variable>
#include "libsass/sass_context.h" #include "libsass/sass_context.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -12,20 +13,27 @@ extern "C" { ...@@ -12,20 +13,27 @@ extern "C" {
void compile_it(uv_work_t* req); void compile_it(uv_work_t* req);
struct sass_context_wrapper { 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_Data_Context* dctx;
Sass_File_Context* fctx; Sass_File_Context* fctx;
Persistent<Object> result;
uv_work_t request; // libuv related
uv_mutex_t importer_mutex;
uv_cond_t importer_condition_variable;
uv_async_t async; uv_async_t async;
const char* file; uv_work_t request;
const char* prev;
void* cookie; // v8 and nan related
bool is_sync; Persistent<Object> result;
Sass_Import** imports;
NanCallback* success_callback;
NanCallback* error_callback; NanCallback* error_callback;
NanCallback* success_callback;
NanCallback* importer_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