Skip to content

Commit 1b5aa3a

Browse files
committed
Add support for node 10.5's --experimental-worker threading support
1 parent 5278b2b commit 1b5aa3a

6 files changed

Lines changed: 18 additions & 14 deletions

File tree

src/async.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ template <class Item, class Parent> class Async {
2222
Parent* parent;
2323

2424
public:
25-
Async(Parent* parent_, Callback cb_)
25+
Async(uv_loop_t* loop_, Parent* parent_, Callback cb_)
2626
: callback(cb_), parent(parent_) {
2727
watcher.data = this;
2828
NODE_SQLITE3_MUTEX_INIT
29-
uv_async_init(uv_default_loop(), &watcher, reinterpret_cast<uv_async_cb>(listener));
29+
uv_async_init(loop_, &watcher, reinterpret_cast<uv_async_cb>(listener));
3030
}
3131

3232
static void listener(uv_async_t* handle, int status) {

src/database.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ NAN_METHOD(Database::New) {
127127
callback = Local<Function>::Cast(info[pos++]);
128128
}
129129

130-
Database* db = new Database();
130+
Database* db = new Database(node::GetCurrentEventLoop(info.GetIsolate()));
131131
db->Wrap(info.This());
132132

133133
Nan::ForceSet(info.This(), Nan::New("filename").ToLocalChecked(), info[0].As<String>(), ReadOnly);
@@ -141,7 +141,7 @@ NAN_METHOD(Database::New) {
141141
}
142142

143143
void Database::Work_BeginOpen(Baton* baton) {
144-
int status = uv_queue_work(uv_default_loop(),
144+
int status = uv_queue_work(baton->db->loop,
145145
&baton->request, Work_Open, (uv_after_work_cb)Work_AfterOpen);
146146
assert(status == 0);
147147
}
@@ -227,7 +227,7 @@ void Database::Work_BeginClose(Baton* baton) {
227227
baton->db->RemoveCallbacks();
228228
baton->db->closing = true;
229229

230-
int status = uv_queue_work(uv_default_loop(),
230+
int status = uv_queue_work(baton->db->loop,
231231
&baton->request, Work_Close, (uv_after_work_cb)Work_AfterClose);
232232
assert(status == 0);
233233
}
@@ -388,7 +388,7 @@ void Database::RegisterTraceCallback(Baton* baton) {
388388

389389
if (db->debug_trace == NULL) {
390390
// Add it.
391-
db->debug_trace = new AsyncTrace(db, TraceCallback);
391+
db->debug_trace = new AsyncTrace(db->loop, db, TraceCallback);
392392
sqlite3_trace(db->_handle, TraceCallback, db);
393393
}
394394
else {
@@ -426,7 +426,7 @@ void Database::RegisterProfileCallback(Baton* baton) {
426426

427427
if (db->debug_profile == NULL) {
428428
// Add it.
429-
db->debug_profile = new AsyncProfile(db, ProfileCallback);
429+
db->debug_profile = new AsyncProfile(db->loop, db, ProfileCallback);
430430
sqlite3_profile(db->_handle, ProfileCallback, db);
431431
}
432432
else {
@@ -467,7 +467,7 @@ void Database::RegisterUpdateCallback(Baton* baton) {
467467

468468
if (db->update_event == NULL) {
469469
// Add it.
470-
db->update_event = new AsyncUpdate(db, UpdateCallback);
470+
db->update_event = new AsyncUpdate(db->loop, db, UpdateCallback);
471471
sqlite3_update_hook(db->_handle, UpdateCallback, db);
472472
}
473473
else {
@@ -522,7 +522,7 @@ void Database::Work_BeginExec(Baton* baton) {
522522
assert(baton->db->open);
523523
assert(baton->db->_handle);
524524
assert(baton->db->pending == 0);
525-
int status = uv_queue_work(uv_default_loop(),
525+
int status = uv_queue_work(baton->db->loop,
526526
&baton->request, Work_Exec, (uv_after_work_cb)Work_AfterExec);
527527
assert(status == 0);
528528
}
@@ -622,7 +622,7 @@ void Database::Work_BeginLoadExtension(Baton* baton) {
622622
assert(baton->db->open);
623623
assert(baton->db->_handle);
624624
assert(baton->db->pending == 0);
625-
int status = uv_queue_work(uv_default_loop(),
625+
int status = uv_queue_work(baton->db->loop,
626626
&baton->request, Work_LoadExtension, reinterpret_cast<uv_after_work_cb>(Work_AfterLoadExtension));
627627
assert(status == 0);
628628
}

src/database.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ class Database : public Nan::ObjectWrap {
100100
friend class Statement;
101101

102102
protected:
103-
Database() : Nan::ObjectWrap(),
103+
Database(uv_loop_t* loop_) : Nan::ObjectWrap(),
104104
_handle(NULL),
105+
loop(loop_),
105106
open(false),
106107
closing(false),
107108
locked(false),
@@ -172,7 +173,10 @@ class Database : public Nan::ObjectWrap {
172173

173174
protected:
174175
sqlite3* _handle;
176+
public:
177+
uv_loop_t* loop;
175178

179+
protected:
176180
bool open;
177181
bool closing;
178182
bool locked;

src/macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const char* sqlite_authorizer_string(int type);
122122
assert(baton->stmt->prepared); \
123123
baton->stmt->locked = true; \
124124
baton->stmt->db->pending++; \
125-
int status = uv_queue_work(uv_default_loop(), \
125+
int status = uv_queue_work(baton->stmt->db->loop, \
126126
&baton->request, \
127127
Work_##type, reinterpret_cast<uv_after_work_cb>(Work_After##type)); \
128128
assert(status == 0);

src/statement.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ NAN_METHOD(Statement::New) {
115115
void Statement::Work_BeginPrepare(Database::Baton* baton) {
116116
assert(baton->db->open);
117117
baton->db->pending++;
118-
int status = uv_queue_work(uv_default_loop(),
118+
int status = uv_queue_work(baton->db->loop,
119119
&baton->request, Work_Prepare, (uv_after_work_cb)Work_AfterPrepare);
120120
assert(status == 0);
121121
}

src/statement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class Statement : public Nan::ObjectWrap {
174174
watcher.data = this;
175175
NODE_SQLITE3_MUTEX_INIT
176176
stmt->Ref();
177-
uv_async_init(uv_default_loop(), &watcher, async_cb);
177+
uv_async_init(stmt->db->loop, &watcher, async_cb);
178178
}
179179

180180
~Async() {

0 commit comments

Comments
 (0)