Skip to content

Commit 5a44a6a

Browse files
committed
Start dedicated thread / loop for libgit2 calls
1 parent c603d2d commit 5a44a6a

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef NODEGIT_H
2+
#define NODEGIT_H
3+
4+
#include "nan.h"
5+
6+
extern uv_loop_t *libgit2_loop;
7+
8+
#endif

‎generate/templates/templates/nodegit.cc‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <node.h>
44
#include <git2.h>
55

6+
#include "../include/nodegit.h"
67
#include "../include/wrapper.h"
78
#include "../include/functions/copy.h"
89
{% each %}
@@ -11,6 +12,8 @@
1112
{% endif %}
1213
{% endeach %}
1314

15+
void run_libgit2_event_queue(void *);
16+
1417
extern "C" void init(Local<v8::Object> target) {
1518
Nan::HandleScope scope;
1619

@@ -20,6 +23,28 @@ extern "C" void init(Local<v8::Object> target) {
2023
{{ cppClassName }}::InitializeComponent(target);
2124
{% endif %}
2225
{% endeach %}
26+
27+
// initialize a thread on which we will execute all libgit2 calls
28+
// for async NodeGit wrappers (and sync ones, eventually)
29+
uv_thread_t libgit2_thread_id;
30+
uv_thread_create(&libgit2_thread_id, run_libgit2_event_queue, NULL);
2331
}
2432

2533
NODE_MODULE(nodegit, init)
34+
35+
uv_loop_t *libgit2_loop;
36+
37+
void run_libgit2_event_queue(void *)
38+
{
39+
uv_loop_t *loop = (uv_loop_t *)malloc(sizeof(uv_loop_t));
40+
uv_loop_init(loop);
41+
42+
// run, CPU, run
43+
for ( ; ; ) {
44+
uv_run(loop, UV_RUN_DEFAULT);
45+
// TODO: break out of loop
46+
}
47+
48+
uv_loop_close(loop);
49+
free(loop);
50+
}

0 commit comments

Comments
 (0)