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

@@ -124,6 +124,7 @@ static const bool config_debug =
#include "test/math.h"
#include "test/mtx.h"
#include "test/mq.h"
#include "test/sleep.h"
#include "test/test.h"
#include "test/timer.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
@@ -82,7 +82,7 @@ a_prefix##get(a_mq_type *mq) { \
\
ns = 1; \
while (true) { \
mq_nanosleep(ns); \
sleep_ns(ns); \
msg = a_prefix##tryget(mq); \
if (msg != NULL) { \
return msg; \

View File

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

View File

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