From 67814b638783f3dde6dd8df12346bbdf81c70efc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20=C3=85strand=20=28astrand=29?= Date: Mon, 7 May 2018 14:59:57 +0200 Subject: [PATCH] Avoid creating unused thread on single CPU machines --- common/rfb/DecodeManager.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/rfb/DecodeManager.cxx b/common/rfb/DecodeManager.cxx index ccf084f7..774f7bb8 100644 --- a/common/rfb/DecodeManager.cxx +++ b/common/rfb/DecodeManager.cxx @@ -64,6 +64,12 @@ DecodeManager::DecodeManager(CConnection *conn) : vlog.info("Creating %d decoder thread(s)", (int)cpuCount); } + if (cpuCount == 1) { + // Threads are not used on single CPU machines + freeBuffers.push_back(new rdr::MemOutStream()); + return; + } + while (cpuCount--) { // Twice as many possible entries in the queue as there // are worker threads to make sure they don't stall @@ -123,7 +129,7 @@ void DecodeManager::decodeRect(const Rect& r, int encoding, // Fast path for single CPU machines to avoid the context // switching overhead - if (threads.size() == 1) { + if (threads.empty()) { bufferStream = freeBuffers.front(); bufferStream->clear(); decoder->readRect(r, conn->getInStream(), conn->cp, bufferStream); -- 2.39.5