Fix crash when loading old state files.
[dcpomatic.git] / src / lib / encoder.cc
index 8ba794a8e4c43b368e6cb801f4de28aac150e430..36e4fe55d4adba72ca2aff7416393c6a5e7bf85c 100644 (file)
@@ -1,19 +1,20 @@
 /*
     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
+    DCP-o-matic is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
@@ -381,9 +382,25 @@ 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);
+       if (windows_xp) {
+               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
                }
        }