Re-add mutex that was taken away in
authorCarl Hetherington <cth@carlh.net>
Wed, 4 Nov 2020 22:33:10 +0000 (23:33 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 4 Nov 2020 22:36:56 +0000 (23:36 +0100)
73ebb92e9df01ba7afb97121b6e2cef6ca13a18e

I'm not sure why it was removed, and it seems necessary;
servers_list_changed() can be called from a variety of different places
(the constructor and two different EncodeServerFinder threads).

May help with #1854.

src/lib/j2k_encoder.cc
src/lib/j2k_encoder.h

index 18bb27645ea72e209d0054323dd235570fe4bd45..c000f8599cfa89a0b3aa70320ac6b805bcda9c43 100644 (file)
@@ -178,7 +178,11 @@ J2KEncoder::encode (shared_ptr<PlayerVideo> pv, DCPTime time)
 {
        _waker.nudge ();
 
-       size_t threads = _threads->size();
+       size_t threads = 0;
+       {
+               boost::mutex::scoped_lock lm (_threads_mutex);
+               threads = _threads->size();
+       }
 
        boost::mutex::scoped_lock queue_lock (_queue_mutex);
 
@@ -240,6 +244,7 @@ void
 J2KEncoder::terminate_threads ()
 {
        boost::this_thread::disable_interruption dis;
+       boost::mutex::scoped_lock lm (_threads_mutex);
 
        if (!_threads) {
                return;
@@ -370,6 +375,8 @@ J2KEncoder::servers_list_changed ()
        terminate_threads ();
        _threads.reset (new boost::thread_group());
 
+       boost::mutex::scoped_lock lm (_threads_mutex);
+
        /* XXX: could re-use threads */
 
        if (!Config::instance()->only_servers_encode ()) {
index d56fc1aecd19576c15c96525ce77193fff66d9f9..818c75c99209052044f6d2131e680417406555a2 100644 (file)
@@ -87,6 +87,7 @@ private:
 
        EventHistory _history;
 
+       boost::mutex _threads_mutex;
        boost::shared_ptr<boost::thread_group> _threads;
 
        mutable boost::mutex _queue_mutex;