mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
fix platform_thread_mutex, update time
This commit is contained in:
parent
0084d91e6d
commit
e55c9a6a17
@ -7,23 +7,23 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
void _time_sleep_ms(PikaObj* self, int ms) {
|
||||
#if defined(__linux)
|
||||
usleep(ms * 1000);
|
||||
#elif defined(_WIN32)
|
||||
Sleep(ms);
|
||||
#else
|
||||
__platform_sleep_ms(ms);
|
||||
#endif
|
||||
void (*global_do_sleep_ms)(uint32_t);
|
||||
|
||||
static void _do_sleep_ms_tick(uint32_t ms) {
|
||||
uint32_t tick = pika_platform_get_tick();
|
||||
while (pika_platform_get_tick() - tick < ms) {
|
||||
_pikaVM_yield();
|
||||
}
|
||||
}
|
||||
|
||||
void _time_sleep_ms(PikaObj* self, int ms) {
|
||||
global_do_sleep_ms(ms);
|
||||
}
|
||||
|
||||
void _time_sleep_s(PikaObj* self, int s) {
|
||||
#if defined(__linux)
|
||||
sleep(s);
|
||||
#elif defined(_WIN32)
|
||||
Sleep(s * 1000);
|
||||
#else
|
||||
__platform_sleep_s(s);
|
||||
#endif
|
||||
for (int i = 0; i < s; i++) {
|
||||
_time_sleep_ms(self, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
void _time_platformGetTick(PikaObj* self) {
|
||||
@ -701,12 +701,10 @@ void _time___init__(PikaObj* self) {
|
||||
obj_setInt(self, "locale", 8);
|
||||
time_localtime(0.0, &this_tm, 8);
|
||||
time_set_tm_value(self, &this_tm);
|
||||
if (-1 == pika_platform_get_tick()) {
|
||||
global_do_sleep_ms = pika_platform_sleep_ms;
|
||||
} else {
|
||||
global_do_sleep_ms = _do_sleep_ms_tick;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void _time_sleep(PikaObj* self, pika_float s) {
|
||||
Args* args = New_args(NULL);
|
||||
args_setInt(args, "ms", s * 1000);
|
||||
obj_runNativeMethod(self, "sleep_ms", args);
|
||||
args_deinit(args);
|
||||
}
|
||||
|
@ -4,10 +4,6 @@ from PikaObj import *
|
||||
def __init__(self): ...
|
||||
|
||||
|
||||
def sleep(self, s: float):
|
||||
"""Sleep for s seconds."""
|
||||
|
||||
|
||||
@PIKA_C_MACRO_IF("PIKA_STD_DEVICE_UNIX_TIME_ENABLE")
|
||||
def time(self) -> float:
|
||||
"""Get the current time."""
|
||||
|
@ -2,7 +2,9 @@ import _time
|
||||
|
||||
|
||||
def sleep(s: float):
|
||||
return _time.sleep(s)
|
||||
for i in range(int(s)):
|
||||
_time.sleep_s(1)
|
||||
_time.sleep_ms(int((s - int(s)) * 1000))
|
||||
|
||||
|
||||
def sleep_s(s: int):
|
||||
|
@ -241,11 +241,13 @@ typedef struct pika_platform_thread_mutex {
|
||||
typedef struct pika_platform_thread_mutex {
|
||||
SemaphoreHandle_t mutex;
|
||||
volatile int is_init;
|
||||
volatile int is_first_lock;
|
||||
} pika_platform_thread_mutex_t;
|
||||
#else
|
||||
typedef struct pika_platform_thread_mutex {
|
||||
void* platform_data;
|
||||
volatile int is_init;
|
||||
volatile int is_first_lock;
|
||||
} pika_platform_thread_mutex_t;
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user