#include <windows.h>
#else
#include <pthread.h>
+#include <unistd.h>
#endif
#include <rdr/Exception.h>
return running;
}
+size_t Thread::getSystemCPUCount()
+{
+#ifdef WIN32
+ SYSTEM_INFO si;
+ size_t count;
+ DWORD mask;
+
+ GetSystemInfo(&si);
+
+ count = 0;
+ for (mask = si.dwActiveProcessorMask;mask != 0;mask >>= 1) {
+ if (mask & 0x1)
+ count++;
+ }
+
+ if (count > si.dwNumberOfProcessors)
+ count = si.dwNumberOfProcessors;
+
+ return count;
+#else
+ long ret;
+
+ ret = sysconf(_SC_NPROCESSORS_ONLN);
+ if (ret == -1)
+ return 0;
+
+ return ret;
+#endif
+}
+
#ifdef WIN32
long unsigned __stdcall Thread::startRoutine(void* data)
#else
DecodeManager::DecodeManager(CConnection *conn) :
conn(conn)
{
- int i;
+ size_t cpuCount;
memset(decoders, 0, sizeof(decoders));
producerCond = new os::Condition(queueMutex);
consumerCond = new os::Condition(queueMutex);
- // Just a single thread for now as we haven't sorted out the
- // dependencies between rects
- for (i = 0;i < 1;i++) {
+ cpuCount = os::Thread::getSystemCPUCount();
+ if (cpuCount == 0) {
+ vlog.error("Unable to determine the number of CPU cores on this system");
+ cpuCount = 1;
+ } else {
+ vlog.info("Detected %d CPU core(s) available for decoding", (int)cpuCount);
+ }
+
+ while (cpuCount--) {
// Twice as many possible entries in the queue as there
// are worker threads to make sure they don't stall
freeBuffers.push_back(new rdr::MemOutStream());