Skip to content

Commit 74b4833

Browse files
committed
Fix
This fix prevents the Orchestrator instance from waiting for each libgit2 callback to end before starting with the next one. This way more than one libgit2 callback can be dispatched to the main JS thread, so that they can run in parallel. NOTE1: the Threadpool creates 10 Orchestrator instances. NOTE2: an Orchestrator instance takes the libgit2 callbacks from its executorEventsQueue. NOTE3: libgit2 callbacks for the same AsyncWorker might be created in different libigt2 threads (the case for LFS checkout), but they will queue in the same Executor's queue.
1 parent 1acd78f commit 74b4833

2 files changed

Lines changed: 3 additions & 14 deletions

File tree

generate/templates/manual/src/async_baton.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ namespace nodegit {
6060
ThreadPool::QueueCallbackFn queueCallback,
6161
ThreadPool::Callback callbackCompleted
6262
) -> ThreadPool::Callback {
63-
this->onCompletion = callbackCompleted;
63+
this->onCompletion = std::bind(&AsyncBaton::SignalCompletion, this);
6464

6565
queueCallback(jsCallback, cancelCallback);
6666

67-
return std::bind(&AsyncBaton::SignalCompletion, this);
67+
return []() {};
6868
}
6969
);
7070

generate/templates/manual/src/thread_pool.cc

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,25 +374,14 @@ namespace nodegit {
374374

375375
// We must have received a callback from libgit2
376376
auto callbackEvent = std::static_pointer_cast<Executor::CallbackEvent>(event);
377-
std::shared_ptr<std::mutex> callbackMutex(new std::mutex);
378-
std::shared_ptr<std::condition_variable> callbackCondition(new std::condition_variable);
379-
bool hasCompleted = false;
380377

381378
LockMaster::TemporaryUnlock temporaryUnlock;
382379
auto onCompletedCallback = (*callbackEvent)(
383380
[this](ThreadPool::Callback callback, ThreadPool::Callback cancelCallback) {
384381
queueCallbackOnJSThread(callback, cancelCallback, false);
385382
},
386-
[callbackCondition, callbackMutex, &hasCompleted]() {
387-
std::lock_guard<std::mutex> lock(*callbackMutex);
388-
hasCompleted = true;
389-
callbackCondition->notify_one();
390-
}
383+
[]() {}
391384
);
392-
393-
std::unique_lock<std::mutex> lock(*callbackMutex);
394-
while (!hasCompleted) callbackCondition->wait(lock);
395-
onCompletedCallback();
396385
}
397386

398387
queueCallbackOnJSThread(

0 commit comments

Comments
 (0)