Commit 292e1ba5 by Adeel

Importer-cb: Adds lock to acquire v8 main thread.

parent cbcacc24
#include <mutex>
#include <nan.h> #include <nan.h>
#include "sass_context_wrapper.h" #include "sass_context_wrapper.h"
...@@ -12,9 +13,12 @@ char* CreateString(Local<Value> value) { ...@@ -12,9 +13,12 @@ char* CreateString(Local<Value> value) {
return str; return str;
} }
uv_async_t async; static std::mutex importer_mutex;
void dispatched_async_uv_callback(uv_async_t *req){ void dispatched_async_uv_callback(uv_async_t *req){
std::unique_lock<std::mutex> v8_lock(importer_mutex);
v8_lock.lock();
//importer_mutex.lock();
NanScope(); NanScope();
TryCatch try_catch; TryCatch try_catch;
...@@ -57,6 +61,8 @@ void dispatched_async_uv_callback(uv_async_t *req){ ...@@ -57,6 +61,8 @@ void dispatched_async_uv_callback(uv_async_t *req){
bag->incs[0] = sass_make_import_entry(bag->file, 0, 0); bag->incs[0] = sass_make_import_entry(bag->file, 0, 0);
} }
v8_lock.unlock();
//importer_mutex.unlock();
if (try_catch.HasCaught()) { if (try_catch.HasCaught()) {
node::FatalException(try_catch); node::FatalException(try_catch);
} }
...@@ -64,16 +70,20 @@ void dispatched_async_uv_callback(uv_async_t *req){ ...@@ -64,16 +70,20 @@ void dispatched_async_uv_callback(uv_async_t *req){
struct Sass_Import** sass_importer(const char* file, void* cookie) struct Sass_Import** sass_importer(const char* file, void* cookie)
{ {
std::try_lock(importer_mutex);
import_bag* bag = (import_bag*)calloc(1, sizeof(import_bag)); import_bag* bag = (import_bag*)calloc(1, sizeof(import_bag));
bag->cookie = cookie; bag->cookie = cookie;
bag->file = file; bag->file = file;
uv_async_t async;
uv_async_init(uv_default_loop(), &async, (uv_async_cb)dispatched_async_uv_callback);
async.data = (void*)bag; async.data = (void*)bag;
uv_async_send(&async); uv_async_send(&async);
// Dispatch immediately // Dispatch immediately
uv_run(async.loop, UV_RUN_DEFAULT); //uv_run(async.loop, UV_RUN_DEFAULT);
Sass_Import** import = bag->incs; Sass_Import** import = bag->incs;
...@@ -115,7 +125,6 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx ...@@ -115,7 +125,6 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx
if (!importer_callback->IsUndefined()){ if (!importer_callback->IsUndefined()){
sass_option_set_importer(sass_options, sass_make_importer(sass_importer, ctx_w->importer_callback)); sass_option_set_importer(sass_options, sass_make_importer(sass_importer, ctx_w->importer_callback));
uv_async_init(uv_default_loop(), &async, (uv_async_cb)dispatched_async_uv_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