From e2c065d18df8a05600661b822f990e720b17b792 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 26 Nov 2025 22:06:15 +0800 Subject: [PATCH] Update time.c --- src/modules/time.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/modules/time.c b/src/modules/time.c index 747b1066..998a3e87 100644 --- a/src/modules/time.c +++ b/src/modules/time.c @@ -1,7 +1,9 @@ #define _XOPEN_SOURCE 700 +#include +#undef _XOPEN_SOURCE #include "pocketpy/pocketpy.h" -#include +#include "pocketpy/common/threads.h" #include #define NANOS_PER_SEC 1000000000 @@ -50,11 +52,14 @@ static bool time_sleep(int argc, py_Ref argv) { py_f64 secs; if(!py_castfloat(argv, &secs)) return false; - clock_t start = clock(); - const clock_t end = start + (clock_t)(secs * CLOCKS_PER_SEC); + int64_t start = time_ns(); + const int64_t end = start + secs * NANOS_PER_SEC; while(true) { - clock_t now = clock(); + int64_t now = time_ns(); if(now >= end) break; +#if PK_ENABLE_THREADS + c11_thrd__yield(); +#endif } py_newnone(py_retval()); return true;