< prev index next >

src/hotspot/share/jfr/utilities/jfrRefCountPointer.hpp

Print this page




  75   bool valid() const {
  76     return _ptr != NULL;
  77   }
  78 
  79   const T & operator->() const {
  80     return *_ptr;
  81   }
  82 
  83   T& operator->() {
  84     return *const_cast<T*>(_ptr);
  85   }
  86 };
  87 
  88 class MultiThreadedRefCounter {
  89  private:
  90   mutable volatile int _refs;
  91  public:
  92   MultiThreadedRefCounter() : _refs(0) {}
  93 
  94   void inc() const {
  95     Atomic::add(1, &_refs);
  96   }
  97 
  98   bool dec() const {
  99     return 0 == Atomic::add((-1), &_refs);
 100   }
 101 
 102   int current() const {
 103    return _refs;
 104   }
 105 };
 106 
 107 template <typename T, typename RefCountImpl = MultiThreadedRefCounter>
 108 class RefCountPointer : public JfrCHeapObj {
 109   template <typename>
 110   friend class RefCountHandle;
 111   typedef RefCountHandle<RefCountPointer<T, RefCountImpl> > RefHandle;
 112  private:
 113   const T* _ptr;
 114   mutable RefCountImpl _refs;
 115 
 116   // disallow multiple copies
 117   RefCountPointer(const RefCountPointer<T, RefCountImpl>& rhs);
 118   void operator=(const RefCountPointer<T, RefCountImpl>& rhs);
 119 




  75   bool valid() const {
  76     return _ptr != NULL;
  77   }
  78 
  79   const T & operator->() const {
  80     return *_ptr;
  81   }
  82 
  83   T& operator->() {
  84     return *const_cast<T*>(_ptr);
  85   }
  86 };
  87 
  88 class MultiThreadedRefCounter {
  89  private:
  90   mutable volatile int _refs;
  91  public:
  92   MultiThreadedRefCounter() : _refs(0) {}
  93 
  94   void inc() const {
  95     Atomic::add(&_refs, 1);
  96   }
  97 
  98   bool dec() const {
  99     return 0 == Atomic::add(&_refs, (-1));
 100   }
 101 
 102   int current() const {
 103    return _refs;
 104   }
 105 };
 106 
 107 template <typename T, typename RefCountImpl = MultiThreadedRefCounter>
 108 class RefCountPointer : public JfrCHeapObj {
 109   template <typename>
 110   friend class RefCountHandle;
 111   typedef RefCountHandle<RefCountPointer<T, RefCountImpl> > RefHandle;
 112  private:
 113   const T* _ptr;
 114   mutable RefCountImpl _refs;
 115 
 116   // disallow multiple copies
 117   RefCountPointer(const RefCountPointer<T, RefCountImpl>& rhs);
 118   void operator=(const RefCountPointer<T, RefCountImpl>& rhs);
 119 


< prev index next >