Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
800738a4
Commit
800738a4
authored
Nov 22, 2014
by
Adeel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Importer: Moves mutex in context.
parent
292e1ba5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
41 deletions
+39
-41
binding.cpp
src/binding.cpp
+28
-34
sass_context_wrapper.cpp
src/sass_context_wrapper.cpp
+4
-1
sass_context_wrapper.h
src/sass_context_wrapper.h
+7
-6
No files found.
src/binding.cpp
View file @
800738a4
#include <mutex>
#include <nan.h>
#include "sass_context_wrapper.h"
...
...
@@ -13,27 +12,22 @@ char* CreateString(Local<Value> value) {
return
str
;
}
static
std
::
mutex
importer_mutex
;
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
();
sass_context_wrapper
*
ctx_w
=
static_cast
<
sass_context_wrapper
*>
(
req
->
data
);
TryCatch
try_catch
;
import_bag
*
bag
=
static_cast
<
import_bag
*>
(
req
->
data
);
Handle
<
Value
>
argv
[]
=
{
NanNew
<
String
>
(
bag
->
file
)
NanNew
<
String
>
(
ctx_w
->
file
)
};
Local
<
Value
>
returned_value
=
NanNew
<
Value
>
(
((
NanCallback
*
)
bag
->
cookie
)
->
Call
(
1
,
argv
));
Local
<
Value
>
returned_value
=
NanNew
<
Value
>
(
ctx_w
->
importer_callback
->
Call
(
1
,
argv
));
if
(
returned_value
->
IsArray
())
{
Handle
<
Array
>
array
=
Handle
<
Array
>::
Cast
(
returned_value
);
bag
->
inc
s
=
sass_make_import_list
(
array
->
Length
());
ctx_w
->
import
s
=
sass_make_import_list
(
array
->
Length
());
for
(
size_t
i
=
0
;
i
<
array
->
Length
();
++
i
)
{
Local
<
Value
>
value
=
array
->
Get
(
i
);
...
...
@@ -45,24 +39,25 @@ void dispatched_async_uv_callback(uv_async_t *req){
char
*
path
=
CreateString
(
object
->
Get
(
String
::
New
(
"file"
)));
char
*
contents
=
CreateString
(
object
->
Get
(
String
::
New
(
"contents"
)));
bag
->
inc
s
[
i
]
=
sass_make_import_entry
(
path
,
(
!
contents
||
contents
[
0
]
==
'\0'
)
?
0
:
strdup
(
contents
),
0
);
ctx_w
->
import
s
[
i
]
=
sass_make_import_entry
(
path
,
(
!
contents
||
contents
[
0
]
==
'\0'
)
?
0
:
strdup
(
contents
),
0
);
}
}
else
if
(
returned_value
->
IsObject
())
{
bag
->
inc
s
=
sass_make_import_list
(
1
);
ctx_w
->
import
s
=
sass_make_import_list
(
1
);
Local
<
Object
>
object
=
Local
<
Object
>::
Cast
(
returned_value
);
char
*
path
=
CreateString
(
object
->
Get
(
String
::
New
(
"file"
)));
char
*
contents
=
CreateString
(
object
->
Get
(
String
::
New
(
"contents"
)));
bag
->
inc
s
[
0
]
=
sass_make_import_entry
(
path
,
(
!
contents
||
contents
[
0
]
==
'\0'
)
?
0
:
strdup
(
contents
),
0
);
ctx_w
->
import
s
[
0
]
=
sass_make_import_entry
(
path
,
(
!
contents
||
contents
[
0
]
==
'\0'
)
?
0
:
strdup
(
contents
),
0
);
}
else
{
bag
->
inc
s
=
sass_make_import_list
(
1
);
bag
->
incs
[
0
]
=
sass_make_import_entry
(
bag
->
file
,
0
,
0
);
ctx_w
->
import
s
=
sass_make_import_list
(
1
);
ctx_w
->
imports
[
0
]
=
sass_make_import_entry
(
ctx_w
->
file
,
0
,
0
);
}
v8_lock
.
unlock
();
//importer_mutex.unlock();
//uv_mutex_unlock(ctx_w->mutex);
ctx_w
->
importer_mutex
->
unlock
();
if
(
try_catch
.
HasCaught
())
{
node
::
FatalException
(
try_catch
);
}
...
...
@@ -70,26 +65,24 @@ void dispatched_async_uv_callback(uv_async_t *req){
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
));
bag
->
cookie
=
cookie
;
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
;
uv_async_send
(
&
async
);
sass_context_wrapper
*
ctx_w
=
static_cast
<
sass_context_wrapper
*>
(
cookie
);
// Dispatch immediately
//uv_run(async.loop, UV_RUN_DEFAULT);
uv_mutex_t
t
;
ctx_w
->
importer_mutex
->
lock
();
//uv_mutex_lock(ctx_w->mutex);
Sass_Import
**
import
=
bag
->
incs
;
// Enter critical section
ctx_w
->
file
=
file
;
ctx_w
->
async
.
data
=
(
void
*
)
&
ctx_w
;
uv_async_send
(
&
ctx_w
->
async
);
free
(
bag
);
// Reassurances
//uv_mutex_lock(ctx_w->mutex);
//uv_mutex_unlock(ctx_w->mutex);
ctx_w
->
importer_mutex
->
lock
();
ctx_w
->
importer_mutex
->
unlock
();
return
import
;
return
ctx_w
->
imports
;
}
void
ExtractOptions
(
Local
<
Object
>
options
,
void
*
cptr
,
sass_context_wrapper
*
ctx_w
,
bool
isFile
)
{
...
...
@@ -124,7 +117,8 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx
ctx_w
->
importer_callback
=
new
NanCallback
(
importer_callback
);
if
(
!
importer_callback
->
IsUndefined
()){
sass_option_set_importer
(
sass_options
,
sass_make_importer
(
sass_importer
,
ctx_w
->
importer_callback
));
uv_async_init
(
uv_default_loop
(),
&
ctx_w
->
async
,
(
uv_async_cb
)
dispatched_async_uv_callback
);
sass_option_set_importer
(
sass_options
,
sass_make_importer
(
sass_importer
,
ctx_w
));
}
}
...
...
src/sass_context_wrapper.cpp
View file @
800738a4
...
...
@@ -22,7 +22,10 @@ extern "C" {
}
sass_context_wrapper
*
sass_make_context_wrapper
()
{
return
(
sass_context_wrapper
*
)
calloc
(
1
,
sizeof
(
sass_context_wrapper
));
// (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
::
recursive_mutex
();
return
ctx_w
;
}
void
sass_free_context_wrapper
(
sass_context_wrapper
*
ctx_w
)
{
...
...
src/sass_context_wrapper.h
View file @
800738a4
#include <mutex>
#include <nan.h>
#include "libsass/sass_context.h"
...
...
@@ -16,17 +17,17 @@ struct sass_context_wrapper {
Sass_File_Context
*
fctx
;
Persistent
<
Object
>
stats
;
uv_work_t
request
;
std
::
recursive_mutex
*
importer_mutex
;
//uv_mutex_t* mutex;
uv_async_t
async
;
const
char
*
file
;
void
*
cookie
;
Sass_Import
**
imports
;
NanCallback
*
success_callback
;
NanCallback
*
error_callback
;
NanCallback
*
importer_callback
;
};
struct
import_bag
{
const
char
*
file
;
void
*
cookie
;
Sass_Import
**
incs
;
};
struct
sass_context_wrapper
*
sass_make_context_wrapper
(
void
);
void
sass_free_context_wrapper
(
struct
sass_context_wrapper
*
ctx_w
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment