X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fthread_pool_observer.cpp;h=d630fd953a5b4cbe2c5661b2861cf04c2a36c1f8;hb=4e67e7b651f010f3f7d11180a6d1062d1bffa50c;hp=832bd29faa8014b82c6f61a30569855b80c95150;hpb=c1d953eee6c00432493bc364da6284704ccd9cc2;p=metaproxy-moved-to-github.git diff --git a/src/thread_pool_observer.cpp b/src/thread_pool_observer.cpp index 832bd29..d630fd9 100644 --- a/src/thread_pool_observer.cpp +++ b/src/thread_pool_observer.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2011 Index Data + Copyright (C) 2005-2012 Index Data Metaproxy 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 @@ -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;