Skip to content

Commit 9e244ac

Browse files
committed
Trigger the event loop semaphore at the right time
This should prevent the hidden window on Windows from getting spammed, and also prevent qode from entering this weird "slow down" state.
1 parent 2b2ce83 commit 9e244ac

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

qode/integration/node_integration.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ void NodeIntegration::UvRunOnce() {
6363

6464
// Deal with uv events.
6565
uv_run(uv_loop_, UV_RUN_NOWAIT);
66-
67-
// Tell the worker thread to continue polling.
68-
uv_sem_post(&embed_sem_);
6966
}
7067

7168
void NodeIntegration::CallNextTick() {
@@ -79,6 +76,8 @@ void NodeIntegration::ReleaseHandleRef() {
7976
void NodeIntegration::WakeupMainThread() {
8077
PostTask([this] {
8178
this->UvRunOnce();
79+
// Tell the worker thread to continue polling.
80+
uv_sem_post(&this->embed_sem_);
8281
});
8382
}
8483

@@ -91,8 +90,6 @@ void NodeIntegration::EmbedThreadRunner(void *arg) {
9190
NodeIntegration* self = static_cast<NodeIntegration*>(arg);
9291

9392
while (true) {
94-
// Wait for the main loop to deal with events.
95-
uv_sem_wait(&self->embed_sem_);
9693
if (self->embed_closed_)
9794
break;
9895

@@ -113,6 +110,9 @@ void NodeIntegration::EmbedThreadRunner(void *arg) {
113110

114111
// Deal with event in main thread.
115112
self->WakeupMainThread();
113+
114+
// Wait for the main loop to deal with events.
115+
uv_sem_wait(&self->embed_sem_);
116116
}
117117
}
118118

qode/integration/node_integration_win.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "qode/integration/node_integration_win.h"
66
#include "uv/src/uv-common.h"
7+
#include <stdio.h>
78

89
// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
910
extern "C" IMAGE_DOS_HEADER __ImageBase;
@@ -70,7 +71,11 @@ void NodeIntegrationWin::PostTask(const std::function<void()>& task) {
7071
::EnterCriticalSection(&lock_);
7172
tasks_[++task_id_] = task;
7273
::LeaveCriticalSection(&lock_);
73-
::PostMessage(message_window_, WM_USER, task_id_, 0L);
74+
BOOL result = ::PostMessage(message_window_, WM_USER, task_id_, 0L);
75+
if (result == 0) {
76+
int lastError = ::GetLastError();
77+
fprintf(stderr, "Qode: PostMessage() failed! LastError=%d\n", lastError);
78+
}
7479
}
7580

7681
void NodeIntegrationWin::OnTask(int id) {

0 commit comments

Comments
 (0)