| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

ThreadPoolSvc.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_THREADPOOLSVC_H
2 #define GAUDIHIVE_THREADPOOLSVC_H
3
4 #include "GaudiKernel/IThreadInitTool.h"
5 #include "GaudiKernel/IThreadPoolSvc.h"
6 #include "GaudiKernel/Service.h"
7 #include "GaudiKernel/ToolHandle.h"
8
9 #include "boost/thread.hpp"
10 #include "tbb/spin_mutex.h"
11 #include "tbb/task_scheduler_init.h"
12
13 #include <memory>
14 #include <vector>
15
26 class ThreadPoolSvc : public extends<Service, IThreadPoolSvc>
27 {
28 public:
30 ThreadPoolSvc( const std::string& name, ISvcLocator* svc );
31
33 virtual StatusCode initialize() override final;
34
36 virtual StatusCode finalize() override final;
37
39 virtual StatusCode initPool( const int& poolSize ) override final;
40
42 virtual StatusCode terminatePool() override final;
43
44 virtual int poolSize() const override final { return m_threadPoolSize; }
45
46 virtual bool isInit() const { return m_init; }
47
48 private:
50 StatusCode launchTasks( bool finalize = false );
51
53 ToolHandleArray<IThreadInitTool> m_threadInitTools;
54
56 bool m_init;
57
59 int m_threadPoolSize;
60
62 tbb::spin_mutex m_initMutex;
63
65 std::unique_ptr<tbb::task_scheduler_init> m_tbbSchedInit;
66
68 std::unique_ptr<boost::barrier> m_barrier;
69 };
70
71 #endif
ThreadPoolSvc::finalize
virtual StatusCode finalize() override final
Finalise.
Definition: ThreadPoolSvc.cpp:60
ThreadPoolSvc::ThreadPoolSvc
ThreadPoolSvc(const std::string &name, ISvcLocator *svc)
Constructor.
Definition: ThreadPoolSvc.cpp:19
IThreadPoolSvc.h
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ThreadPoolSvc::terminatePool
virtual StatusCode terminatePool() override final
Terminate the thread pool and launch thread termination tasks.
Definition: ThreadPoolSvc.cpp:128
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
ThreadPoolSvc::isInit
virtual bool isInit() const
Definition: ThreadPoolSvc.h:46
ToolHandleArray< IThreadInitTool >
ThreadPoolSvc::m_threadPoolSize
int m_threadPoolSize
Size of the thread pool allocated.
Definition: ThreadPoolSvc.h:59
std::string
STL class.
Service.h
ThreadPoolSvc::m_init
bool m_init
Was the thread pool initialized?
Definition: ThreadPoolSvc.h:56
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
ThreadPoolSvc::poolSize
virtual int poolSize() const override final
Definition: ThreadPoolSvc.h:44
ThreadPoolSvc::initialize
virtual StatusCode initialize() override final
Initialise.
Definition: ThreadPoolSvc.cpp:33
ThreadPoolSvc::m_barrier
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
Definition: ThreadPoolSvc.h:68
ThreadPoolSvc::m_initMutex
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
Definition: ThreadPoolSvc.h:62
std::unique_ptr< tbb::task_scheduler_init >
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
ThreadPoolSvc
A service which initializes a TBB thread pool.
Definition: ThreadPoolSvc.h:26
ToolHandle.h
ThreadPoolSvc::m_tbbSchedInit
std::unique_ptr< tbb::task_scheduler_init > m_tbbSchedInit
TBB task scheduler initializer.
Definition: ThreadPoolSvc.h:65
ThreadPoolSvc::initPool
virtual StatusCode initPool(const int &poolSize) override final
Initialize the thread pool and launch the ThreadInitTasks.
Definition: ThreadPoolSvc.cpp:73
ThreadPoolSvc::m_threadInitTools
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
Definition: ThreadPoolSvc.h:53
IThreadInitTool.h
ThreadPoolSvc::launchTasks
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.
Definition: ThreadPoolSvc.cpp:149