
#ifndef PLS_INTERNAL_BASE_FUTEX_WRAPPER_H_
#define PLS_INTERNAL_BASE_FUTEX_WRAPPER_H_

#include <unistd.h>
#include <sys/syscall.h>
#include <linux/futex.h>
#include <ctime>
#include <cerrno>
#include <cstdint>

namespace pls::internal::base {

int futex(int *uaddr, int futex_op, int val, const struct timespec *timeout, int *uaddr2, int val3) {
  return syscall(SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
}

int futex_wait(int32_t *uaddr, int32_t val) {
  return futex(uaddr, FUTEX_WAIT_PRIVATE, val, nullptr, nullptr, 0);
}

int futex_wakeup(int32_t *uaddr, int num_waked) {
  return futex(uaddr, FUTEX_WAKE_PRIVATE, num_waked, nullptr, nullptr, 0);
}

}

#endif //PLS_INTERNAL_BASE_FUTEX_WRAPPER_H_
