File indexing completed on 2025-01-18 10:12:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TProcessID
0013 #define ROOT_TProcessID
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #include "TNamed.h"
0026
0027 #ifdef R__LESS_INCLUDES
0028 class TObjArray;
0029 #else
0030 #include "TObjArray.h"
0031 #endif
0032
0033 #include <atomic>
0034 #include <type_traits>
0035
0036 class TExMap;
0037
0038 namespace ROOT {
0039 namespace Internal {
0040
0041
0042
0043
0044
0045
0046
0047
0048 template <typename T> class TAtomicPointer {
0049 private:
0050 std::atomic<T> fAtomic;
0051
0052 public:
0053 TAtomicPointer() : fAtomic(nullptr)
0054 {
0055 static_assert(std::is_pointer<T>::value, "Only pointer types supported");
0056 }
0057
0058 ~TAtomicPointer() { delete fAtomic.load(); }
0059
0060 T operator->() const { return fAtomic; }
0061
0062 operator T() const { return fAtomic; }
0063
0064 T operator=(const T& t)
0065 {
0066 fAtomic = t;
0067 return t;
0068 }
0069 };
0070 }
0071 }
0072
0073
0074 class TProcessID : public TNamed {
0075
0076 private:
0077 TProcessID(const TProcessID &ref) = delete;
0078 TProcessID& operator=(const TProcessID &ref) = delete;
0079
0080 protected:
0081 std::atomic_int fCount;
0082 ROOT::Internal::TAtomicPointer<TObjArray*> fObjects;
0083 std::atomic_flag fLock;
0084
0085 static TProcessID *fgPID;
0086 static TObjArray *fgPIDs;
0087 static TExMap *fgObjPIDs;
0088
0089 static std::atomic_uint fgNumber;
0090
0091 public:
0092 TProcessID();
0093 virtual ~TProcessID();
0094 void CheckInit();
0095 void Clear(Option_t *option="") override;
0096 Int_t DecrementCount();
0097 Int_t IncrementCount();
0098 Int_t GetCount() const {return fCount;}
0099 TObjArray *GetObjects() const {return fObjects;}
0100 TObject *GetObjectWithID(UInt_t uid);
0101 void PutObjectWithID(TObject *obj, UInt_t uid = 0);
0102 void RecursiveRemove(TObject *obj) override;
0103
0104 static TProcessID *AddProcessID();
0105 static UInt_t AssignID(TObject *obj);
0106 static void Cleanup();
0107 static UInt_t GetNProcessIDs();
0108 static TProcessID *GetPID();
0109 static TObjArray *GetPIDs();
0110 static TProcessID *GetProcessID(UShort_t pid);
0111 static TProcessID *GetProcessWithUID(const TObject *obj);
0112 static TProcessID *GetProcessWithUID(UInt_t uid,const void *obj);
0113 static TProcessID *GetSessionProcessID();
0114 static UInt_t GetObjectCount();
0115 static Bool_t IsValid(TProcessID *pid);
0116 static void SetObjectCount(UInt_t number);
0117
0118 ClassDefOverride(TProcessID,1)
0119 };
0120
0121 #endif