mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
commit
56a756c296
@ -197,6 +197,8 @@ PIKA_WEAK void pika_platform_sleep_ms(uint32_t ms) {
|
||||
Sleep(ms);
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
rt_thread_mdelay(ms);
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
zos_task_msleep(ms);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
vTaskDelay(ms / portTICK_PERIOD_MS);
|
||||
#else
|
||||
@ -223,6 +225,9 @@ PIKA_WEAK int64_t pika_platform_get_tick(void) {
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
uint32_t tick = rt_tick_get() * 1000;
|
||||
return (uint32_t)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND);
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
uint32_t tick = zos_tick_get() * 1000;
|
||||
return (uint32_t)((tick + ZOS_TICK_PER_SECOND - 1) / ZOS_TICK_PER_SECOND);
|
||||
#elif defined(_WIN32) && !defined(CROSS_BUILD)
|
||||
FILETIME ft;
|
||||
ULARGE_INTEGER ull;
|
||||
@ -611,6 +616,8 @@ PIKA_WEAK void pika_platform_thread_yield(void) {
|
||||
return;
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
rt_thread_yield();
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
zos_task_msleep(1);
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
@ -689,6 +696,22 @@ PIKA_WEAK pika_platform_thread_t* pika_platform_thread_init(
|
||||
} else {
|
||||
return thread;
|
||||
}
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
pika_platform_thread_t* thread;
|
||||
static int thread_count = 0;
|
||||
char task_name[ZOS_NAME_MAX+1] = {0};
|
||||
zos_sprintf(task_name, "%s%d", name,thread_count++);
|
||||
thread = pikaMalloc(sizeof(pika_platform_thread_t));
|
||||
if(ZOS_NULL == thread) {
|
||||
return ZOS_NULL;
|
||||
}
|
||||
thread->thread = zos_task_create(task_name,entry,param,stack_size,priority);
|
||||
if (thread->thread == ZOS_NULL) {
|
||||
pikaFree(thread, sizeof(pika_platform_thread_t));
|
||||
return ZOS_NULL;
|
||||
} else {
|
||||
return thread;
|
||||
}
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
return NULL;
|
||||
@ -704,6 +727,8 @@ PIKA_WEAK uint64_t pika_platform_thread_self(void) {
|
||||
return (uint64_t)xTaskGetCurrentTaskHandle();
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
return (uint64_t)(uintptr_t)rt_thread_self();
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
return (uint64_t)zos_task_self();
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
return 0;
|
||||
@ -714,6 +739,8 @@ PIKA_WEAK void pika_platform_thread_startup(pika_platform_thread_t* thread) {
|
||||
(void)thread;
|
||||
#if PIKA_RTTHREAD_ENABLE
|
||||
rt_thread_startup(thread->thread);
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
zos_task_startup(thread->thread);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -726,6 +753,8 @@ PIKA_WEAK void pika_platform_thread_stop(pika_platform_thread_t* thread) {
|
||||
vTaskSuspend(thread->thread);
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
rt_thread_suspend(thread->thread);
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
zos_task_suspend(thread->thread);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
#endif
|
||||
@ -740,6 +769,8 @@ PIKA_WEAK void pika_platform_thread_start(pika_platform_thread_t* thread) {
|
||||
vTaskResume(thread->thread);
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
rt_thread_resume(thread->thread);
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
zos_task_resume(thread->thread);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
#endif
|
||||
@ -766,6 +797,12 @@ PIKA_WEAK void pika_platform_thread_destroy(pika_platform_thread_t* thread) {
|
||||
pikaFree(thread, sizeof(pika_platform_thread_t));
|
||||
return;
|
||||
}
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
if (NULL != thread) {
|
||||
zos_task_destroy(thread->thread);
|
||||
pikaFree(thread, sizeof(pika_platform_thread_t));
|
||||
return;
|
||||
}
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
#endif
|
||||
@ -789,6 +826,13 @@ PIKA_WEAK void pika_platform_thread_exit(pika_platform_thread_t* thread) {
|
||||
}
|
||||
rt_thread_delete(thread->thread);
|
||||
return;
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
if (NULL == thread) {
|
||||
zos_task_exit();
|
||||
return;
|
||||
}
|
||||
zos_task_destroy(thread->thread);
|
||||
return;
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
#endif
|
||||
@ -803,6 +847,12 @@ PIKA_WEAK int pika_platform_thread_mutex_init(pika_platform_thread_mutex_t* m) {
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
m->mutex = rt_mutex_create("pika_platform_mutex", RT_IPC_FLAG_PRIO);
|
||||
return 0;
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
static int mutex_count = 0;
|
||||
char mutex_name[ZOS_NAME_MAX+1] = {0};
|
||||
zos_sprintf(mutex_name, "pika_mutex%d", mutex_count++);
|
||||
m->mutex = zos_mutex_create(mutex_name,ZOS_FALSE);
|
||||
return 0;
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
return -1;
|
||||
@ -819,6 +869,8 @@ PIKA_WEAK int pika_platform_thread_mutex_lock(pika_platform_thread_mutex_t* m) {
|
||||
return -1;
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
return rt_mutex_take((m->mutex), RT_WAITING_FOREVER);
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
return zos_mutex_lock(m->mutex,ZOS_WAIT_FOREVER);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
return -1;
|
||||
@ -836,6 +888,8 @@ PIKA_WEAK int pika_platform_thread_mutex_trylock(
|
||||
return -1;
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
return rt_mutex_take((m->mutex), 0);
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
return zos_mutex_lock(m->mutex,0);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
return -1;
|
||||
@ -850,6 +904,8 @@ PIKA_WEAK int pika_platform_thread_mutex_unlock(
|
||||
return xSemaphoreGive(m->mutex);
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
return rt_mutex_release((m->mutex));
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
return zos_mutex_unlock(m->mutex);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
return -1;
|
||||
@ -865,6 +921,8 @@ PIKA_WEAK int pika_platform_thread_mutex_destroy(
|
||||
return 0;
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
return rt_mutex_delete((m->mutex));
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
return zos_mutex_destroy(m->mutex);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
return -1;
|
||||
@ -872,10 +930,23 @@ PIKA_WEAK int pika_platform_thread_mutex_destroy(
|
||||
}
|
||||
|
||||
int pika_thread_recursive_mutex_init(pika_thread_recursive_mutex_t* m) {
|
||||
int ret = pika_platform_thread_mutex_init(&m->mutex);
|
||||
int ret = 0;
|
||||
#if PIKA_ZEUSOS_ENABLE
|
||||
static int mutex_count = 0;
|
||||
char mutex_name[ZOS_NAME_MAX+1] = {0};
|
||||
zos_sprintf(mutex_name, "pika_rec_mutex%d", mutex_count++);
|
||||
m->mutex.mutex = zos_mutex_create(mutex_name,ZOS_TRUE);
|
||||
if (m->mutex.mutex == ZOS_NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
ret = pika_platform_thread_mutex_init(&m->mutex);
|
||||
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
m->owner = 0;
|
||||
m->lock_times = 0;
|
||||
return 0;
|
||||
@ -887,7 +958,12 @@ int pika_thread_recursive_mutex_lock(pika_thread_recursive_mutex_t* m) {
|
||||
m->lock_times++;
|
||||
return 0;
|
||||
}
|
||||
int ret = pika_platform_thread_mutex_lock(&m->mutex);
|
||||
int ret = 0;
|
||||
#if PIKA_ZEUSOS_ENABLE
|
||||
ret = zos_mutex_recursive_lock(m->mutex.mutex,ZOS_WAIT_FOREVER);
|
||||
#else
|
||||
ret = pika_platform_thread_mutex_lock(&m->mutex);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
@ -902,7 +978,12 @@ int pika_thread_recursive_mutex_trylock(pika_thread_recursive_mutex_t* m) {
|
||||
m->lock_times++;
|
||||
return 0;
|
||||
}
|
||||
int ret = pika_platform_thread_mutex_trylock(&m->mutex);
|
||||
int ret = 0;
|
||||
#if PIKA_ZEUSOS_ENABLE
|
||||
ret = zos_mutex_recursive_lock(m->mutex.mutex,0);
|
||||
#else
|
||||
ret = pika_platform_thread_mutex_trylock(&m->mutex);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
@ -918,13 +999,23 @@ int pika_thread_recursive_mutex_unlock(pika_thread_recursive_mutex_t* m) {
|
||||
m->lock_times--;
|
||||
if (m->lock_times == 0) {
|
||||
m->owner = 0;
|
||||
return pika_platform_thread_mutex_unlock(&m->mutex);
|
||||
#if PIKA_ZEUSOS_ENABLE
|
||||
return zos_mutex_recursive_unlock(m->mutex.mutex);
|
||||
#else
|
||||
return pika_platform_thread_mutex_unlock(&m->mutex);
|
||||
#endif
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_thread_recursive_mutex_destroy(pika_thread_recursive_mutex_t* m) {
|
||||
#if PIKA_ZEUSOS_ENABLE
|
||||
return zos_mutex_destroy(m->mutex.mutex);
|
||||
#else
|
||||
return pika_platform_thread_mutex_destroy(&m->mutex);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
PIKA_WEAK void pika_platform_thread_timer_init(pika_platform_timer_t* timer) {
|
||||
@ -937,6 +1028,8 @@ PIKA_WEAK void pika_platform_thread_timer_init(pika_platform_timer_t* timer) {
|
||||
timer->time = 0;
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
timer->time = 0;
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
timer->time = 0;
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
#endif
|
||||
@ -963,6 +1056,11 @@ PIKA_WEAK void pika_platform_thread_timer_cutdown(pika_platform_timer_t* timer,
|
||||
timer->time =
|
||||
(uint32_t)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND);
|
||||
timer->time += timeout;
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
zos_uint32_t tick = zos_tick_get() * 1000;
|
||||
timer->time =
|
||||
(uint32_t)((tick + ZOS_TICK_PER_SECOND - 1) / ZOS_TICK_PER_SECOND);
|
||||
timer->time += timeout;
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
#endif
|
||||
@ -988,6 +1086,11 @@ PIKA_WEAK char pika_platform_thread_timer_is_expired(
|
||||
uint32_t time =
|
||||
(uint32_t)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND);
|
||||
return time > timer->time ? 1 : 0;
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
uint32_t tick = zos_tick_get() * 1000;
|
||||
uint32_t time =
|
||||
(uint32_t)((tick + ZOS_TICK_PER_SECOND - 1) / ZOS_TICK_PER_SECOND);
|
||||
return time > timer->time ? 1 : 0;
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
return 1;
|
||||
@ -1021,6 +1124,14 @@ PIKA_WEAK int pika_platform_thread_timer_remain(pika_platform_timer_t* timer) {
|
||||
return 0;
|
||||
}
|
||||
return timer->time - now;
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
uint32_t now;
|
||||
uint32_t tick = zos_tick_get() * 1000;
|
||||
now = (uint32_t)((tick + ZOS_TICK_PER_SECOND - 1) / ZOS_TICK_PER_SECOND);
|
||||
if (timer->time <= now) {
|
||||
return 0;
|
||||
}
|
||||
return timer->time - now;
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
return -1;
|
||||
@ -1036,6 +1147,10 @@ PIKA_WEAK unsigned long pika_platform_thread_timer_now(void) {
|
||||
uint32_t tick = rt_tick_get() * 1000;
|
||||
return (unsigned long)((tick + RT_TICK_PER_SECOND - 1) /
|
||||
RT_TICK_PER_SECOND);
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
uint32_t tick = zos_tick_get() * 1000;
|
||||
return (unsigned long)((tick + ZOS_TICK_PER_SECOND - 1) /
|
||||
ZOS_TICK_PER_SECOND);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
return 1;
|
||||
@ -1063,6 +1178,15 @@ PIKA_WEAK void pika_platform_thread_timer_usleep(unsigned long usec) {
|
||||
tick = 1;
|
||||
}
|
||||
rt_thread_mdelay(tick);
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
zos_tick_t tick = 1;
|
||||
if (usec != 0) {
|
||||
tick = usec / ZOS_TICK_PER_SECOND;
|
||||
|
||||
if (tick == 0)
|
||||
tick = 1;
|
||||
}
|
||||
zos_task_tsleep(tick);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||
#endif
|
||||
|
@ -116,6 +116,9 @@ extern "C" {
|
||||
#if defined(__RTTHREAD__) && PIKA_RTTHREAD_ENABLE
|
||||
#include <rtthread.h>
|
||||
#define pika_platform_printf(...) rt_kprintf(__VA_ARGS__)
|
||||
#elif defined(__ZEUSOS__) && PIKA_ZEUSOS_ENABLE
|
||||
#include "zos.h"
|
||||
#define pika_platform_printf(...) zos_kprintf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
@ -289,6 +292,11 @@ typedef struct pika_platform_thread {
|
||||
typedef struct pika_platform_thread {
|
||||
rt_thread_t thread;
|
||||
} pika_platform_thread_t;
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
#include "zos.h"
|
||||
typedef struct pika_platform_thread {
|
||||
zos_task_t thread;
|
||||
} pika_platform_thread_t;
|
||||
#else
|
||||
typedef struct pika_platform_thread {
|
||||
void* platform_data;
|
||||
@ -319,6 +327,9 @@ typedef SemaphoreHandle_t pika_mutex_platform_data_t;
|
||||
#elif PIKA_RTTHREAD_ENABLE
|
||||
#include <rtthread.h>
|
||||
typedef rt_mutex_t pika_mutex_platform_data_t;
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
#include "zos.h"
|
||||
typedef zos_mutex_t pika_mutex_platform_data_t;
|
||||
#else
|
||||
typedef void* pika_mutex_platform_data_t;
|
||||
#endif
|
||||
@ -364,6 +375,11 @@ typedef struct pika_platform_timer {
|
||||
typedef struct pika_platform_timer {
|
||||
uint32_t time;
|
||||
} pika_platform_timer_t;
|
||||
#elif PIKA_ZEUSOS_ENABLE
|
||||
#include "zos.h"
|
||||
typedef struct pika_platform_timer {
|
||||
uint32_t time;
|
||||
} pika_platform_timer_t;
|
||||
#else
|
||||
typedef struct pika_platform_timer {
|
||||
void* platform_data;
|
||||
|
@ -419,6 +419,10 @@ extern "C" {
|
||||
#define PIKA_RTTHREAD_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_ZEUSOS_ENABLE
|
||||
#define PIKA_ZEUSOS_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_LINUX_COMPATIBLE
|
||||
#define PIKA_LINUX_COMPATIBLE 0
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user