This source file includes following definitions.
- NaClAbsTimeToRelTime
 
- IrtFutexWaitAbs
 
- IrtFutexWake
 
#include <errno.h>
#include <linux/futex.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <unistd.h>
#include "components/nacl/loader/nonsfi/irt_interfaces.h"
#include "components/nacl/loader/nonsfi/irt_util.h"
#include "native_client/src/trusted/service_runtime/include/sys/time.h"
namespace nacl {
namespace nonsfi {
namespace {
void NaClAbsTimeToRelTime(const struct nacl_abi_timespec& nacl_abstime,
                          const struct timespec& now,
                          struct timespec* reltime) {
  reltime->tv_sec = nacl_abstime.tv_sec - now.tv_sec;
  reltime->tv_nsec = nacl_abstime.tv_nsec - now.tv_nsec;
  if (reltime->tv_nsec < 0) {
    reltime->tv_sec -= 1;
    reltime->tv_nsec += 1000000000;
  }
}
int IrtFutexWaitAbs(volatile int* addr, int value,
                    const struct nacl_abi_timespec* abstime) {
  struct timespec timeout;
  struct timespec* timeout_ptr = NULL;
  if (abstime) {
    
    
    struct timespec now;
    if (clock_gettime(CLOCK_REALTIME, &now))
      return errno;
    NaClAbsTimeToRelTime(*abstime, now, &timeout);
    
    
    
    
    
    if (timeout.tv_sec < 0)
      return ETIMEDOUT;
    timeout_ptr = &timeout;
  }
  return CheckError(
      syscall(SYS_futex, addr, FUTEX_WAIT_PRIVATE, value, timeout_ptr, 0, 0));
}
int IrtFutexWake(volatile int* addr, int nwake, int* count) {
  return CheckErrorWithResult(
      syscall(SYS_futex, addr, FUTEX_WAKE_PRIVATE, nwake, 0, 0, 0), count);
}
}  
const nacl_irt_futex kIrtFutex = {
  reinterpret_cast<int(*)(volatile int*, int, const struct timespec*)>(
      IrtFutexWaitAbs),
  IrtFutexWake,
};
}  
}