Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,35 @@ size_t os::vm_min_address() {
#endif
}

#ifdef __OpenBSD__
// OpenBSD does not provide sleep functionality with nanosecond resolution, so we
// try to approximate this with spinning combined with spin pause for sleeps
// less then 20 ms
void os::naked_short_nanosleep(jlong ns) {
assert(ns > -1 && ns < NANOUNITS, "Un-interruptable sleep, short time use only");

// if >= 20 ms use nanosleep
if (ns >= 20 * NANOUNITS_PER_MILLIUNIT) {
struct timespec req, rem;
req.tv_sec = 0;
req.tv_nsec = ns;
while(::nanosleep(&req, &rem) == -1) {
if (errno == EINTR)
req = rem;
else
break;
}
return;
}

// less then 20 ms need to use busy wait
int64_t start = os::javaTimeNanos();
do {
SpinPause();
} while (os::javaTimeNanos() - start < ns);
}
#endif // __OpenBSD__

////////////////////////////////////////////////////////////////////////////////
// thread priority support

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/os/posix/os_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ void os::infinite_sleep() {
}
}

#ifndef __OpenBSD__
void os::naked_short_nanosleep(jlong ns) {
struct timespec req;
assert(ns > -1 && ns < NANOUNITS, "Un-interruptable sleep, short time use only");
Expand All @@ -1036,6 +1037,7 @@ void os::naked_short_nanosleep(jlong ns) {
::nanosleep(&req, nullptr);
return;
}
#endif

void os::naked_short_sleep(jlong ms) {
assert(ms < MILLIUNITS, "Un-interruptable sleep, short time use only");
Expand Down