The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
ThreadPoolSvc.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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
15#include <GaudiKernel/Service.h>
17
18#include <boost/thread/barrier.hpp>
19
20#include <tbb/global_control.h>
21#include <tbb/spin_mutex.h>
22#include <tbb/task_arena.h>
23
24#include <memory>
25#include <vector>
26
37class ThreadPoolSvc : public extends<Service, IThreadPoolSvc> {
38public:
40 ThreadPoolSvc( const std::string& name, ISvcLocator* svc );
41
43 StatusCode initialize() override final;
44
46 StatusCode finalize() override final;
47
49 StatusCode initPool( const int& poolSize, const int& maxParallelismExtra ) override final;
50
52 StatusCode terminatePool() override final;
53
54 int poolSize() const override final { return m_threadPoolSize; }
55
56 virtual bool isInit() const { return m_init; }
57
58 virtual void initThisThread() override;
59
60 tbb::task_arena* getArena() { return &m_arena; }
61
62private:
64 StatusCode launchTasks( bool finalize = false );
65
68
70 bool m_init = false;
71
74
76 tbb::spin_mutex m_initMutex;
77
79 std::unique_ptr<boost::barrier> m_barrier;
80
82 std::unique_ptr<tbb::global_control> m_tbbgc;
83
85 tbb::task_arena m_arena;
86
88 std::atomic<int> m_threadInitCount = 0;
89};
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< boost::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:393
Base class used to extend a class implementing other interfaces.
Definition extends.h:19