Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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()) {
53  if (ROOT::Internal::TPoolManager::GetPoolSize() == 0) {
54  TThread::Initialize();
55  }
56  R__GetPoolManagerMT() = ROOT::Internal::GetPoolManager(numthreads);
57  GetImplicitMTFlag() = true;
58  } else {
59  ::Warning("ROOT_TImplicitMT_EnableImplicitMT", "Implicit multi-threading is already enabled");
60  }
61 };
62 
63 extern "C" void ROOT_TImplicitMT_DisableImplicitMT()
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 
73 extern "C" UInt_t ROOT_TImplicitMT_GetImplicitMTPoolSize()
74 {
75  return ROOT::Internal::TPoolManager::GetPoolSize();
76 };
77 
78 
79 extern "C" void ROOT_TImplicitMT_EnableParBranchProcessing()
80 {
81  ++GetParBranchProcessingCount();
82 };
83 
84 extern "C" void ROOT_TImplicitMT_DisableParBranchProcessing()
85 {
86  --GetParBranchProcessingCount();
87 };
88 
89 extern "C" bool ROOT_TImplicitMT_IsParBranchProcessingEnabled()
90 {
91  return GetParBranchProcessingCount() > 0;
92 };
93 
94 extern "C" void ROOT_TImplicitMT_EnableParTreeProcessing()
95 {
96  ++GetParTreeProcessingCount();
97 };
98 
99 extern "C" void ROOT_TImplicitMT_DisableParTreeProcessing()
100 {
101  --GetParTreeProcessingCount();
102 };
103 
104 extern "C" bool ROOT_TImplicitMT_IsParTreeProcessingEnabled()
105 {
106  return GetParTreeProcessingCount() > 0;
107 };