ATLAS Offline Software
ThreadInitTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ATHEXHIVE_THREADINITTOOL_H
6 #define ATHEXHIVE_THREADINITTOOL_H
7 
9 #include "GaudiKernel/IThreadInitTool.h"
10 
11 #include <string>
12 #include <atomic>
13 
14 //-------------------------------------------------------------------------------
15 //
16 // This is an example of a Tool that will get executed in every thread by the
17 // ThreadPoolSvc.
18 //
19 // At the beginning of the job, just after the ThreadPool has been created,
20 // the initThread() method of the Tool will be called in each thread.
21 //
22 // as a check, m_nInitThreads MUST be incremented at the end of the initThread()
23 // method.
24 //
25 // At the end of the job, the terminateThread() method will be called.
26 //
27 //-------------------------------------------------------------------------------
28 
29 
30 class ThreadInitTool: virtual public extends1<AthAlgTool, IThreadInitTool> {
31 
32 public:
33  ThreadInitTool( const std::string&, const std::string&, const IInterface* );
34 
35 
36  virtual void initThread() override;
37  virtual void terminateThread() override;
38 
39  virtual unsigned int nInit() const override { return m_nInitThreads; }
40 
41 private:
42  // Number of threads that have been initialized
43  std::atomic_uint m_nInitThreads;
44 
45 };
46 
47 #endif
ThreadInitTool::ThreadInitTool
ThreadInitTool(const std::string &, const std::string &, const IInterface *)
Definition: ThreadInitTool.cxx:10
ThreadInitTool::terminateThread
virtual void terminateThread() override
Definition: ThreadInitTool.cxx:33
ThreadInitTool
Definition: ThreadInitTool.h:30
ThreadInitTool::initThread
virtual void initThread() override
Definition: ThreadInitTool.cxx:20
AthAlgTool.h
ThreadInitTool::m_nInitThreads
std::atomic_uint m_nInitThreads
Definition: ThreadInitTool.h:43
ThreadInitTool::nInit
virtual unsigned int nInit() const override
Definition: ThreadInitTool.h:39