| The Gaudi Framework v32r1 (f65d50dc)

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 #define TBB_PREVIEW_GLOBAL_CONTROL 1
13 #include "tbb/global_control.h"
14
15 #include <memory>
16 #include <vector>
17
28 class ThreadPoolSvc : public extends<Service, IThreadPoolSvc> {
29 public:
31 ThreadPoolSvc( const std::string& name, ISvcLocator* svc );
32
34 StatusCode initialize() override final;
35
37 StatusCode finalize() override final;
38
40 StatusCode initPool( const int& poolSize ) override final;
41
43 StatusCode terminatePool() override final;
44
45 int poolSize() const override final { return m_threadPoolSize; }
46
47 virtual bool isInit() const { return m_init; }
48
49 virtual void initThisThread() override;
50
51 private:
53 StatusCode launchTasks( bool finalize = false );
54
56 ToolHandleArray<IThreadInitTool> m_threadInitTools = {this};
57
59 bool m_init = false;
60
62 int m_threadPoolSize = 0;
63
65 tbb::spin_mutex m_initMutex;
66
68 std::unique_ptr<tbb::task_scheduler_init> m_tbbSchedInit;
69
71 std::unique_ptr<boost::barrier> m_barrier;
72
74 std::unique_ptr<tbb::global_control> m_tbbgc;
75 };
76
77 #endif
ThreadPoolSvc::finalize
StatusCode finalize() override final
Finalise.
Definition: ThreadPoolSvc.cpp:55
ThreadPoolSvc::ThreadPoolSvc
ThreadPoolSvc(const std::string &name, ISvcLocator *svc)
Constructor.
Definition: ThreadPoolSvc.cpp:24
IThreadPoolSvc.h
ThreadPoolSvc::m_tbbgc
std::unique_ptr< tbb::global_control > m_tbbgc
TBB global control parameter.
Definition: ThreadPoolSvc.h:74
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ThreadPoolSvc::terminatePool
StatusCode terminatePool() override final
Terminate the thread pool and launch thread termination tasks.
Definition: ThreadPoolSvc.cpp:132
ToolHandleArray< IThreadInitTool >
ThreadPoolSvc::initThisThread
virtual void initThisThread() override
Definition: ThreadPoolSvc.cpp:233
ThreadPoolSvc::isInit
virtual bool isInit() const
Definition: ThreadPoolSvc.h:47
ThreadPoolSvc::m_threadPoolSize
int m_threadPoolSize
Size of the thread pool allocated.
Definition: ThreadPoolSvc.h:62
std::string
STL class.
Service.h
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
ThreadPoolSvc::m_init
bool m_init
Was the thread pool initialized?
Definition: ThreadPoolSvc.h:59
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
ThreadPoolSvc::initialize
StatusCode initialize() override final
Initialise.
Definition: ThreadPoolSvc.cpp:30
ThreadPoolSvc::m_barrier
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
Definition: ThreadPoolSvc.h:71
ThreadPoolSvc::m_initMutex
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
Definition: ThreadPoolSvc.h:65
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:28
ToolHandle.h
ThreadPoolSvc::m_tbbSchedInit
std::unique_ptr< tbb::task_scheduler_init > m_tbbSchedInit
TBB task scheduler initializer.
Definition: ThreadPoolSvc.h:68
ThreadPoolSvc::initPool
StatusCode initPool(const int &poolSize) override final
Initialize the thread pool and launch the ThreadInitTasks.
Definition: ThreadPoolSvc.cpp:67
ThreadPoolSvc::m_threadInitTools
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
Definition: ThreadPoolSvc.h:56
IThreadInitTool.h
ThreadPoolSvc::poolSize
int poolSize() const override final
Definition: ThreadPoolSvc.h:45
ThreadPoolSvc::launchTasks
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.
Definition: ThreadPoolSvc.cpp:152