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