Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
13 #include <memory>
14 #include <vector>
15 
26 class ThreadPoolSvc : public extends<Service, IThreadPoolSvc> {
27 public:
29  ThreadPoolSvc( const std::string& name, ISvcLocator* svc );
30 
32  StatusCode initialize() override final;
33 
35  StatusCode finalize() override final;
36 
38  StatusCode initPool( const int& poolSize ) override final;
39 
41  StatusCode terminatePool() override final;
42 
43  int poolSize() const override final { return m_threadPoolSize; }
44 
45  virtual bool isInit() const { return m_init; }
46 
47  virtual void initThisThread() override;
48 
49 private:
51  StatusCode launchTasks( bool finalize = false );
52 
55 
57  bool m_init = false;
58 
61 
63  tbb::spin_mutex m_initMutex;
64 
67 
70 };
71 
72 #endif
StatusCode finalize() override final
Finalise.
ThreadPoolSvc(const std::string &name, ISvcLocator *svc)
Constructor.
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.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
virtual bool isInit() const
Definition: ThreadPoolSvc.h:45
int m_threadPoolSize
Size of the thread pool allocated.
Definition: ThreadPoolSvc.h:60
STL class.
bool m_init
Was the thread pool initialized?
Definition: ThreadPoolSvc.h:57
virtual void initThisThread() override
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:69
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
Definition: ThreadPoolSvc.h:63
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:26
std::unique_ptr< tbb::task_scheduler_init > m_tbbSchedInit
TBB task scheduler initializer.
Definition: ThreadPoolSvc.h:66
StatusCode initPool(const int &poolSize) override final
Initialize the thread pool and launch the ThreadInitTasks.
int poolSize() const override final
Definition: ThreadPoolSvc.h:43
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
Definition: ThreadPoolSvc.h:54
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.