Commit 2e82e70f by Adeel

Importer: Uses uv_cond to solve the puzzle.

Credit goes to @txdv.
parent b2ce0f6f
...@@ -55,8 +55,7 @@ void dispatched_async_uv_callback(uv_async_t *req){ ...@@ -55,8 +55,7 @@ void dispatched_async_uv_callback(uv_async_t *req){
ctx_w->imports[0] = sass_make_import_entry(ctx_w->file, 0, 0); ctx_w->imports[0] = sass_make_import_entry(ctx_w->file, 0, 0);
} }
//uv_mutex_unlock(ctx_w->mutex); uv_cond_signal(&ctx_w->importer_condition_variable);
ctx_w->importer_mutex->unlock();
if (try_catch.HasCaught()) { if (try_catch.HasCaught()) {
node::FatalException(try_catch); node::FatalException(try_catch);
...@@ -67,20 +66,11 @@ struct Sass_Import** sass_importer(const char* file, void* cookie) ...@@ -67,20 +66,11 @@ struct Sass_Import** sass_importer(const char* file, void* cookie)
{ {
sass_context_wrapper* ctx_w = static_cast<sass_context_wrapper*>(cookie); sass_context_wrapper* ctx_w = static_cast<sass_context_wrapper*>(cookie);
ctx_w->importer_mutex->lock();
//uv_mutex_lock(ctx_w->mutex);
// Enter critical section
ctx_w->file = strdup(file); ctx_w->file = strdup(file);
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);
// Reassurances uv_cond_wait(&ctx_w->importer_condition_variable, &ctx_w->importer_mutex);
//uv_mutex_lock(ctx_w->mutex);
//uv_mutex_unlock(ctx_w->mutex);
Sleep(5);
ctx_w->importer_mutex->lock();
ctx_w->importer_mutex->unlock();
return ctx_w->imports; return ctx_w->imports;
} }
......
Subproject commit 21688e1979bff089a13d9a44ad0608357b2a91cc Subproject commit a94377b5aac6a10a6aa3ed90656557e7b9843fd1
...@@ -23,9 +23,9 @@ extern "C" { ...@@ -23,9 +23,9 @@ extern "C" {
} }
sass_context_wrapper* sass_make_context_wrapper() { sass_context_wrapper* sass_make_context_wrapper() {
// (sass_context_wrapper*) calloc(1, sizeof(sass_context_wrapper));
auto ctx_w = (sass_context_wrapper*)calloc(1, sizeof(sass_context_wrapper)); auto ctx_w = (sass_context_wrapper*)calloc(1, sizeof(sass_context_wrapper));
ctx_w->importer_mutex = new std::mutex(); uv_mutex_init(&ctx_w->importer_mutex);
uv_cond_init(&ctx_w->importer_condition_variable);
return ctx_w; return ctx_w;
} }
......
#include <mutex>
#include <nan.h> #include <nan.h>
#include "libsass/sass_context.h" #include "libsass/sass_context.h"
...@@ -17,8 +16,8 @@ extern "C" { ...@@ -17,8 +16,8 @@ extern "C" {
Sass_File_Context* fctx; Sass_File_Context* fctx;
Persistent<Object> stats; Persistent<Object> stats;
uv_work_t request; uv_work_t request;
std::mutex* importer_mutex; uv_mutex_t importer_mutex;
//uv_mutex_t* mutex; uv_cond_t importer_condition_variable;
uv_async_t async; uv_async_t async;
const char* file; const char* file;
void* cookie; void* cookie;
......
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