Skip to content

Commit 128d05c

Browse files
authored
Implement os_usleep for posix (bytecodealliance#2517)
1 parent a3c5988 commit 128d05c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (C) 2023 Midokura Japan KK. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include <time.h>
7+
8+
#include "platform_api_extension.h"
9+
10+
int
11+
os_usleep(uint32 usec)
12+
{
13+
struct timespec ts;
14+
int ret;
15+
16+
ts.tv_sec = usec / 1000000;
17+
ts.tv_nsec = (usec % 1000000) * 1000;
18+
ret = nanosleep(&ts, NULL);
19+
return ret == 0 ? 0 : -1;
20+
}

0 commit comments

Comments
 (0)