Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:20

0001 // @(#)root/cont:$Id$
0002 // Author: Rene Brun   28/09/2001
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TProcessID
0013 #define ROOT_TProcessID
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TProcessID                                                           //
0019 //                                                                      //
0020 // Process Identifier object                                            //
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       * \class ROOT::Internal::TAtomicPointer
0042       * \brief Helper class to manage atomic pointers.
0043       * \tparam T Pointer type to be made atomic
0044       *
0045       * Helper class to manage atomic pointers. The class enforces that the templated type
0046       * is a pointer.
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    } // End of namespace Internal
0071 } // End of namespace ROOT
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;                           //!Reference count to this object (from TFile)
0082    ROOT::Internal::TAtomicPointer<TObjArray*> fObjects; //!Array pointing to the referenced objects
0083    std::atomic_flag   fLock;                            //!Spin lock for initialization of fObjects
0084 
0085    static TProcessID *fgPID;      //Pointer to current session ProcessID
0086    static TObjArray  *fgPIDs;     //Table of ProcessIDs
0087    static TExMap     *fgObjPIDs;  //Table pointer to pids
0088 
0089    static std::atomic_uint      fgNumber;   //Referenced objects count
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)  //Process Unique Identifier in time and space
0119 };
0120 
0121 #endif