From 78c9e9838a205bbd66e0a5456514a0818e024b66 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 5 Mar 2016 21:03:31 +0000 Subject: Set thread affinity on Windows XP so that each encoder thread is tied to a single CPU. There is some suggestion on the web that Windows 7 does this better, which may explain the slowdowns and erratic timings that we see post-2.6.3 on Windows XP (see #771). --- src/lib/encoder.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 8ba794a8e..34cae7d76 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -381,9 +381,23 @@ Encoder::servers_list_changed () boost::mutex::scoped_lock lm (_threads_mutex); +#ifdef BOOST_THREAD_PLATFORM_WIN32 + OSVERSIONINFO info; + info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + GetVersionEx (&info); + bool const windows_xp = (info.dwMajorVersion == 5 && info.dwMinorVersion == 1); + LOG_GENERAL_NC (N_("Setting thread affinity for Windows XP")); +#endif + if (!Config::instance()->only_servers_encode ()) { for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) { - _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, optional ()))); + boost::thread* t = new boost::thread (boost::bind (&Encoder::encoder_thread, this, optional ())); + _threads.push_back (t); +#ifdef BOOST_THREAD_PLATFORM_WIN32 + if (windows_xp) { + SetThreadAffinityMask (t->native_handle(), 1 << i); + } +#endif } } -- cgit v1.2.3