X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fthread_pool_observer.cpp;h=d630fd953a5b4cbe2c5661b2861cf04c2a36c1f8;hb=dc0a7b40ef2cc8138c93e078dd8c34de64460ebe;hp=ded50d70f82fa510b7381ff91c802f70b8737103;hpb=50597d2f7d3607e91c94601eb8eb495d73be3eae;p=metaproxy-moved-to-github.git diff --git a/src/thread_pool_observer.cpp b/src/thread_pool_observer.cpp index ded50d7..d630fd9 100644 --- a/src/thread_pool_observer.cpp +++ b/src/thread_pool_observer.cpp @@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include #include #include @@ -68,6 +69,7 @@ namespace metaproxy_1 { std::deque m_output; bool m_stop_flag; unsigned m_no_threads; + unsigned m_no_threads_waiting; }; const unsigned int queue_size_per_thread = 64; } @@ -100,6 +102,7 @@ ThreadPoolSocketObserver::ThreadPoolSocketObserver( m_p->m_stop_flag = false; m_p->m_no_threads = no_threads; + m_p->m_no_threads_waiting = 0; int i; for (i = 0; im_output.front(); m_p->m_output.pop_front(); } + + if (out) - out->result(); + { + std::ostringstream os; + { + boost::mutex::scoped_lock input_lock(m_p->m_mutex_input_data); + os << "tbusy/total " << + m_p->m_no_threads - m_p->m_no_threads_waiting << + "/" << m_p->m_no_threads + << " queue in/out " << m_p->m_input.size() << "/" + << m_p->m_output.size(); + } + out->result(os.str().c_str()); + } } } @@ -157,8 +173,10 @@ void ThreadPoolSocketObserver::run(void *p) IThreadPoolMsg *in = 0; { boost::mutex::scoped_lock input_lock(m_p->m_mutex_input_data); + m_p->m_no_threads_waiting++; while (!m_p->m_stop_flag && m_p->m_input.size() == 0) m_p->m_cond_input_data.wait(input_lock); + m_p->m_no_threads_waiting--; if (m_p->m_stop_flag) break;