Skip to content

Commit 9a859cc

Browse files
committed
Merge pull request nodegit#435 from nodegit/fix-libuv-thread
Fix libuv threading issue
2 parents 094f240 + a8da0a2 commit 9a859cc

File tree

5 files changed

+21
-31
lines changed

5 files changed

+21
-31
lines changed

generate/templates/partials/callback_helpers.cc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
baton->req.data = baton;
1717
baton->done = false;
1818

19-
uv_queue_work(uv_default_loop(), &baton->req, {{ cppFunctionName }}_{{ cbFunction.name }}_asyncWork, {{ cppFunctionName }}_{{ cbFunction.name }}_asyncAfter);
19+
uv_async_init(uv_default_loop(), &baton->req, {{ cppFunctionName }}_{{ cbFunction.name }}_async);
20+
uv_async_send(&baton->req);
2021

2122
while(!baton->done) {
2223
this_thread::sleep_for(chrono::milliseconds(1));
@@ -31,13 +32,7 @@
3132
return baton->result;
3233
}
3334

34-
void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_asyncWork(uv_work_t* req) {
35-
// We aren't doing any work on a seperate thread, just need to
36-
// access the main node thread in the async after method.
37-
// However, this worker method is still needed
38-
}
39-
40-
void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_asyncAfter(uv_work_t* req, int status) {
35+
void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_async(uv_async_t* req, int status) {
4136
NanScope();
4237

4338
{{ cppFunctionName }}_{{ cbFunction.name|titleCase }}Baton* baton = static_cast<{{ cppFunctionName }}_{{ cbFunction.name|titleCase }}Baton*>(req->data);
@@ -85,7 +80,8 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_asyncAfter(
8580

8681
NanAssignPersistent(baton->promise, promise);
8782

88-
uv_queue_work(uv_default_loop(), &baton->req, {{ cppFunctionName }}_{{ cbFunction.name }}_asyncWork, {{ cppFunctionName }}_{{ cbFunction.name }}_asyncPromisePolling);
83+
uv_async_init(uv_default_loop(), &baton->req, {{ cppFunctionName }}_{{ cbFunction.name }}_asyncPromisePolling);
84+
uv_async_send(&baton->req);
8985
return;
9086
}
9187
}
@@ -117,7 +113,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_asyncAfter(
117113
baton->done = true;
118114
}
119115

120-
void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_asyncPromisePolling(uv_work_t* req, int status) {
116+
void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_asyncPromisePolling(uv_async_t* req, int status) {
121117
NanScope();
122118

123119
{{ cppFunctionName }}_{{ cbFunction.name|titleCase }}Baton* baton = static_cast<{{ cppFunctionName }}_{{ cbFunction.name|titleCase }}Baton*>(req->data);
@@ -127,7 +123,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_asyncPromis
127123
Local<Boolean> isPending = isPendingFn->Call(0, argv)->ToBoolean();
128124

129125
if (isPending->Value()) {
130-
uv_queue_work(uv_default_loop(), &baton->req, {{ cppFunctionName }}_{{ cbFunction.name }}_asyncWork, {{ cppFunctionName }}_{{ cbFunction.name }}_asyncPromisePolling);
126+
uv_async_send(&baton->req);
131127
return;
132128
}
133129

generate/templates/partials/field_accessors.cc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@
9696
baton->req.data = baton;
9797
baton->done = false;
9898

99-
uv_queue_work(uv_default_loop(), &baton->req, {{ field.name }}_asyncWork, {{ field.name }}_asyncAfter);
99+
uv_async_init(uv_default_loop(), &baton->req, {{ field.name }}_async);
100+
uv_async_send(&baton->req);
100101

101102
while(!baton->done) {
102103
this_thread::sleep_for(chrono::milliseconds(1));
@@ -111,13 +112,7 @@
111112
return baton->result;
112113
}
113114

114-
void {{ cppClassName }}::{{ field.name }}_asyncWork(uv_work_t* req) {
115-
// We aren't doing any work on a seperate thread, just need to
116-
// access the main node thread in the async after method.
117-
// However, this worker method is still needed
118-
}
119-
120-
void {{ cppClassName }}::{{ field.name }}_asyncAfter(uv_work_t* req, int status) {
115+
void {{ cppClassName }}::{{ field.name }}_async(uv_async_t* req, int status) {
121116
NanScope();
122117

123118
{{ field.name|titleCase }}Baton* baton = static_cast<{{ field.name|titleCase }}Baton*>(req->data);
@@ -178,7 +173,8 @@
178173

179174
NanAssignPersistent(baton->promise, promise);
180175

181-
uv_queue_work(uv_default_loop(), &baton->req, {{ field.name }}_asyncWork, {{ field.name }}_asyncPromisePolling);
176+
uv_async_init(uv_default_loop(), &baton->req, {{ field.name }}_asyncPromisePolling);
177+
uv_async_send(&baton->req);
182178
return;
183179
}
184180
}
@@ -210,7 +206,7 @@
210206
baton->done = true;
211207
}
212208

213-
void {{ cppClassName }}::{{ field.name }}_asyncPromisePolling(uv_work_t* req, int status) {
209+
void {{ cppClassName }}::{{ field.name }}_asyncPromisePolling(uv_async_t* req, int status) {
214210
NanScope();
215211

216212
{{ field.name|titleCase }}Baton* baton = static_cast<{{ field.name|titleCase }}Baton*>(req->data);
@@ -220,7 +216,7 @@
220216
Local<Boolean> isPending = isPendingFn->Call(0, argv)->ToBoolean();
221217

222218
if (isPending->Value()) {
223-
uv_queue_work(uv_default_loop(), &baton->req, {{ field.name }}_asyncWork, {{ field.name }}_asyncPromisePolling);
219+
uv_async_send(&baton->req);
224220
return;
225221
}
226222

generate/templates/templates/class_header.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,14 @@ class {{ cppClassName }} : public ObjectWrap {
5757
{% endeach %}
5858
);
5959

60-
static void {{ function.cppFunctionName }}_{{ arg.name }}_asyncWork(uv_work_t* req);
61-
static void {{ function.cppFunctionName }}_{{ arg.name }}_asyncAfter(uv_work_t* req, int status);
62-
static void {{ function.cppFunctionName }}_{{ arg.name }}_asyncPromisePolling(uv_work_t* req, int status);
60+
static void {{ function.cppFunctionName }}_{{ arg.name }}_async(uv_async_t* req, int status);
61+
static void {{ function.cppFunctionName }}_{{ arg.name }}_asyncPromisePolling(uv_async_t* req, int status);
6362
struct {{ function.cppFunctionName }}_{{ arg.name|titleCase }}Baton {
6463
{% each arg.args|argsInfo as cbArg %}
6564
{{ cbArg.cType }} {{ cbArg.name }};
6665
{% endeach %}
6766

68-
uv_work_t req;
67+
uv_async_t req;
6968
{{ arg.return.type }} result;
7069
Persistent<Object> promise;
7170
bool done;

generate/templates/templates/struct_header.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ class {{ cppClassName }} : public ObjectWrap {
4444
{% endeach %}
4545
);
4646

47-
static void {{ field.name }}_asyncWork(uv_work_t* req);
48-
static void {{ field.name }}_asyncAfter(uv_work_t* req, int status);
49-
static void {{ field.name }}_asyncPromisePolling(uv_work_t* req, int status);
47+
static void {{ field.name }}_async(uv_async_t* req, int status);
48+
static void {{ field.name }}_asyncPromisePolling(uv_async_t* req, int status);
5049
struct {{ field.name|titleCase }}Baton {
5150
{% each field.args|argsInfo as arg %}
5251
{{ arg.cType }} {{ arg.name}};
5352
{% endeach %}
5453

55-
uv_work_t req;
54+
uv_async_t req;
5655
{{ field.return.type }} result;
5756
Persistent<Object> promise;
5857
bool done;

test/tests/remote.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe("Remote", function() {
112112
});
113113
});
114114

115-
it.skip("can monitor transfer progress while downloading", function() {
115+
it("can monitor transfer progress while downloading", function() {
116116
// Set a reasonable timeout here now that our repository has grown.
117117
this.timeout(600000);
118118

0 commit comments

Comments
 (0)