The Gaudi Framework  v30r3 (a5ef0a68)
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 {
28 public:
30  ThreadPoolSvc( const std::string& name, ISvcLocator* svc );
31 
33  StatusCode initialize() override final;
34 
36  StatusCode finalize() override final;
37 
39  StatusCode initPool( const int& poolSize ) override final;
40 
42  StatusCode terminatePool() override final;
43 
44  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 
54 
56  bool m_init = false;
57 
60 
62  tbb::spin_mutex m_initMutex;
63 
66 
69 };
70 
71 #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:288
virtual bool isInit() const
Definition: ThreadPoolSvc.h:46
int m_threadPoolSize
Size of the thread pool allocated.
Definition: ThreadPoolSvc.h:59
STL class.
bool m_init
Was the thread pool initialized?
Definition: ThreadPoolSvc.h:56
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
StatusCode initialize() override final
Initialise.
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
Definition: ThreadPoolSvc.h:68
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
Definition: ThreadPoolSvc.h:62
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:65
StatusCode initPool(const int &poolSize) override final
Initialize the thread pool and launch the ThreadInitTasks.
int poolSize() const override final
Definition: ThreadPoolSvc.h:44
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
Definition: ThreadPoolSvc.h:53
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.