26
27 #include "runtime/os.hpp"
28
29 #include "gc/shenandoah/shenandoahLock.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/os.inline.hpp"
32 #include "runtime/thread.hpp"
33
34 ShenandoahSimpleLock::ShenandoahSimpleLock() {
35 assert(os::mutex_init_done(), "Too early!");
36 }
37
38 void ShenandoahSimpleLock::lock() {
39 _lock.lock();
40 }
41
42 void ShenandoahSimpleLock::unlock() {
43 _lock.unlock();
44 }
45
46 ShenandoahReentrantLock::ShenandoahReentrantLock() :
47 ShenandoahSimpleLock(), _owner(NULL), _count(0) {
48 assert(os::mutex_init_done(), "Too early!");
49 }
50
51 ShenandoahReentrantLock::~ShenandoahReentrantLock() {
52 assert(_count == 0, "Unbalance");
53 }
54
55 void ShenandoahReentrantLock::lock() {
56 Thread* const thread = Thread::current();
57 Thread* const owner = Atomic::load(&_owner);
58
59 if (owner != thread) {
60 ShenandoahSimpleLock::lock();
61 Atomic::store(&_owner, thread);
62 }
63
64 _count++;
65 }
66
67 void ShenandoahReentrantLock::unlock() {
68 assert(owned_by_self(), "Invalid owner");
69 assert(_count > 0, "Invalid count");
70
71 _count--;
72
73 if (_count == 0) {
74 Atomic::store(&_owner, (Thread*)NULL);
75 ShenandoahSimpleLock::unlock();
76 }
77 }
78
79 bool ShenandoahReentrantLock::owned_by_self() const {
80 Thread* const thread = Thread::current();
81 Thread* const owner = Atomic::load(&_owner);
82 return owner == thread;
83 }
|
26
27 #include "runtime/os.hpp"
28
29 #include "gc/shenandoah/shenandoahLock.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/os.inline.hpp"
32 #include "runtime/thread.hpp"
33
34 ShenandoahSimpleLock::ShenandoahSimpleLock() {
35 assert(os::mutex_init_done(), "Too early!");
36 }
37
38 void ShenandoahSimpleLock::lock() {
39 _lock.lock();
40 }
41
42 void ShenandoahSimpleLock::unlock() {
43 _lock.unlock();
44 }
45
46 bool ShenandoahSimpleLock::try_lock() {
47 return _lock.try_lock();
48 }
49
50 ShenandoahReentrantLock::ShenandoahReentrantLock() :
51 ShenandoahSimpleLock(), _owner(NULL), _count(0) {
52 assert(os::mutex_init_done(), "Too early!");
53 }
54
55 ShenandoahReentrantLock::~ShenandoahReentrantLock() {
56 assert(_count == 0, "Unbalance");
57 }
58
59 void ShenandoahReentrantLock::lock() {
60 Thread* const thread = Thread::current();
61 Thread* const owner = Atomic::load(&_owner);
62
63 if (owner != thread) {
64 ShenandoahSimpleLock::lock();
65 Atomic::store(&_owner, thread);
66 }
67
68 _count++;
69 }
70
71 bool ShenandoahReentrantLock::try_lock() {
72 Thread* const thread = Thread::current();
73 Thread* const owner = Atomic::load(&_owner);
74
75 if (owner != thread) {
76 if (!ShenandoahSimpleLock::try_lock()) {
77 return false;
78 }
79 Atomic::store(&_owner, thread);
80 }
81
82 _count++;
83 return true;
84 }
85
86 void ShenandoahReentrantLock::unlock() {
87 assert(owned_by_self(), "Invalid owner");
88 assert(_count > 0, "Invalid count");
89
90 _count--;
91
92 if (_count == 0) {
93 Atomic::store(&_owner, (Thread*)NULL);
94 ShenandoahSimpleLock::unlock();
95 }
96 }
97
98 bool ShenandoahReentrantLock::owned_by_self() const {
99 Thread* const thread = Thread::current();
100 Thread* const owner = Atomic::load(&_owner);
101 return owner == thread;
102 }
|