posix: Use trunc() from <math.h> instead of std::trunc()

This folow-up to d2d10d1dc8f3 is for compatibility with 32-bit Android
platforms using NDK API 16.

isinf() is also caught up in the switch.

Change-Id: I652e27061c01afa3dd932f494cc4eeaca4236f40
Reviewed-on: https://chromium-review.googlesource.com/544238
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Mark Mentovai 2017-06-22 16:46:26 -04:00
parent d2d10d1dc8
commit 7819ecbed6

View File

@ -15,10 +15,9 @@
#include "util/synchronization/semaphore.h" #include "util/synchronization/semaphore.h"
#include <errno.h> #include <errno.h>
#include <math.h>
#include <time.h> #include <time.h>
#include <cmath>
#include "base/logging.h" #include "base/logging.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
@ -54,7 +53,7 @@ void Semaphore::Wait() {
bool Semaphore::TimedWait(double seconds) { bool Semaphore::TimedWait(double seconds) {
DCHECK_GE(seconds, 0.0); DCHECK_GE(seconds, 0.0);
if (std::isinf(seconds)) { if (isinf(seconds)) {
Wait(); Wait();
return true; return true;
} }
@ -66,7 +65,7 @@ bool Semaphore::TimedWait(double seconds) {
} }
timespec timeout; timespec timeout;
timeout.tv_sec = seconds; timeout.tv_sec = seconds;
timeout.tv_nsec = (seconds - std::trunc(seconds)) * 1E9; timeout.tv_nsec = (seconds - trunc(seconds)) * 1E9;
AddTimespec(current_time, timeout, &timeout); AddTimespec(current_time, timeout, &timeout);
int rv = HANDLE_EINTR(sem_timedwait(&semaphore_, &timeout)); int rv = HANDLE_EINTR(sem_timedwait(&semaphore_, &timeout));