Commit 6fd918a2 authored by Wez's avatar Wez Committed by Commit Bot

Clean up usage of POSIX APIs that are unsupported under Fuchsia.

Recent Fuchsia SDKs have begun removing both symbols for unsupported
POSIX APIs, and also the relevant definitions, and even headers.

This CL:
- Removes dependencies on <sys/resource.h>.
- Adds a working implementation of GetUserTime().
- Fixes GetCurrentThreadId() to use the native (32-bit) Fuchsia thread
  handle, rather than the (64-bit) pthread*, to avoid potential for id
  clashes when truncating the value into a 32-bit int.

Bug: chromium:707030
Change-Id: Ic5774e138f7657123dd65d0fb7ef5d87876766e8
Reviewed-on: https://chromium-review.googlesource.com/933247Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51579}
parent 797d3df0
......@@ -131,5 +131,21 @@ void OS::SignalCodeMovingGC() {
UNREACHABLE(); // TODO(scottmg): Port, https://crbug.com/731217.
}
int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
const auto kNanosPerMicrosecond = 1000ULL;
const auto kMicrosPerSecond = 1000000ULL;
const zx_time_t nanos_since_thread_started = zx_clock_get(ZX_CLOCK_THREAD);
// First convert to microseconds, rounding up.
const uint64_t micros_since_thread_started =
(nanos_since_thread_started + kNanosPerMicrosecond - 1ULL) /
kNanosPerMicrosecond;
*secs = static_cast<uint32_t>(micros_since_thread_started / kMicrosPerSecond);
*usecs =
static_cast<uint32_t>(micros_since_thread_started % kMicrosPerSecond);
return 0;
}
} // namespace base
} // namespace v8
......@@ -18,7 +18,6 @@
#include <unistd.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
......@@ -55,6 +54,12 @@
#include <sys/prctl.h> // NOLINT, for prctl
#endif
#if defined(V8_OS_FUCHSIA)
#include <zircon/process.h>
#else
#include <sys/resource.h>
#endif
#if !defined(_AIX) && !defined(V8_OS_FUCHSIA)
#include <sys/syscall.h>
#endif
......@@ -478,7 +483,7 @@ int OS::GetCurrentThreadId() {
#elif V8_OS_AIX
return static_cast<int>(thread_self());
#elif V8_OS_FUCHSIA
return static_cast<int>(pthread_self());
return static_cast<int>(zx_thread_self());
#elif V8_OS_SOLARIS
return static_cast<int>(pthread_self());
#else
......@@ -491,6 +496,7 @@ int OS::GetCurrentThreadId() {
// POSIX date/time support.
//
#if !defined(V8_OS_FUCHSIA)
int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
struct rusage usage;
......@@ -499,7 +505,7 @@ int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
*usecs = static_cast<uint32_t>(usage.ru_utime.tv_usec);
return 0;
}
#endif
double OS::TimeCurrentMillis() {
return Time::Now().ToJsTime();
......
......@@ -5,11 +5,13 @@
#include "src/base/sys-info.h"
#if V8_OS_POSIX
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#if !V8_OS_FUCHSIA
#include <sys/resource.h>
#endif
#endif
#if V8_OS_BSD
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment