The Gaudi Framework  v33r1 (b1225454)
ThreadPoolSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIHIVE_THREADPOOLSVC_H
12 #define GAUDIHIVE_THREADPOOLSVC_H
13 
16 #include "GaudiKernel/Service.h"
17 #include "GaudiKernel/ToolHandle.h"
18 
19 #include "boost/thread.hpp"
20 #include "tbb/spin_mutex.h"
21 #include "tbb/tbb_stddef.h"
22 #if TBB_INTERFACE_VERSION_MAJOR < 12
23 # include "tbb/task_scheduler_init.h"
24 # define TBB_PREVIEW_GLOBAL_CONTROL 1
25 #endif // TBB_INTERFACE_VERSION_MAJOR < 12
26 #include "tbb/global_control.h"
27 
28 #include <memory>
29 #include <vector>
30 
41 class ThreadPoolSvc : public extends<Service, IThreadPoolSvc> {
42 public:
44  ThreadPoolSvc( const std::string& name, ISvcLocator* svc );
45 
47  StatusCode initialize() override final;
48 
50  StatusCode finalize() override final;
51 
53  StatusCode initPool( const int& poolSize ) override final;
54 
56  StatusCode terminatePool() override final;
57 
58  int poolSize() const override final { return m_threadPoolSize; }
59 
60  virtual bool isInit() const { return m_init; }
61 
62  virtual void initThisThread() override;
63 
64 private:
66  StatusCode launchTasks( bool finalize = false );
67 
70 
72  bool m_init = false;
73 
76 
78  tbb::spin_mutex m_initMutex;
79 
80 #if TBB_INTERFACE_VERSION_MAJOR < 12
83 #endif // TBB_INTERFACE_VERSION_MAJOR < 12
84 
87 
90 };
91 
92 #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:89
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
StatusCode terminatePool() override final
Terminate the thread pool and launch thread termination tasks.
virtual void initThisThread() override
virtual bool isInit() const
Definition: ThreadPoolSvc.h:60
int m_threadPoolSize
Size of the thread pool allocated.
Definition: ThreadPoolSvc.h:75
STL class.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
bool m_init
Was the thread pool initialized?
Definition: ThreadPoolSvc.h:72
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
StatusCode initialize() override final
Initialise.
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
Definition: ThreadPoolSvc.h:86
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
Definition: ThreadPoolSvc.h:78
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
A service which initializes a TBB thread pool.
Definition: ThreadPoolSvc.h:41
std::unique_ptr< tbb::task_scheduler_init > m_tbbSchedInit
TBB task scheduler initializer.
Definition: ThreadPoolSvc.h:82
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:69
int poolSize() const override final
Definition: ThreadPoolSvc.h:58
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.