The Gaudi Framework  v32r2 (46d42edc)
ThreadPoolSvc.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_THREADPOOLSVC_H
2 #define GAUDIHIVE_THREADPOOLSVC_H
3 
6 #include "GaudiKernel/Service.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 
57 
59  bool m_init = false;
60 
63 
65  tbb::spin_mutex m_initMutex;
66 
69 
72 
75 };
76 
77 #endif
StatusCode finalize() override final
Finalise.
ThreadPoolSvc(const std::string &name, ISvcLocator *svc)
Constructor.
std::unique_ptr< tbb::global_control > m_tbbgc
TBB global control parameter.
Definition: ThreadPoolSvc.h:74
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
StatusCode terminatePool() override final
Terminate the thread pool and launch thread termination tasks.
virtual void initThisThread() override
virtual bool isInit() const
Definition: ThreadPoolSvc.h:47
int m_threadPoolSize
Size of the thread pool allocated.
Definition: ThreadPoolSvc.h:62
STL class.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
bool m_init
Was the thread pool initialized?
Definition: ThreadPoolSvc.h:59
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode initialize() override final
Initialise.
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
Definition: ThreadPoolSvc.h:71
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
Definition: ThreadPoolSvc.h:65
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
A service which initializes a TBB thread pool.
Definition: ThreadPoolSvc.h:28
std::unique_ptr< tbb::task_scheduler_init > m_tbbSchedInit
TBB task scheduler initializer.
Definition: ThreadPoolSvc.h:68
StatusCode initPool(const int &poolSize) override final
Initialize the thread pool and launch the ThreadInitTasks.
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
Definition: ThreadPoolSvc.h:56
int poolSize() const override final
Definition: ThreadPoolSvc.h:45
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.