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/shared_mutex.hpp>
10
#include <boost/thread/mutex.hpp>
11
#include <boost/thread/lock_guard.hpp>
13
#include <boost/config/abi_prefix.hpp>
17
#pragma warning(disable:4251)
25
thread_group(thread_group const&);
26
thread_group& operator=(thread_group const&);
31
for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
39
bool is_this_thread_in()
41
thread::id id = this_thread::get_id();
42
boost::shared_lock<shared_mutex> guard(m);
43
for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
47
if ((*it)->get_id() == id)
53
bool is_thread_in(thread* thrd)
57
thread::id id = thrd->get_id();
58
boost::shared_lock<shared_mutex> guard(m);
59
for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
63
if ((*it)->get_id() == id)
75
thread* create_thread(F threadfunc)
77
boost::lock_guard<shared_mutex> guard(m);
78
std::auto_ptr<thread> new_thread(new thread(threadfunc));
79
threads.push_back(new_thread.get());
80
return new_thread.release();
83
void add_thread(thread* thrd)
87
BOOST_THREAD_ASSERT_PRECONDITION( ! is_thread_in(thrd) ,
88
thread_resource_error(system::errc::resource_deadlock_would_occur, "boost::thread_group: trying to add a duplicated thread")
91
boost::lock_guard<shared_mutex> guard(m);
92
threads.push_back(thrd);
96
void remove_thread(thread* thrd)
98
boost::lock_guard<shared_mutex> guard(m);
99
std::list<thread*>::iterator const it=std::find(threads.begin(),threads.end(),thrd);
100
if(it!=threads.end())
108
BOOST_THREAD_ASSERT_PRECONDITION( ! is_this_thread_in() ,
109
thread_resource_error(system::errc::resource_deadlock_would_occur, "boost::thread_group: trying joining itself")
111
boost::shared_lock<shared_mutex> guard(m);
113
for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
117
if ((*it)->joinable())
122
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
125
boost::shared_lock<shared_mutex> guard(m);
127
for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
138
boost::shared_lock<shared_mutex> guard(m);
139
return threads.size();
143
std::list<thread*> threads;
144
mutable shared_mutex m;
152
#include <boost/config/abi_suffix.hpp>