From 75c46fa727b78678fbfb4523d27f8e9fc4974f03 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Thu, 7 Jul 2022 14:35:10 +0800 Subject: [PATCH] :rocket: change usleep in builtin_sleep to cross platform c++11::std::this_thread::sleep_for. Although this is not so accurate in Windows platform, the accuracy is still improved and this line of code does not need MinGW to build on Windows platform. --- nasal.h | 2 ++ nasal_builtin.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/nasal.h b/nasal.h index d8c6ab5..d8537cf 100644 --- a/nasal.h +++ b/nasal.h @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include diff --git a/nasal_builtin.h b/nasal_builtin.h index 13450a0..604c6b2 100644 --- a/nasal_builtin.h +++ b/nasal_builtin.h @@ -1037,7 +1037,7 @@ nasal_ref builtin_sleep(nasal_ref* local,nasal_gc& gc) nasal_ref val=local[1]; if(val.type!=vm_num) return builtin_err("sleep","\"duration\" must be number"); - usleep((useconds_t)(val.num()*1e6)); + std::this_thread::sleep_for(std::chrono::microseconds(int64_t(val.num()*1e6))); return nil; } nasal_ref builtin_pipe(nasal_ref* local,nasal_gc& gc)