| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

worker_thread.hpp
Go to the documentation of this file.
1
17 #ifndef THREADPOOL_DETAIL_WORKER_THREAD_HPP_INCLUDED
18 #define THREADPOOL_DETAIL_WORKER_THREAD_HPP_INCLUDED
19
20
21 #include "scope_guard.hpp"
22
23 #include <boost/smart_ptr.hpp>
24 #include <boost/thread.hpp>
25 #include <boost/thread/exceptions.hpp>
26 #include <boost/thread/mutex.hpp>
27 #include <boost/bind.hpp>
28
29
30 namespace boost { namespace threadpool { namespace detail
31 {
32
43 template <typename Pool>
44 class worker_thread
45 : public enable_shared_from_this< worker_thread<Pool> >
46 , private noncopyable
47 {
48 public:
49 typedef Pool pool_type;
50
51 private:
52 shared_ptr<pool_type> m_pool;
53 shared_ptr<boost::thread> m_thread;
54
55
60 worker_thread(shared_ptr<pool_type> const & pool)
61 : m_pool(pool)
62 {
63 assert(pool);
64 }
65
66
69 void died_unexpectedly()
70 {
71 m_pool->worker_died_unexpectedly(this->shared_from_this());
72 }
73
74
75 public:
78 void run()
79 {
80 scope_guard notify_exception(bind(&worker_thread::died_unexpectedly, this));
81
82 while(m_pool->execute_task()) {}
83
84 notify_exception.disable();
85 m_pool->worker_destructed(this->shared_from_this());
86 }
87
88
91 void join()
92 {
93 m_thread->join();
94 }
95
96
100 static void create_and_attach(shared_ptr<pool_type> const & pool)
101 {
102 shared_ptr<worker_thread> worker(new worker_thread(pool));
103 if(worker)
104 {
105 worker->m_thread.reset(new boost::thread(bind(&worker_thread::run, worker)));
106 }
107 }
108
109 };
110
111
112 } } } // namespace boost::threadpool::detail
113
114 #endif // THREADPOOL_DETAIL_WORKER_THREAD_HPP_INCLUDED
115
boost
The namespace threadpool contains a thread pool and related utility classes.
Definition: iter_pos.hpp:13
boost::threadpool::detail::worker_thread::died_unexpectedly
void died_unexpectedly()
Notifies that an exception occurred in the run loop.
Definition: worker_thread.hpp:69
boost::threadpool::detail::worker_thread
Thread pool worker.
Definition: worker_thread.hpp:44
boost::threadpool::detail::worker_thread::m_thread
shared_ptr< boost::thread > m_thread
Pointer to the thread which executes the run loop.
Definition: worker_thread.hpp:53
boost::threadpool::detail::worker_thread::pool_type
Pool pool_type
Indicates the pool&#39;s type.
Definition: worker_thread.hpp:49
boost::threadpool::detail::worker_thread::worker_thread
worker_thread(shared_ptr< pool_type > const &pool)
Constructs a new worker.
Definition: worker_thread.hpp:60
detail
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
pool
Definition: PoolClasses.h:11
boost::threadpool::detail::worker_thread::create_and_attach
static void create_and_attach(shared_ptr< pool_type > const &pool)
Constructs a new worker thread and attaches it to the pool.
Definition: worker_thread.hpp:100
boost::threadpool::detail::worker_thread::run
void run()
Executes pool&#39;s tasks sequentially.
Definition: worker_thread.hpp:78
boost::threadpool::detail::scope_guard::disable
void disable()
Definition: scope_guard.hpp:50
boost::threadpool::detail::worker_thread::join
void join()
Joins the worker&#39;s thread.
Definition: worker_thread.hpp:91
boost::threadpool::detail::scope_guard
Definition: scope_guard.hpp:29
boost::threadpool::detail::worker_thread::m_pool
shared_ptr< pool_type > m_pool
Pointer to the pool which created the worker.
Definition: worker_thread.hpp:52
scope_guard.hpp
TODO.