fix: allow 2 threads for CreateIoCompletionPort on single-core to prevent busy looping (backport: 3-1-x) (#16011)
* allow 2 threads for CreateIoCompletionPort on single-core * use base::SysInfo::NumberOfProcessors instead of env var * CHECK that uv_loop_ has not been used before replacing its iocp
This commit is contained in:
parent
3c4cd3f662
commit
9490a9f9ba
1 changed files with 15 additions and 1 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <windows.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/sys_info.h"
|
||||
|
||||
extern "C" {
|
||||
#include "vendor/node/deps/uv/src/win/internal.h"
|
||||
|
@ -15,7 +16,20 @@ extern "C" {
|
|||
namespace atom {
|
||||
|
||||
NodeBindingsWin::NodeBindingsWin(BrowserEnvironment browser_env)
|
||||
: NodeBindings(browser_env) {}
|
||||
: NodeBindings(browser_env) {
|
||||
// on single-core the io comp port NumberOfConcurrentThreads needs to be 2
|
||||
// to avoid cpu pegging likely caused by a busy loop in PollEvents
|
||||
if (base::SysInfo::NumberOfProcessors() == 1) {
|
||||
// the expectation is the uv_loop_ has just been initialized
|
||||
// which makes iocp replacement safe
|
||||
CHECK_EQ(0u, uv_loop_->active_handles);
|
||||
CHECK_EQ(0u, uv_loop_->active_reqs.count);
|
||||
|
||||
if (uv_loop_->iocp && uv_loop_->iocp != INVALID_HANDLE_VALUE)
|
||||
CloseHandle(uv_loop_->iocp);
|
||||
uv_loop_->iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
NodeBindingsWin::~NodeBindingsWin() {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue