Logo ROOT  
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
27#ifdef R__LESS_INCLUDES
28class TObjArray;
29#else
30#include "TObjArray.h"
31#endif
32
33#include <atomic>
34#include <type_traits>
35
36class TExMap;
37
38namespace ROOT {
39 namespace Internal {
40 /**
41 * \class ROOT::Internal::TAtomicPointer
42 * \brief Helper class to manage atomic pointers.
43 * \tparam T Pointer type to be made atomic
44 *
45 * Helper class to manage atomic pointers. The class enforces that the templated type
46 * is a pointer.
47 */
48 template <typename T> class TAtomicPointer {
49 private:
50 std::atomic<T> fAtomic;
51
52 public:
54 {
55 static_assert(std::is_pointer<T>::value, "Only pointer types supported");
56 }
57
58 ~TAtomicPointer() { delete fAtomic.load(); }
59
60 T operator->() const { return fAtomic; }
61
62 operator T() const { return fAtomic; }
63
64 T operator=(const T& t)
65 {
66 fAtomic = t;
67 return t;
68 }
69 };
70 } // End of namespace Internal
71} // End of namespace ROOT
72
73
74class TProcessID : public TNamed {
75
76private:
77 TProcessID(const TProcessID &ref); // TProcessID are not copiable.
78 TProcessID& operator=(const TProcessID &ref); // TProcessID are not copiable.
79
80protected:
81 std::atomic_int fCount; //!Reference count to this object (from TFile)
82 ROOT::Internal::TAtomicPointer<TObjArray*> fObjects; //!Array pointing to the referenced objects
83 std::atomic_flag fLock; //!Spin lock for initialization of fObjects
84
85 static TProcessID *fgPID; //Pointer to current session ProcessID
86 static TObjArray *fgPIDs; //Table of ProcessIDs
87 static TExMap *fgObjPIDs; //Table pointer to pids
88
89 static std::atomic_uint fgNumber; //Referenced objects count
90
91public:
92 TProcessID();
93 virtual ~TProcessID();
94 void CheckInit();
95 virtual void Clear(Option_t *option="");
98 Int_t GetCount() const {return fCount;}
99 TObjArray *GetObjects() const {return fObjects;}
101 void PutObjectWithID(TObject *obj, UInt_t uid=0);
102 virtual void RecursiveRemove(TObject *obj);
103
104 static TProcessID *AddProcessID();
105 static UInt_t AssignID(TObject *obj);
106 static void Cleanup();
107 static UInt_t GetNProcessIDs();
108 static TProcessID *GetPID();
109 static TObjArray *GetPIDs();
110 static TProcessID *GetProcessID(UShort_t pid);
111 static TProcessID *GetProcessWithUID(const TObject *obj);
112 static TProcessID *GetProcessWithUID(UInt_t uid,const void *obj);
114 static UInt_t GetObjectCount();
115 static Bool_t IsValid(TProcessID *pid);
116 static void SetObjectCount(UInt_t number);
117
118 ClassDef(TProcessID,1) //Process Unique Identifier in time and space
119};
120
121#endif
unsigned short UShort_t
Definition: RtypesCore.h:40
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
bool Bool_t
Definition: RtypesCore.h:63
const char Option_t
Definition: RtypesCore.h:66
#define ClassDef(name, id)
Definition: Rtypes.h:325
Helper class to manage atomic pointers.
Definition: TProcessID.h:48
std::atomic< T > fAtomic
Definition: TProcessID.h:50
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:33
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
An array of TObjects.
Definition: TObjArray.h:37
Mother of all ROOT objects.
Definition: TObject.h:37
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:74
Int_t IncrementCount()
Increase the reference count to this object.
Definition: TProcessID.cxx:313
void CheckInit()
Initialize fObjects.
Definition: TProcessID.cxx:192
static void Cleanup()
static function (called by TROOT destructor) to delete all TProcessIDs
Definition: TProcessID.cxx:204
static Bool_t IsValid(TProcessID *pid)
static function. return kTRUE if pid is a valid TProcessID
Definition: TProcessID.cxx:360
static UInt_t GetNProcessIDs()
Return the (static) number of process IDs.
Definition: TProcessID.cxx:256
virtual void Clear(Option_t *option="")
delete the TObjArray pointing to referenced objects this function is called by TFile::Close("R")
Definition: TProcessID.cxx:218
static TObjArray * fgPIDs
Definition: TProcessID.h:86
static TObjArray * GetPIDs()
static: returns array of TProcessIDs
Definition: TProcessID.cxx:351
TProcessID & operator=(const TProcessID &ref)
static UInt_t AssignID(TObject *obj)
static function returning the ID assigned to obj If the object is not yet referenced,...
Definition: TProcessID.cxx:155
virtual void RecursiveRemove(TObject *obj)
called by the object destructor remove reference to obj from the current table if it is referenced
Definition: TProcessID.cxx:412
static TProcessID * GetSessionProcessID()
static function returning the pointer to the session TProcessID
Definition: TProcessID.cxx:305
void PutObjectWithID(TObject *obj, UInt_t uid=0)
stores the object at the uid th slot in the table of objects The object uniqued is set as well as its...
Definition: TProcessID.cxx:383
virtual ~TProcessID()
Destructor.
Definition: TProcessID.cxx:95
TProcessID(const TProcessID &ref)
static TExMap * fgObjPIDs
Definition: TProcessID.h:87
std::atomic_int fCount
Definition: TProcessID.h:81
static TProcessID * AddProcessID()
Static function to add a new TProcessID to the list of PIDs.
Definition: TProcessID.cxx:116
std::atomic_flag fLock
Array pointing to the referenced objects.
Definition: TProcessID.h:83
static TProcessID * GetProcessWithUID(const TObject *obj)
static function returning a pointer to TProcessID with its pid encoded in the highest byte of obj->Ge...
Definition: TProcessID.cxx:297
static TProcessID * GetProcessID(UShort_t pid)
static function returning a pointer to TProcessID number pid in fgPIDs
Definition: TProcessID.cxx:248
Int_t DecrementCount()
The reference fCount is used to delete the TProcessID in the TFile destructor when fCount = 0.
Definition: TProcessID.cxx:238
TObjArray * GetObjects() const
Definition: TProcessID.h:99
TObject * GetObjectWithID(UInt_t uid)
returns the TObject with unique identifier uid in the table of objects
Definition: TProcessID.cxx:332
static std::atomic_uint fgNumber
Definition: TProcessID.h:89
ROOT::Internal::TAtomicPointer< TObjArray * > fObjects
Reference count to this object (from TFile)
Definition: TProcessID.h:82
static TProcessID * fgPID
Spin lock for initialization of fObjects.
Definition: TProcessID.h:85
Int_t GetCount() const
Definition: TProcessID.h:98
TProcessID()
Default constructor.
Definition: TProcessID.cxx:77
static UInt_t GetObjectCount()
Return the current referenced object count fgNumber is incremented every time a new object is referen...
Definition: TProcessID.cxx:324
static TProcessID * GetPID()
static: returns pointer to current TProcessID
Definition: TProcessID.cxx:343
static void SetObjectCount(UInt_t number)
static function to set the current referenced object count fgNumber is incremented every time a new o...
Definition: TProcessID.cxx:436
double T(double x)
Definition: ChebyshevPol.h:34
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...