From: Peter Åstrand (astrand) Date: Mon, 7 May 2018 12:59:57 +0000 (+0200) Subject: Avoid creating unused thread on single CPU machines X-Git-Tag: v1.8.90~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=67814b638783f3dde6dd8df12346bbdf81c70efc;p=tigervnc.git Avoid creating unused thread on single CPU machines --- 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);