7 *
8 * This code is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 */
22
23 #ifndef SHARE_GC_Z_ZLOCK_INLINE_HPP
24 #define SHARE_GC_Z_ZLOCK_INLINE_HPP
25
26 #include "gc/z/zLock.hpp"
27
28 inline ZLock::ZLock() {
29 pthread_mutex_init(&_lock, NULL);
30 }
31
32 inline void ZLock::lock() {
33 pthread_mutex_lock(&_lock);
34 }
35
36 inline bool ZLock::try_lock() {
37 return pthread_mutex_trylock(&_lock) == 0;
38 }
39
40 inline void ZLock::unlock() {
41 pthread_mutex_unlock(&_lock);
42 }
43
44 inline ZLocker::ZLocker(ZLock* lock) :
45 _lock(lock) {
46 _lock->lock();
47 }
48
49 inline ZLocker::~ZLocker() {
50 _lock->unlock();
51 }
52
53 #endif // SHARE_GC_Z_ZLOCK_INLINE_HPP
|
7 *
8 * This code is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 */
22
23 #ifndef SHARE_GC_Z_ZLOCK_INLINE_HPP
24 #define SHARE_GC_Z_ZLOCK_INLINE_HPP
25
26 #include "gc/z/zLock.hpp"
27 #include "runtime/thread.hpp"
28
29 inline ZLock::ZLock() {
30 pthread_mutex_init(&_lock, NULL);
31 }
32
33 inline ZLocker::ZLocker(ZLock* lock) :
34 _lock(lock) {
35 _lock->lock();
36 }
37
38 inline ZLocker::~ZLocker() {
39 _lock->unlock();
40 }
41
42 inline ZReentrantLock::ZReentrantLock() :
43 ZLock(),
44 _owner(NULL) { }
45
46 inline bool ZReentrantLock::is_owned() const {
47 return _owner == Thread::current();
48 }
49
50 inline bool ZReentrantLock::reentrant_lock() {
51 if (is_owned()) {
52 return false;
53 }
54 lock();
55 return true;
56 }
57
58 #endif // SHARE_GC_Z_ZLOCK_INLINE_HPP
|