File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 44#include <stdlib.h>
55#include <sys/time.h>
66#include <time.h>
7+ #include <wasi/version.h>
78
89#define TEST (c ) \
910 do { \
1213 t_error("%s failed (errno = %d)\n", #c, errno); \
1314 } while (0)
1415
16+ #ifdef __wasip1__
17+ #define CLOCK CLOCK_REALTIME
18+ #else
19+ #define CLOCK CLOCK_MONOTONIC
20+ #endif
21+
1522int main (void ) {
1623 // Sleep for a total of 5ms
1724 long ns_to_sleep = 5E6 ;
1825
1926 struct timespec start_time , end_time ;
20- clock_gettime (CLOCK_MONOTONIC , & start_time );
27+ clock_gettime (CLOCK , & start_time );
2128 struct timespec dur ;
2229 dur .tv_sec = 0 ;
2330 dur .tv_nsec = ns_to_sleep ;
2431 TEST (nanosleep (& dur , NULL ) == 0 );
25- clock_gettime (CLOCK_MONOTONIC , & end_time );
32+ clock_gettime (CLOCK , & end_time );
2633 TEST (end_time .tv_sec - start_time .tv_sec <= 1 );
2734
2835 long nanoseconds_elapsed = (end_time .tv_sec - start_time .tv_sec ) * 1E9 -
Original file line number Diff line number Diff line change 44#include <stdlib.h>
55#include <sys/time.h>
66#include <time.h>
7+ #include <wasi/version.h>
78
89#define TEST (c ) \
910 do { \
1213 t_error("%s failed (errno = %d)\n", #c, errno); \
1314 } while (0)
1415
16+ #ifdef __wasip1__
17+ #define CLOCK CLOCK_REALTIME
18+ #else
19+ #define CLOCK CLOCK_MONOTONIC
20+ #endif
21+
1522int main (void ) {
1623 // Sleep for a total of 5ms
1724 long ns_to_sleep = 5E6 ;
1825
1926 struct timespec start_time , end_time ;
20- clock_gettime (CLOCK_MONOTONIC , & start_time );
27+ clock_gettime (CLOCK , & start_time );
2128 TEST (usleep (ns_to_sleep / 1000 ) == 0 );
22- clock_gettime (CLOCK_MONOTONIC , & end_time );
29+ clock_gettime (CLOCK , & end_time );
2330 TEST (end_time .tv_sec - start_time .tv_sec <= 1 );
2431
2532 long nanoseconds_elapsed = (end_time .tv_sec - start_time .tv_sec ) * 1E9 -
You can’t perform that action at this time.
0 commit comments