From a2327d00b64241d3de8e5a173535bf65d0eeffe7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 1 Oct 2015 11:24:47 +0200 Subject: [PATCH] thread::attribute only available in Boost 1.50 or later --- src/thread_pool_observer.cpp | 41 ++++++++++++++++++++--------------------- src/thread_pool_observer.hpp | 1 + 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/thread_pool_observer.cpp b/src/thread_pool_observer.cpp index f7d3e63..c2a854f 100644 --- a/src/thread_pool_observer.cpp +++ b/src/thread_pool_observer.cpp @@ -106,22 +106,14 @@ ThreadPoolSocketObserver::ThreadPoolSocketObserver( obs->maskObserver(this, SOCKET_OBSERVE_READ); m_p->m_stop_flag = false; - m_p->m_min_threads = m_p->m_no_threads = min_threads; + m_p->m_no_threads = 0; + m_p->m_min_threads = min_threads; m_p->m_max_threads = max_threads; m_p->m_waiting_threads = 0; m_p->m_stack_size = stack_size; unsigned i; - for (i = 0; i < m_p->m_no_threads; i++) - { - Worker w(this); - boost::thread::attributes attrs; - if (m_p->m_stack_size) - attrs.set_stack_size(m_p->m_stack_size); - - boost::thread *x = new boost::thread(attrs, w); - - m_p->m_thrds.add_thread(x); - } + for (i = 0; i < min_threads; i++) + add_worker(); } ThreadPoolSocketObserver::~ThreadPoolSocketObserver() @@ -135,6 +127,21 @@ ThreadPoolSocketObserver::~ThreadPoolSocketObserver() m_p->m_socketObservable->deleteObserver(this); } +void ThreadPoolSocketObserver::add_worker(void) +{ + Worker w(this); +#if BOOST_VERSION >= 1050000 + boost::thread::attributes attrs; + if (m_p->m_stack_size) + attrs.set_stack_size(m_stack_size); + boost::thread *x = new boost::thread(attrs, w); +#else + boost::thread *x = new boost::thread(w); +#endif + m_p->m_no_threads++; + m_p->m_thrds.add_thread(x); +} + void ThreadPoolSocketObserver::socketNotify(int event) { if (event & SOCKET_OBSERVE_READ) @@ -245,15 +252,7 @@ void ThreadPoolSocketObserver::put(IThreadPoolMsg *m) if (m_p->m_waiting_threads == 0 && m_p->m_no_threads < m_p->m_max_threads) { - m_p->m_no_threads++; - Worker w(this); - - boost::thread::attributes attrs; - if (m_p->m_stack_size) - attrs.set_stack_size(m_p->m_stack_size); - boost::thread *x = new boost::thread(attrs, w); - - m_p->m_thrds.add_thread(x); + add_worker(); } while (m_p->m_input.size() >= m_p->m_no_threads * queue_size_per_thread) m_p->m_cond_input_full.wait(input_lock); diff --git a/src/thread_pool_observer.hpp b/src/thread_pool_observer.hpp index 8d59897..f10a16f 100644 --- a/src/thread_pool_observer.hpp +++ b/src/thread_pool_observer.hpp @@ -47,6 +47,7 @@ namespace metaproxy_1 { void run(void *p); void get_thread_info(int &tbusy, int &total); private: + void add_worker(void); void socketNotify(int event); boost::scoped_ptr m_p; -- 1.7.10.4