瀏覽代碼

Implement os_usleep for posix (#2517)

YAMAMOTO Takashi 2 年之前
父節點
當前提交
1ff41ebdc2
共有 1 個文件被更改,包括 20 次插入0 次删除
  1. 20 0
      core/shared/platform/common/posix/posix_sleep.c

+ 20 - 0
core/shared/platform/common/posix/posix_sleep.c

@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2023 Midokura Japan KK.  All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ */
+
+#include <time.h>
+
+#include "platform_api_extension.h"
+
+int
+os_usleep(uint32 usec)
+{
+    struct timespec ts;
+    int ret;
+
+    ts.tv_sec = usec / 1000000;
+    ts.tv_nsec = (usec % 1000000) * 1000;
+    ret = nanosleep(&ts, NULL);
+    return ret == 0 ? 0 : -1;
+}