🚀 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.
This commit is contained in:
parent
bd5044add2
commit
75c46fa727
2
nasal.h
2
nasal.h
|
@ -20,6 +20,8 @@
|
|||
#include <queue>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.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)
|
||||
|
|
Loading…
Reference in New Issue