The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
ThreadPoolSvc.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2026 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
#pragma once
12
13
#include <
GaudiKernel/ConcurrencyFlags.h
>
14
#include <
GaudiKernel/IThreadInitTool.h
>
15
#include <
GaudiKernel/IThreadPoolSvc.h
>
16
#include <
GaudiKernel/Service.h
>
17
#include <
GaudiKernel/ToolHandle.h
>
18
19
#include <boost/thread/barrier.hpp>
20
21
#include <tbb/global_control.h>
22
#include <tbb/spin_mutex.h>
23
#include <tbb/task_arena.h>
24
25
#include <memory>
26
#include <vector>
27
38
class
ThreadPoolSvc
:
public
extends
<Service, IThreadPoolSvc, Gaudi::Concurrency::ConcurrencyManager> {
39
public
:
41
ThreadPoolSvc
(
const
std::string&
name
,
ISvcLocator
* svc );
42
44
StatusCode
initialize
()
override
final
;
45
47
StatusCode
finalize
()
override
final
;
48
50
StatusCode
initPool
(
const
int
&
poolSize
,
const
int
& maxParallelismExtra )
override
final
;
51
53
StatusCode
terminatePool
()
override
final
;
54
55
int
poolSize
() const override final {
return
m_threadPoolSize
; }
56
57
virtual
bool
isInit
()
const
{
return
m_init
; }
58
59
virtual
void
initThisThread
()
override
;
60
61
tbb::task_arena*
getArena
() {
return
&
m_arena
; }
62
63
private
:
65
StatusCode
launchTasks
(
bool
finalize
=
false
);
66
68
ToolHandleArray<IThreadInitTool>
m_threadInitTools
= {
this
};
69
71
bool
m_init
=
false
;
72
74
int
m_threadPoolSize
= 0;
75
77
tbb::spin_mutex
m_initMutex
;
78
80
std::unique_ptr<boost::barrier>
m_barrier
;
81
83
std::unique_ptr<tbb::global_control>
m_tbbgc
;
84
86
tbb::task_arena
m_arena
;
87
89
std::atomic<int>
m_threadInitCount
= 0;
90
};
ConcurrencyFlags.h
IThreadInitTool.h
IThreadPoolSvc.h
Service.h
ToolHandle.h
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition
ISvcLocator.h:42
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition
Service.cpp:333
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
ThreadPoolSvc::initThisThread
virtual void initThisThread() override
Definition
ThreadPoolSvc.cpp:234
ThreadPoolSvc::initPool
StatusCode initPool(const int &poolSize, const int &maxParallelismExtra) override final
Initialize the thread pool and launch the ThreadInitTasks.
Definition
ThreadPoolSvc.cpp:73
ThreadPoolSvc::launchTasks
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.
Definition
ThreadPoolSvc.cpp:158
ThreadPoolSvc::m_tbbgc
std::unique_ptr< tbb::global_control > m_tbbgc
TBB global control parameter.
Definition
ThreadPoolSvc.h:83
ThreadPoolSvc::m_threadInitCount
std::atomic< int > m_threadInitCount
Counter for all threads that are initialised.
Definition
ThreadPoolSvc.h:89
ThreadPoolSvc::isInit
virtual bool isInit() const
Definition
ThreadPoolSvc.h:57
ThreadPoolSvc::m_init
bool m_init
Was the thread pool initialized?
Definition
ThreadPoolSvc.h:71
ThreadPoolSvc::m_barrier
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
Definition
ThreadPoolSvc.h:80
ThreadPoolSvc::m_threadPoolSize
int m_threadPoolSize
Size of the thread pool allocated.
Definition
ThreadPoolSvc.h:74
ThreadPoolSvc::getArena
tbb::task_arena * getArena()
Definition
ThreadPoolSvc.h:61
ThreadPoolSvc::m_threadInitTools
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
Definition
ThreadPoolSvc.h:68
ThreadPoolSvc::terminatePool
StatusCode terminatePool() override final
Terminate the thread pool and launch thread termination tasks.
Definition
ThreadPoolSvc.cpp:137
ThreadPoolSvc::poolSize
int poolSize() const override final
Definition
ThreadPoolSvc.h:55
ThreadPoolSvc::m_arena
tbb::task_arena m_arena
TBB task arena to run all algorithms.
Definition
ThreadPoolSvc.h:86
ThreadPoolSvc::finalize
StatusCode finalize() override final
Finalise.
Definition
ThreadPoolSvc.cpp:62
ThreadPoolSvc::m_initMutex
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
Definition
ThreadPoolSvc.h:77
ThreadPoolSvc::initialize
StatusCode initialize() override final
Initialise.
Definition
ThreadPoolSvc.cpp:38
ThreadPoolSvc::ThreadPoolSvc
ThreadPoolSvc(const std::string &name, ISvcLocator *svc)
Constructor.
Definition
ThreadPoolSvc.cpp:32
ToolHandleArray
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition
ToolHandle.h:396
extends
Base class used to extend a class implementing other interfaces.
Definition
extends.h:19
GaudiHive
src
ThreadPoolSvc.h
Generated on
for The Gaudi Framework by
1.17.0