Set thread affinity on Windows XP so that each encoder thread
authorCarl Hetherington <cth@carlh.net>
Sat, 5 Mar 2016 21:03:31 +0000 (21:03 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 5 Mar 2016 22:20:37 +0000 (22:20 +0000)
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).

ChangeLog
src/lib/encoder.cc

index 3bb168cfa5dc7467115b847ce6b631ab6a5bbf14..2f3ab4c255a7d9de216434678d68bfbf29ac8e02 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-03-05  Carl Hetherington  <cth@carlh.net>
+
+       * Try to fix slowdowns on Windows XP (#771).
+
 2016-03-02  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.6.31 released.
index 8ba794a8e4c43b368e6cb801f4de28aac150e430..34cae7d768c6ad229ecfd14c2b253d5fdd37904d 100644 (file)
@@ -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<EncodeServerDescription> ())));
+                       boost::thread* t = new boost::thread (boost::bind (&Encoder::encoder_thread, this, optional<EncodeServerDescription> ()));
+                       _threads.push_back (t);
+#ifdef BOOST_THREAD_PLATFORM_WIN32
+                       if (windows_xp) {
+                               SetThreadAffinityMask (t->native_handle(), 1 << i);
+                       }
+#endif
                }
        }