diff mbox series

[3/7] Add clock_nanosleep

Message ID 20230422161934.2311-3-itachis6234@gmail.com (mailing list archive)
State New, archived
Headers show
Series [1/7] Create os-time.c and add t2h_freebsd_timeval | expand

Commit Message

Ajeet Singh April 22, 2023, 4:19 p.m. UTC
From: Kyle Evans <kevans@freebsd.org>

+Add clock_nanosleep(2)
Provide sleep interval in nanoseconds and allows to choose which clock
to measure it against.
Signed-off-by: Ajeets6 <itachis6234@gmail.com>
Signed-off-by: Kyle Evans <kevans@freebsd.org>
---
 bsd-user/freebsd/os-time.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h
index 18c9e1dd12..29d2c8d02a 100644
--- a/bsd-user/freebsd/os-time.h
+++ b/bsd-user/freebsd/os-time.h
@@ -42,3 +42,24 @@  static inline abi_long do_freebsd_nanosleep(abi_long arg1, abi_long arg2)
 
     return ret;
 }
+/* clock_nanosleep(2) */
+static inline abi_long do_freebsd_clock_nanosleep(abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4)
+{
+    struct timespec req, rem;
+    abi_long ret;
+    int clkid, flags;
+
+    clkid = arg1;
+    /* XXX Translate? */
+    flags = arg2;
+    ret = t2h_freebsd_timespec(&req, arg3);
+    if (!is_error(ret)) {
+        ret = get_errno(safe_clock_nanosleep(clkid, flags, &req, &rem));
+        if (ret == -TARGET_EINTR && arg4) {
+            h2t_freebsd_timespec(arg4, &rem);
+        }
+    }
+
+    return ret;
+}