The Gaudi Framework master (9cc87df9)
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// Framework includes
17#include <GaudiKernel/Service.h>
19
20// STL includes
21#include <atomic>
22#include <barrier>
23#include <memory>
24#include <string>
25#include <vector>
26
27// TBB includes
28#include <tbb/global_control.h>
29#include <tbb/spin_mutex.h>
30#include <tbb/task_arena.h>
31
42class ThreadPoolSvc : public extends<Service, IThreadPoolSvc, Gaudi::Concurrency::ConcurrencyManager> {
43public:
45 ThreadPoolSvc( const std::string& name, ISvcLocator* svc );
46
48 StatusCode initialize() override final;
49
51 StatusCode finalize() override final;
52
54 StatusCode initPool( const int& poolSize, const int& maxParallelismExtra ) override final;
55
57 StatusCode terminatePool() override final;
58
59 int poolSize() const override final { return m_threadPoolSize; }
60
61 virtual bool isInit() const { return m_init; }
62
63 virtual void initThisThread() override;
64
65 tbb::task_arena* getArena() { return &m_arena; }
66
67private:
69 StatusCode launchTasks( bool finalize = false );
70
73
75 bool m_init = false;
76
79
81 tbb::spin_mutex m_initMutex;
82
85
88
90 tbb::task_arena m_arena;
91
94};
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
virtual void initThisThread() override
StatusCode initPool(const int &poolSize, const int &maxParallelismExtra) override final
Initialize the thread pool and launch the ThreadInitTasks.
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.
std::unique_ptr< tbb::global_control > m_tbbgc
TBB global control parameter.
std::atomic< int > m_threadInitCount
Counter for all threads that are initialised.
virtual bool isInit() const
bool m_init
Was the thread pool initialized?
std::unique_ptr< std::barrier<> > m_barrier
Barrier used to synchronization thread init tasks.
int m_threadPoolSize
Size of the thread pool allocated.
tbb::task_arena * getArena()
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
StatusCode terminatePool() override final
Terminate the thread pool and launch thread termination tasks.
int poolSize() const override final
tbb::task_arena m_arena
TBB task arena to run all algorithms.
StatusCode finalize() override final
Finalise.
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
StatusCode initialize() override final
Initialise.
ThreadPoolSvc(const std::string &name, ISvcLocator *svc)
Constructor.
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition ToolHandle.h:396
Base class used to extend a class implementing other interfaces.
Definition extends.h:19