< prev index next >

src/hotspot/share/gc/z/zLock.inline.hpp

Print this page




  36 
  37 inline bool ZLock::try_lock() {
  38   return _lock.try_lock();
  39 }
  40 
  41 inline void ZLock::unlock() {
  42   _lock.unlock();
  43 }
  44 
  45 inline ZReentrantLock::ZReentrantLock() :
  46     _lock(),
  47     _owner(NULL),
  48     _count(0) {}
  49 
  50 inline void ZReentrantLock::lock() {
  51   Thread* const thread = Thread::current();
  52   Thread* const owner = Atomic::load(&_owner);
  53 
  54   if (owner != thread) {
  55     _lock.lock();
  56     Atomic::store(thread, &_owner);
  57   }
  58 
  59   _count++;
  60 }
  61 
  62 inline void ZReentrantLock::unlock() {
  63   assert(is_owned(), "Invalid owner");
  64   assert(_count > 0, "Invalid count");
  65 
  66   _count--;
  67 
  68   if (_count == 0) {
  69     Atomic::store((Thread*)NULL, &_owner);
  70     _lock.unlock();
  71   }
  72 }
  73 
  74 inline bool ZReentrantLock::is_owned() const {
  75   Thread* const thread = Thread::current();
  76   Thread* const owner = Atomic::load(&_owner);
  77   return owner == thread;
  78 }
  79 
  80 template <typename T>
  81 inline ZLocker<T>::ZLocker(T* lock) :
  82     _lock(lock) {
  83   if (_lock != NULL) {
  84     _lock->lock();
  85   }
  86 }
  87 
  88 template <typename T>
  89 inline ZLocker<T>::~ZLocker() {


  36 
  37 inline bool ZLock::try_lock() {
  38   return _lock.try_lock();
  39 }
  40 
  41 inline void ZLock::unlock() {
  42   _lock.unlock();
  43 }
  44 
  45 inline ZReentrantLock::ZReentrantLock() :
  46     _lock(),
  47     _owner(NULL),
  48     _count(0) {}
  49 
  50 inline void ZReentrantLock::lock() {
  51   Thread* const thread = Thread::current();
  52   Thread* const owner = Atomic::load(&_owner);
  53 
  54   if (owner != thread) {
  55     _lock.lock();
  56     Atomic::store(&_owner, thread);
  57   }
  58 
  59   _count++;
  60 }
  61 
  62 inline void ZReentrantLock::unlock() {
  63   assert(is_owned(), "Invalid owner");
  64   assert(_count > 0, "Invalid count");
  65 
  66   _count--;
  67 
  68   if (_count == 0) {
  69     Atomic::store(&_owner, (Thread*)NULL);
  70     _lock.unlock();
  71   }
  72 }
  73 
  74 inline bool ZReentrantLock::is_owned() const {
  75   Thread* const thread = Thread::current();
  76   Thread* const owner = Atomic::load(&_owner);
  77   return owner == thread;
  78 }
  79 
  80 template <typename T>
  81 inline ZLocker<T>::ZLocker(T* lock) :
  82     _lock(lock) {
  83   if (_lock != NULL) {
  84     _lock->lock();
  85   }
  86 }
  87 
  88 template <typename T>
  89 inline ZLocker<T>::~ZLocker() {
< prev index next >