Logo ROOT   6.18/05
Reference Guide
TPoolManager.hxx
Go to the documentation of this file.
1// @(#)root/thread:$Id$
2// Author: Xavier Valls January 2017
3
4/*************************************************************************
5 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TPoolManager //
15// //
16// //
17// //
18// //
19//////////////////////////////////////////////////////////////////////////
20
21
22#ifndef ROOT_TPoolManager
23#define ROOT_TPoolManager
24
25#include "RConfigure.h"
26#include "Rtypes.h"
27
28// exclude in case ROOT does not have IMT support
29#ifndef R__USE_IMT
30// No need to error out for dictionaries.
31# if !defined(__ROOTCLING__) && !defined(G__DICTIONARY)
32# error "Cannot use ROOT::TPoolManager without defining R__USE_IMT."
33# endif
34#else
35
36#include<memory>
37
38namespace tbb {
39 class task_scheduler_init;
40}
41
42namespace ROOT {
43 namespace Internal {
44 /**
45 \class ROOT::TPoolManager
46 \ingroup TPoolManager
47 \brief A manager for the scheduler behind ROOT multithreading operations.
48
49 A manager for the multithreading scheduler that solves undefined behaviours and interferences between
50 classes and functions that made direct use of the scheduler, such as EnableImplicitMT() ot TThreadExecutor.
51 */
52
54 public:
55 friend std::shared_ptr<TPoolManager> GetPoolManager(UInt_t nThreads);
56 /// Returns the number of threads running when the scheduler has been instantiated within ROOT.
57 static UInt_t GetPoolSize();
58 /// Terminates the scheduler instantiated within ROOT.
60 private:
61 ///Initializes the scheduler within ROOT. If the scheduler has already been initialized by the
62 /// user before invoking the constructor it won't change its behaviour and it won't terminate it,
63 /// but it will still keep record of the number of threads passed as a parameter.
64 TPoolManager(UInt_t nThreads = 0);
66 bool mustDelete = true;
67 tbb::task_scheduler_init *fSched = nullptr;
68 };
69 /// Get a shared pointer to the manager. Initialize the manager with nThreads if not active. If active,
70 /// the number of threads, even if specified otherwise, will remain the same.
71 ///
72 /// The number of threads will be able to change calling the factory function again after the last
73 /// remaining shared_ptr owning the object is destroyed or reasigned, which will trigger the destructor of the manager.
74 std::shared_ptr<TPoolManager> GetPoolManager(UInt_t nThreads = 0);
75 }
76}
77
78#endif // R__USE_IMT
79
80#endif
unsigned int UInt_t
Definition: RtypesCore.h:42
TPoolManager(UInt_t nThreads=0)
Initializes the scheduler within ROOT.
friend std::shared_ptr< TPoolManager > GetPoolManager(UInt_t nThreads)
Get a shared pointer to the manager.
tbb::task_scheduler_init * fSched
~TPoolManager()
Terminates the scheduler instantiated within ROOT.
static UInt_t GetPoolSize()
Returns the number of threads running when the scheduler has been instantiated within ROOT.
std::shared_ptr< TPoolManager > GetPoolManager(UInt_t nThreads=0)
Get a shared pointer to the manager.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21