Restructure and correct sleep utility for testing

This commit is contained in:
Yinan Zhang 2020-01-15 07:25:59 -08:00
parent 7b67ed0b5a
commit a72ea0db60
5 changed files with 7 additions and 5 deletions

View File

@ -167,7 +167,7 @@ DOCS_MAN3 := $(DOCS_XML:$(objroot)%.xml=$(objroot)%.3)
DOCS := $(DOCS_HTML) $(DOCS_MAN3) DOCS := $(DOCS_HTML) $(DOCS_MAN3)
C_TESTLIB_SRCS := $(srcroot)test/src/btalloc.c $(srcroot)test/src/btalloc_0.c \ C_TESTLIB_SRCS := $(srcroot)test/src/btalloc.c $(srcroot)test/src/btalloc_0.c \
$(srcroot)test/src/btalloc_1.c $(srcroot)test/src/math.c \ $(srcroot)test/src/btalloc_1.c $(srcroot)test/src/math.c \
$(srcroot)test/src/mtx.c $(srcroot)test/src/mq.c \ $(srcroot)test/src/mtx.c $(srcroot)test/src/sleep.c \
$(srcroot)test/src/SFMT.c $(srcroot)test/src/test.c \ $(srcroot)test/src/SFMT.c $(srcroot)test/src/test.c \
$(srcroot)test/src/thd.c $(srcroot)test/src/timer.c $(srcroot)test/src/thd.c $(srcroot)test/src/timer.c
ifeq (1, $(link_whole_archive)) ifeq (1, $(link_whole_archive))

View File

@ -124,6 +124,7 @@ static const bool config_debug =
#include "test/math.h" #include "test/math.h"
#include "test/mtx.h" #include "test/mtx.h"
#include "test/mq.h" #include "test/mq.h"
#include "test/sleep.h"
#include "test/test.h" #include "test/test.h"
#include "test/timer.h" #include "test/timer.h"
#include "test/thd.h" #include "test/thd.h"

View File

@ -1,4 +1,4 @@
void mq_nanosleep(unsigned ns); #include "test/sleep.h"
/* /*
* Simple templated message queue implementation that relies on only mutexes for * Simple templated message queue implementation that relies on only mutexes for
@ -82,7 +82,7 @@ a_prefix##get(a_mq_type *mq) { \
\ \
ns = 1; \ ns = 1; \
while (true) { \ while (true) { \
mq_nanosleep(ns); \ sleep_ns(ns); \
msg = a_prefix##tryget(mq); \ msg = a_prefix##tryget(mq); \
if (msg != NULL) { \ if (msg != NULL) { \
return msg; \ return msg; \

View File

@ -0,0 +1 @@
void sleep_ns(unsigned ns);

View File

@ -5,11 +5,11 @@
* time is guaranteed. * time is guaranteed.
*/ */
void void
mq_nanosleep(unsigned ns) { sleep_ns(unsigned ns) {
assert(ns <= 1000*1000*1000); assert(ns <= 1000*1000*1000);
#ifdef _WIN32 #ifdef _WIN32
Sleep(ns / 1000); Sleep(ns / 1000 / 1000);
#else #else
{ {
struct timespec timeout; struct timespec timeout;