Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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) = delete;
78 TProcessID& operator=(const TProcessID &ref) = delete;
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 void Clear(Option_t *option="") override;
98 Int_t GetCount() const {return fCount;}
99 TObjArray *GetObjects() const {return fObjects;}
101 void PutObjectWithID(TObject *obj, UInt_t uid = 0);
102 void RecursiveRemove(TObject *obj) override;
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 ClassDefOverride(TProcessID,1) //Process Unique Identifier in time and space
119};
120
121#endif
bool Bool_t
Definition RtypesCore.h:63
unsigned short UShort_t
Definition RtypesCore.h:40
unsigned int UInt_t
Definition RtypesCore.h:46
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t option
Helper class to manage atomic pointers.
Definition TProcessID.h:48
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:31
Mother of all ROOT objects.
Definition TObject.h:41
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.
void Clear(Option_t *option="") override
delete the TObjArray pointing to referenced objects this function is called by TFile::Close("R")
void CheckInit()
Initialize fObjects.
static void Cleanup()
static function (called by TROOT destructor) to delete all TProcessIDs
static Bool_t IsValid(TProcessID *pid)
static function. return kTRUE if pid is a valid TProcessID
static UInt_t GetNProcessIDs()
Return the (static) number of process IDs.
static TObjArray * fgPIDs
Definition TProcessID.h:86
static TObjArray * GetPIDs()
static: returns array of TProcessIDs
static UInt_t AssignID(TObject *obj)
static function returning the ID assigned to obj If the object is not yet referenced,...
static TProcessID * GetSessionProcessID()
static function returning the pointer to the session TProcessID
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...
void RecursiveRemove(TObject *obj) override
called by the object destructor remove reference to obj from the current table if it is referenced
virtual ~TProcessID()
Destructor.
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.
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...
static TProcessID * GetProcessID(UShort_t pid)
static function returning a pointer to TProcessID number pid in fgPIDs
TProcessID & operator=(const TProcessID &ref)=delete
Int_t DecrementCount()
The reference fCount is used to delete the TProcessID in the TFile destructor when fCount = 0.
TObjArray * GetObjects() const
Definition TProcessID.h:99
TObject * GetObjectWithID(UInt_t uid)
returns the TObject with unique identifier uid in the table of objects
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
TProcessID(const TProcessID &ref)=delete
static TProcessID * fgPID
Spin lock for initialization of fObjects.
Definition TProcessID.h:85
Int_t GetCount() const
Definition TProcessID.h:98
TProcessID()
Default constructor.
static UInt_t GetObjectCount()
Return the current referenced object count fgNumber is incremented every time a new object is referen...
static TProcessID * GetPID()
static: returns pointer to current TProcessID
static void SetObjectCount(UInt_t number)
static function to set the current referenced object count fgNumber is incremented every time a new o...
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...