mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-06 18:20:17 +00:00
Update time.c
This commit is contained in:
parent
c3291ef718
commit
e2c065d18d
@ -1,7 +1,9 @@
|
|||||||
#define _XOPEN_SOURCE 700
|
#define _XOPEN_SOURCE 700
|
||||||
|
#include <time.h>
|
||||||
|
#undef _XOPEN_SOURCE
|
||||||
|
|
||||||
#include "pocketpy/pocketpy.h"
|
#include "pocketpy/pocketpy.h"
|
||||||
#include <time.h>
|
#include "pocketpy/common/threads.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#define NANOS_PER_SEC 1000000000
|
#define NANOS_PER_SEC 1000000000
|
||||||
@ -50,11 +52,14 @@ static bool time_sleep(int argc, py_Ref argv) {
|
|||||||
py_f64 secs;
|
py_f64 secs;
|
||||||
if(!py_castfloat(argv, &secs)) return false;
|
if(!py_castfloat(argv, &secs)) return false;
|
||||||
|
|
||||||
clock_t start = clock();
|
int64_t start = time_ns();
|
||||||
const clock_t end = start + (clock_t)(secs * CLOCKS_PER_SEC);
|
const int64_t end = start + secs * NANOS_PER_SEC;
|
||||||
while(true) {
|
while(true) {
|
||||||
clock_t now = clock();
|
int64_t now = time_ns();
|
||||||
if(now >= end) break;
|
if(now >= end) break;
|
||||||
|
#if PK_ENABLE_THREADS
|
||||||
|
c11_thrd__yield();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
py_newnone(py_retval());
|
py_newnone(py_retval());
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user