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 
4 #include "GaudiKernel/Service.h"
8 
9 #include "tbb/spin_mutex.h"
10 #include "tbb/task_scheduler_init.h"
11 #include "boost/thread.hpp"
12 
13 #include <vector>
14 #include <memory>
15 
26 class ThreadPoolSvc: public extends<Service,
27  IThreadPoolSvc> {
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 {
45  return m_threadPoolSize;
46  }
47 
48  virtual bool isInit() const { return m_init; }
49 
50 private:
51 
53  StatusCode launchTasks(bool finalize=false);
54 
57 
59  bool m_init;
60 
63 
65  tbb::spin_mutex m_initMutex;
66 
69 
72 
73 };
74 
75 #endif
virtual 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
virtual 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:289
virtual bool isInit() const
Definition: ThreadPoolSvc.h:48
int m_threadPoolSize
Size of the thread pool allocated.
Definition: ThreadPoolSvc.h:62
STL class.
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:26
virtual int poolSize() const override final
Definition: ThreadPoolSvc.h:44
virtual 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:26
std::unique_ptr< tbb::task_scheduler_init > m_tbbSchedInit
TBB task scheduler initializer.
Definition: ThreadPoolSvc.h:68
virtual 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
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.