Logo ROOT   6.10/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 #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  static UInt_t fgNumber; //Referenced objects count
84 
85 public:
86  TProcessID();
87  virtual ~TProcessID();
88  void CheckInit();
89  virtual void Clear(Option_t *option="");
90  Int_t DecrementCount();
91  Int_t IncrementCount();
92  Int_t GetCount() const {return fCount;}
93  TObjArray *GetObjects() const {return fObjects;}
94  TObject *GetObjectWithID(UInt_t uid);
95  void PutObjectWithID(TObject *obj, UInt_t uid=0);
96  virtual void RecursiveRemove(TObject *obj);
97 
98  static TProcessID *AddProcessID();
99  static UInt_t AssignID(TObject *obj);
100  static void Cleanup();
101  static UInt_t GetNProcessIDs();
102  static TProcessID *GetPID();
103  static TObjArray *GetPIDs();
104  static TProcessID *GetProcessID(UShort_t pid);
105  static TProcessID *GetProcessWithUID(const TObject *obj);
106  static TProcessID *GetProcessWithUID(UInt_t uid,const void *obj);
107  static TProcessID *GetSessionProcessID();
108  static UInt_t GetObjectCount();
109  static Bool_t IsValid(TProcessID *pid);
110  static void SetObjectCount(UInt_t number);
111 
112  ClassDef(TProcessID,1) //Process Unique Identifier in time and space
113 };
114 
115 #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:92
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:297
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
TObjArray * GetObjects() const
Definition: TProcessID.h:93
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 UInt_t fgNumber
Definition: TProcessID.h:83
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