Logo ROOT   6.10/09
Reference Guide
TImplicitMT.cxx
Go to the documentation of this file.
1 // @(#)root/thread:$Id$
2 // // Author: Enric Tejedor Saavedra 03/12/15
3 //
4 /*************************************************************************
5  * Copyright (C) 1995-2015, 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 // TImplicitMT //
15 // //
16 // This file implements the methods to enable, disable and check the //
17 // status of the global implicit multi-threading in ROOT. //
18 // //
19 //////////////////////////////////////////////////////////////////////////
20 
21 #include "TError.h"
22 #include "TThread.h"
23 #include "ROOT/TPoolManager.hxx"
24 #include <atomic>
25 
26 static std::shared_ptr<ROOT::Internal::TPoolManager> &R__GetPoolManagerMT()
27 {
28  static std::shared_ptr<ROOT::Internal::TPoolManager> schedMT;
29  return schedMT;
30 }
31 
32 static bool &GetImplicitMTFlag()
33 {
34  static bool enabled = false;
35  return enabled;
36 }
37 
38 static std::atomic_int &GetParBranchProcessingCount()
39 {
40  static std::atomic_int count(0);
41  return count;
42 }
43 
44 static std::atomic_int &GetParTreeProcessingCount()
45 {
46  static std::atomic_int count(0);
47  return count;
48 }
49 
50 extern "C" void ROOT_TImplicitMT_EnableImplicitMT(UInt_t numthreads)
51 {
52  if (!GetImplicitMTFlag()) {
55  }
57  GetImplicitMTFlag() = true;
58  } else {
59  ::Warning("ROOT_TImplicitMT_EnableImplicitMT", "Implicit multi-threading is already enabled");
60  }
61 };
62 
64 {
65  if (GetImplicitMTFlag()) {
66  GetImplicitMTFlag() = false;
67  R__GetPoolManagerMT().reset();
68  } else {
69  ::Warning("ROOT_TImplicitMT_DisableImplicitMT", "Implicit multi-threading is already disabled");
70  }
71 };
72 
74 {
75  return GetImplicitMTFlag();
76 };
77 
79 {
81 };
82 
83 
85 {
87 };
88 
90 {
92 };
93 
95 {
96  return GetParBranchProcessingCount() > 0;
97 };
98 
100 {
102 };
103 
105 {
107 };
108 
110 {
111  return GetParTreeProcessingCount() > 0;
112 };
void ROOT_TImplicitMT_DisableParTreeProcessing()
std::shared_ptr< TPoolManager > GetPoolManager(UInt_t nThreads=0)
Get a shared pointer to the manager.
static void Initialize()
Initialize the Thread package.
Definition: TThread.cxx:296
static bool & GetImplicitMTFlag()
Definition: TImplicitMT.cxx:32
bool ROOT_TImplicitMT_IsParBranchProcessingEnabled()
Definition: TImplicitMT.cxx:94
void ROOT_TImplicitMT_EnableParTreeProcessing()
Definition: TImplicitMT.cxx:99
static std::atomic_int & GetParBranchProcessingCount()
Definition: TImplicitMT.cxx:38
bool ROOT_TImplicitMT_IsImplicitMTEnabled()
Definition: TImplicitMT.cxx:73
static UInt_t GetPoolSize()
Returns the number of threads running when the scheduler has been instantiated within ROOT...
static std::atomic_int & GetParTreeProcessingCount()
Definition: TImplicitMT.cxx:44
unsigned int UInt_t
Definition: RtypesCore.h:42
void Warning(const char *location, const char *msgfmt,...)
void ROOT_TImplicitMT_DisableImplicitMT()
Definition: TImplicitMT.cxx:63
static std::shared_ptr< ROOT::Internal::TPoolManager > & R__GetPoolManagerMT()
Definition: TImplicitMT.cxx:26
bool ROOT_TImplicitMT_IsParTreeProcessingEnabled()
void ROOT_TImplicitMT_DisableParBranchProcessing()
Definition: TImplicitMT.cxx:89
UInt_t ROOT_TImplicitMT_GetImplicitMTPoolSize()
Definition: TImplicitMT.cxx:78
void ROOT_TImplicitMT_EnableParBranchProcessing()
Definition: TImplicitMT.cxx:84
void ROOT_TImplicitMT_EnableImplicitMT(UInt_t numthreads)
Definition: TImplicitMT.cxx:50