From e8a6e330570b817c6c5fdfef0f508f2cbe0168ef Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 5 Nov 2013 23:21:07 +0000 Subject: Add multiple threads for servers with multiple processing threads. --- src/lib/encoder.cc | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/lib/encoder.cc') diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index f1d2375b6..a442e64d0 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -72,16 +72,18 @@ Encoder::~Encoder () } } -/** Add a worker thread for a remote server. Caller must hold +/** Add a worker thread for a each thread on a remote server. Caller must hold * a lock on _mutex, or know that one is not currently required to * safely modify _threads. */ void -Encoder::add_worker_thread (ServerDescription d) +Encoder::add_worker_threads (ServerDescription d) { - _threads.push_back ( - make_pair (d, new boost::thread (boost::bind (&Encoder::encoder_thread, this, d))) - ); + for (int i = 0; i < d.threads(); ++i) { + _threads.push_back ( + make_pair (d, new boost::thread (boost::bind (&Encoder::encoder_thread, this, d))) + ); + } } void @@ -99,9 +101,7 @@ Encoder::process_begin () vector servers = Config::instance()->servers (); for (vector::iterator i = servers.begin(); i != servers.end(); ++i) { - for (int j = 0; j < i->threads (); ++j) { - add_worker_thread (*i); - } + add_worker_threads (*i); } _broadcast_thread = new boost::thread (boost::bind (&Encoder::broadcast_thread, this)); @@ -432,10 +432,7 @@ Encoder::listen_thread () } if (i == _threads.end ()) { - cout << "Adding a thread for " << ip << "\n"; - add_worker_thread (ServerDescription (ip, xml->number_child ("Threads"))); - } else { - cout << "Already know about " << ip << "\n"; + add_worker_threads (ServerDescription (ip, xml->number_child ("Threads"))); } } } -- cgit v1.2.3