1/*
2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#ifndef OS_POSIX_OS_POSIX_INLINE_HPP
26#define OS_POSIX_OS_POSIX_INLINE_HPP
27
28#include "runtime/os.hpp"
29
30#ifdef SUPPORTS_CLOCK_MONOTONIC
31
32// Exported clock functionality
33
34inline bool os::Posix::supports_monotonic_clock() {
35 return _clock_gettime != NULL;
36}
37
38inline int os::Posix::clock_gettime(clockid_t clock_id, struct timespec *tp) {
39 return _clock_gettime != NULL ? _clock_gettime(clock_id, tp) : -1;
40}
41
42inline int os::Posix::clock_getres(clockid_t clock_id, struct timespec *tp) {
43 return _clock_getres != NULL ? _clock_getres(clock_id, tp) : -1;
44}
45
46#endif // SUPPORTS_CLOCK_MONOTONIC
47
48#ifndef SOLARIS
49
50// Platform Monitor implementation
51
52inline void os::PlatformMonitor::lock() {
53 int status = pthread_mutex_lock(mutex());
54 assert_status(status == 0, status, "mutex_lock");
55}
56
57inline void os::PlatformMonitor::unlock() {
58 int status = pthread_mutex_unlock(mutex());
59 assert_status(status == 0, status, "mutex_unlock");
60}
61
62inline bool os::PlatformMonitor::try_lock() {
63 int status = pthread_mutex_trylock(mutex());
64 assert_status(status == 0 || status == EBUSY, status, "mutex_trylock");
65 return status == 0;
66}
67
68inline void os::PlatformMonitor::notify() {
69 int status = pthread_cond_signal(cond());
70 assert_status(status == 0, status, "cond_signal");
71}
72
73inline void os::PlatformMonitor::notify_all() {
74 int status = pthread_cond_broadcast(cond());
75 assert_status(status == 0, status, "cond_broadcast");
76}
77
78#endif // !SOLARIS
79
80#endif // OS_POSIX_OS_POSIX_INLINE_HPP
81