1 /* |
1 /* |
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
24 #ifndef SHARE_GC_Z_ZLOCK_INLINE_HPP |
24 #ifndef SHARE_GC_Z_ZLOCK_INLINE_HPP |
25 #define SHARE_GC_Z_ZLOCK_INLINE_HPP |
25 #define SHARE_GC_Z_ZLOCK_INLINE_HPP |
26 |
26 |
27 #include "gc/z/zLock.hpp" |
27 #include "gc/z/zLock.hpp" |
28 #include "runtime/atomic.hpp" |
28 #include "runtime/atomic.hpp" |
|
29 #include "runtime/os.inline.hpp" |
29 #include "runtime/thread.hpp" |
30 #include "runtime/thread.hpp" |
30 #include "utilities/debug.hpp" |
31 #include "utilities/debug.hpp" |
31 |
32 |
32 inline ZLock::ZLock() { |
|
33 pthread_mutex_init(&_lock, NULL); |
|
34 } |
|
35 |
|
36 inline ZLock::~ZLock() { |
|
37 pthread_mutex_destroy(&_lock); |
|
38 } |
|
39 |
|
40 inline void ZLock::lock() { |
33 inline void ZLock::lock() { |
41 pthread_mutex_lock(&_lock); |
34 _lock.lock(); |
42 } |
35 } |
43 |
36 |
44 inline bool ZLock::try_lock() { |
37 inline bool ZLock::try_lock() { |
45 return pthread_mutex_trylock(&_lock) == 0; |
38 return _lock.try_lock(); |
46 } |
39 } |
47 |
40 |
48 inline void ZLock::unlock() { |
41 inline void ZLock::unlock() { |
49 pthread_mutex_unlock(&_lock); |
42 _lock.unlock(); |
50 } |
43 } |
51 |
44 |
52 inline ZReentrantLock::ZReentrantLock() : |
45 inline ZReentrantLock::ZReentrantLock() : |
53 _lock(), |
46 _lock(), |
54 _owner(NULL), |
47 _owner(NULL), |