Logo ROOT   6.07/09
Reference Guide
TProcessID.h
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Rene Brun 28/09/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 #ifndef ROOT_TProcessID
13 #define ROOT_TProcessID
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TProcessID //
19 // //
20 // Process Identifier object //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 
25 #ifndef ROOT_TNamed
26 #include "TNamed.h"
27 #endif
28 #ifndef ROOT_TObjArray
29 #include "TObjArray.h"
30 #endif
31 
32 #include <atomic>
33 #include <type_traits>
34 
35 class TExMap;
36 
37 namespace ROOT {
38  namespace Internal {
39  /**
40  * \class ROOT::Internal::TAtomicPointer
41  * \brief Helper class to manage atomic pointers.
42  * \tparam T Pointer type to be made atomic
43  *
44  * Helper class to manage atomic pointers. The class enforces that the templated type
45  * is a pointer.
46  */
47  template <typename T> class TAtomicPointer {
48  private:
49  std::atomic<T> fAtomic;
50 
51  public:
52  TAtomicPointer() : fAtomic(nullptr)
53  {
54  static_assert(std::is_pointer<T>::value, "Only pointer types supported");
55  }
56 
57  ~TAtomicPointer() { delete fAtomic.load(); }
58 
59  T operator->() const { return fAtomic; }
60 
61  operator T() const { return fAtomic; }
62 
63  T operator=(const T& t)
64  {
65  fAtomic = t;
66  return t;
67  }
68  };
69  } // End of namespace Internal
70 } // End of namespace ROOT
71 
72 
73 class TProcessID : public TNamed {
74 
75 private:
76  TProcessID(const TProcessID &ref); // TProcessID are not copiable.
77  TProcessID& operator=(const TProcessID &ref); // TProcessID are not copiable.
78 
79 protected:
80  std::atomic_int fCount; //!Reference count to this object (from TFile)
81  ROOT::Internal::TAtomicPointer<TObjArray*> fObjects; //!Array pointing to the referenced objects
82  std::atomic_flag fLock; //!Spin lock for initialization of fObjects
83 
84  static TProcessID *fgPID; //Pointer to current session ProcessID
85  static TObjArray *fgPIDs; //Table of ProcessIDs
86  static TExMap *fgObjPIDs; //Table pointer to pids
87  static UInt_t fgNumber; //Referenced objects count
88 
89 public:
90  TProcessID();
91  virtual ~TProcessID();
92  void CheckInit();
93  virtual void Clear(Option_t *option="");
94  Int_t DecrementCount();
95  Int_t IncrementCount();
96  Int_t GetCount() const {return fCount;}
97  TObjArray *GetObjects() const {return fObjects;}
98  TObject *GetObjectWithID(UInt_t uid);
99  void PutObjectWithID(TObject *obj, UInt_t uid=0);
100  virtual void RecursiveRemove(TObject *obj);
101 
102  static TProcessID *AddProcessID();
103  static UInt_t AssignID(TObject *obj);
104  static void Cleanup();
105  static UInt_t GetNProcessIDs();
106  static TProcessID *GetPID();
107  static TObjArray *GetPIDs();
108  static TProcessID *GetProcessID(UShort_t pid);
109  static TProcessID *GetProcessWithUID(const TObject *obj);
110  static TProcessID *GetProcessWithUID(UInt_t uid,const void *obj);
111  static TProcessID *GetSessionProcessID();
112  static UInt_t GetObjectCount();
113  static Bool_t IsValid(TProcessID *pid);
114  static void SetObjectCount(UInt_t number);
115 
116  ClassDef(TProcessID,1) //Process Unique Identifier in time and space
117 };
118 
119 #endif
ROOT::Internal::TAtomicPointer< TObjArray * > fObjects
Reference count to this object (from TFile)
Definition: TProcessID.h:81
An array of TObjects.
Definition: TObjArray.h:39
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
const char Option_t
Definition: RtypesCore.h:62
double T(double x)
Definition: ChebyshevPol.h:34
unsigned short UShort_t
Definition: RtypesCore.h:36
std::atomic< T > fAtomic
Definition: TProcessID.h:49
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
static TObjArray * fgPIDs
Definition: TProcessID.h:85
#define ClassDef(name, id)
Definition: Rtypes.h:254
static TProcessID * fgPID
Spin lock for initialization of fObjects.
Definition: TProcessID.h:84
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:73
Helper class to manage atomic pointers.
Definition: TProcessID.h:47
TObjArray * GetObjects() const
Definition: TProcessID.h:97
std::atomic_flag fLock
Array pointing to the referenced objects.
Definition: TProcessID.h:82
unsigned int UInt_t
Definition: RtypesCore.h:42
static UInt_t fgNumber
Definition: TProcessID.h:87
static TExMap * fgObjPIDs
Definition: TProcessID.h:86
std::atomic_int fCount
Definition: TProcessID.h:80
Mother of all ROOT objects.
Definition: TObject.h:44
Int_t GetCount() const
Definition: TProcessID.h:96
#define nullptr
Definition: Rtypes.h:87
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:35