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 *
28 #include "runtime/os.hpp"
29
30 #ifdef SUPPORTS_CLOCK_MONOTONIC
31
32 // Exported clock functionality
33
34 inline bool os::Posix::supports_monotonic_clock() {
35 return _clock_gettime != NULL;
36 }
37
38 inline 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
42 inline 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 Mutex/Monitor implementation
51
52 inline void os::PlatformMutex::lock() {
53 int status = pthread_mutex_lock(mutex());
54 assert_status(status == 0, status, "mutex_lock");
55 }
56
57 inline void os::PlatformMutex::unlock() {
58 int status = pthread_mutex_unlock(mutex());
59 assert_status(status == 0, status, "mutex_unlock");
60 }
61
62 inline bool os::PlatformMutex::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
68 inline void os::PlatformMonitor::notify() {
69 int status = pthread_cond_signal(cond());
70 assert_status(status == 0, status, "cond_signal");
71 }
72
73 inline 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
|
1 /*
2 * Copyright (c) 2019, 2020, 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 *
28 #include "runtime/os.hpp"
29
30 #ifdef SUPPORTS_CLOCK_MONOTONIC
31
32 // Exported clock functionality
33
34 inline bool os::Posix::supports_monotonic_clock() {
35 return _clock_gettime != NULL;
36 }
37
38 inline 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
42 inline 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 // Platform Mutex/Monitor implementation
49
50 inline void os::PlatformMutex::lock() {
51 int status = pthread_mutex_lock(mutex());
52 assert_status(status == 0, status, "mutex_lock");
53 }
54
55 inline void os::PlatformMutex::unlock() {
56 int status = pthread_mutex_unlock(mutex());
57 assert_status(status == 0, status, "mutex_unlock");
58 }
59
60 inline bool os::PlatformMutex::try_lock() {
61 int status = pthread_mutex_trylock(mutex());
62 assert_status(status == 0 || status == EBUSY, status, "mutex_trylock");
63 return status == 0;
64 }
65
66 inline void os::PlatformMonitor::notify() {
67 int status = pthread_cond_signal(cond());
68 assert_status(status == 0, status, "cond_signal");
69 }
70
71 inline void os::PlatformMonitor::notify_all() {
72 int status = pthread_cond_broadcast(cond());
73 assert_status(status == 0, status, "cond_broadcast");
74 }
75
76 #endif // OS_POSIX_OS_POSIX_INLINE_HPP
|