1 #ifndef BOOST_THREAD_DETAIL_THREAD_GROUP_HPP
2 #define BOOST_THREAD_DETAIL_THREAD_GROUP_HPP
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 // (C) Copyright 2007-9 Anthony Williams
9 #include <boost/thread/csbl/memory/unique_ptr.hpp>
10 #include <boost/thread/shared_mutex.hpp>
11 #include <boost/thread/mutex.hpp>
12 #include <boost/thread/lock_guard.hpp>
14 #include <boost/config/abi_prefix.hpp>
18 #pragma warning(disable:4251)
26 thread_group(thread_group const&);
27 thread_group& operator=(thread_group const&);
32 for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
40 bool is_this_thread_in()
42 thread::id id = this_thread::get_id();
43 boost::shared_lock<shared_mutex> guard(m);
44 for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
48 if ((*it)->get_id() == id)
54 bool is_thread_in(thread* thrd)
58 thread::id id = thrd->get_id();
59 boost::shared_lock<shared_mutex> guard(m);
60 for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
64 if ((*it)->get_id() == id)
76 thread* create_thread(F threadfunc)
78 boost::lock_guard<shared_mutex> guard(m);
79 boost::csbl::unique_ptr<thread> new_thread(new thread(threadfunc));
80 threads.push_back(new_thread.get());
81 return new_thread.release();
84 void add_thread(thread* thrd)
88 BOOST_THREAD_ASSERT_PRECONDITION( ! is_thread_in(thrd) ,
89 thread_resource_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost::thread_group: trying to add a duplicated thread")
92 boost::lock_guard<shared_mutex> guard(m);
93 threads.push_back(thrd);
97 void remove_thread(thread* thrd)
99 boost::lock_guard<shared_mutex> guard(m);
100 std::list<thread*>::iterator const it=std::find(threads.begin(),threads.end(),thrd);
101 if(it!=threads.end())
109 BOOST_THREAD_ASSERT_PRECONDITION( ! is_this_thread_in() ,
110 thread_resource_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost::thread_group: trying joining itself")
112 boost::shared_lock<shared_mutex> guard(m);
114 for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
118 if ((*it)->joinable())
123 #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
126 boost::shared_lock<shared_mutex> guard(m);
128 for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
139 boost::shared_lock<shared_mutex> guard(m);
140 return threads.size();
144 std::list<thread*> threads;
145 mutable shared_mutex m;
153 #include <boost/config/abi_suffix.hpp>