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