]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/boost/boost/thread/detail/thread_group.hpp
Add subset of boost library headers needed for compilation on PowerPC
[eurobot/public.git] / src / boost / boost / thread / detail / thread_group.hpp
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
7
8 #include <list>
9 #include <boost/thread/shared_mutex.hpp>
10 #include <boost/thread/mutex.hpp>
11
12 #include <boost/config/abi_prefix.hpp>
13
14 #ifdef BOOST_MSVC
15 #pragma warning(push)
16 #pragma warning(disable:4251)
17 #endif
18
19 namespace boost
20 {
21     class thread_group
22     {
23     private:
24         thread_group(thread_group const&);
25         thread_group& operator=(thread_group const&);        
26     public:
27         thread_group() {}
28         ~thread_group()
29         {
30             for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
31                 it!=end;
32                 ++it)
33             {
34                 delete *it;
35             }
36         }
37
38         template<typename F>
39         thread* create_thread(F threadfunc)
40         {
41             boost::lock_guard<shared_mutex> guard(m);
42             std::auto_ptr<thread> new_thread(new thread(threadfunc));
43             threads.push_back(new_thread.get());
44             return new_thread.release();
45         }
46         
47         void add_thread(thread* thrd)
48         {
49             if(thrd)
50             {
51                 boost::lock_guard<shared_mutex> guard(m);
52                 threads.push_back(thrd);
53             }
54         }
55             
56         void remove_thread(thread* thrd)
57         {
58             boost::lock_guard<shared_mutex> guard(m);
59             std::list<thread*>::iterator const it=std::find(threads.begin(),threads.end(),thrd);
60             if(it!=threads.end())
61             {
62                 threads.erase(it);
63             }
64         }
65         
66         void join_all()
67         {
68             boost::shared_lock<shared_mutex> guard(m);
69             
70             for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
71                 it!=end;
72                 ++it)
73             {
74                 (*it)->join();
75             }
76         }
77         
78         void interrupt_all()
79         {
80             boost::shared_lock<shared_mutex> guard(m);
81             
82             for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
83                 it!=end;
84                 ++it)
85             {
86                 (*it)->interrupt();
87             }
88         }
89         
90         size_t size() const
91         {
92             boost::shared_lock<shared_mutex> guard(m);
93             return threads.size();
94         }
95         
96     private:
97         std::list<thread*> threads;
98         mutable shared_mutex m;
99     };
100 }
101
102 #ifdef BOOST_MSVC
103 #pragma warning(pop)
104 #endif
105
106 #include <boost/config/abi_suffix.hpp>
107
108 #endif