Apply clang-format for core/shared and product-mini files (#785)

Apply clang-format for core/shared and product-mini files
This commit is contained in:
Wenyong Huang
2021-10-14 09:12:07 +08:00
committed by GitHub
parent fb4afc7ca4
commit 17f62ad472
107 changed files with 3436 additions and 2898 deletions

View File

@ -37,7 +37,6 @@
#include <arch/arm/aarch32/cortex_m/cmsis.h>
#endif
#ifndef BH_PLATFORM_ZEPHYR
#define BH_PLATFORM_ZEPHYR
#endif
@ -62,6 +61,7 @@ typedef struct korp_cond {
#define Z_TIMEOUT_MS(ms) ms
#endif
/* clang-format off */
void abort(void);
size_t strspn(const char *s, const char *accept);
size_t strcspn(const char *s, const char *reject);
@ -91,6 +91,7 @@ double scalbn(double x, int n);
unsigned long long int strtoull(const char *nptr, char **endptr, int base);
double strtod(const char *nptr, char **endptr);
float strtof(const char *nptr, char **endptr);
/* clang-format on */
/**
* @brief Allocate executable memroy
@ -99,7 +100,7 @@ float strtof(const char *nptr, char **endptr);
*
* @return the address of the allocated memory if not NULL
*/
typedef void* (*exec_mem_alloc_func_t)(unsigned int size);
typedef void *(*exec_mem_alloc_func_t)(unsigned int size);
/**
* @brief Release executable memroy
@ -108,8 +109,12 @@ typedef void* (*exec_mem_alloc_func_t)(unsigned int size);
*/
typedef void (*exec_mem_free_func_t)(void *addr);
/* Below function are called by external project to set related function pointers that
* will be used to malloc/free executable memory. Otherwise default mechanise will be used. */
void set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func, exec_mem_free_func_t free_func);
/* Below function are called by external project to set related function
* pointers that will be used to malloc/free executable memory. Otherwise
* default mechanise will be used.
*/
void
set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func,
exec_mem_free_func_t free_func);
#endif

View File

@ -29,9 +29,8 @@ disable_mpu_rasr_xn(void)
MPU->RASR |= ~MPU_RASR_XN_Msk;
}
}
}
#endif /* end of CONFIG_ARM_MPU */
#endif /* end of CONFIG_ARM_MPU */
#endif
static int
@ -84,8 +83,7 @@ os_realloc(void *ptr, unsigned size)
void
os_free(void *ptr)
{
}
{}
#if 0
struct out_context {
@ -203,17 +201,17 @@ os_dcache_flush()
SCB_CleanDCache();
irq_unlock(key);
#elif defined(CONFIG_SOC_CVF_EM7D) && defined(CONFIG_ARC_MPU) \
&& defined (CONFIG_CACHE_FLUSHING)
&& defined(CONFIG_CACHE_FLUSHING)
__asm__ __volatile__("sync");
z_arc_v2_aux_reg_write(_ARC_V2_DC_FLSH, BIT(0));
__asm__ __volatile__("sync");
#endif
}
void set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func,
exec_mem_free_func_t free_func)
void
set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func,
exec_mem_free_func_t free_func)
{
exec_mem_alloc_func = alloc_func;
exec_mem_free_func = free_func;
}

View File

@ -6,13 +6,15 @@
#include "platform_api_vmcore.h"
#include "platform_api_extension.h"
/* clang-format off */
#define bh_assert(v) do { \
if (!(v)) { \
printf("\nASSERTION FAILED: %s, at %s, line %d\n", \
#v, __FILE__, __LINE__); \
abort(); \
} \
} while (0)
} while (0)
/* clang-format on */
#if defined(CONFIG_ARM_MPU) || defined(CONFIG_ARC_MPU) \
|| KERNEL_VERSION_NUMBER > 0x020300 /* version 2.3.0 */
@ -28,13 +30,13 @@
#endif
#if BH_ENABLE_ZEPHYR_MPU_STACK != 0
static K_THREAD_STACK_ARRAY_DEFINE(mpu_stacks,
BH_ZEPHYR_MPU_STACK_COUNT,
static K_THREAD_STACK_ARRAY_DEFINE(mpu_stacks, BH_ZEPHYR_MPU_STACK_COUNT,
BH_ZEPHYR_MPU_STACK_SIZE);
static bool mpu_stack_allocated[BH_ZEPHYR_MPU_STACK_COUNT];
static struct k_mutex mpu_stack_lock;
static char *mpu_stack_alloc()
static char *
mpu_stack_alloc()
{
int i;
@ -43,14 +45,15 @@ static char *mpu_stack_alloc()
if (!mpu_stack_allocated[i]) {
mpu_stack_allocated[i] = true;
k_mutex_unlock(&mpu_stack_lock);
return (char*)mpu_stacks[i];
return (char *)mpu_stacks[i];
}
}
k_mutex_unlock(&mpu_stack_lock);
return NULL;
}
static void mpu_stack_free(char *stack)
static void
mpu_stack_free(char *stack)
{
int i;
@ -114,7 +117,8 @@ static struct k_mutex thread_obj_lock;
/* Thread object list */
static os_thread_obj *thread_obj_list = NULL;
static void thread_data_list_add(os_thread_data *thread_data)
static void
thread_data_list_add(os_thread_data *thread_data)
{
k_mutex_lock(&thread_data_lock, K_FOREVER);
if (!thread_data_list)
@ -137,7 +141,8 @@ static void thread_data_list_add(os_thread_data *thread_data)
k_mutex_unlock(&thread_data_lock);
}
static void thread_data_list_remove(os_thread_data *thread_data)
static void
thread_data_list_remove(os_thread_data *thread_data)
{
k_mutex_lock(&thread_data_lock, K_FOREVER);
if (thread_data_list) {
@ -174,7 +179,8 @@ thread_data_list_lookup(k_tid_t tid)
return NULL;
}
static void thread_obj_list_add(os_thread_obj *thread_obj)
static void
thread_obj_list_add(os_thread_obj *thread_obj)
{
k_mutex_lock(&thread_obj_lock, K_FOREVER);
if (!thread_obj_list)
@ -187,7 +193,8 @@ static void thread_obj_list_add(os_thread_obj *thread_obj)
k_mutex_unlock(&thread_obj_lock);
}
static void thread_obj_list_reclaim()
static void
thread_obj_list_reclaim()
{
os_thread_obj *p, *p_prev;
k_mutex_lock(&thread_obj_lock, K_FOREVER);
@ -199,12 +206,14 @@ static void thread_obj_list_reclaim()
thread_obj_list = p->next;
BH_FREE(p);
p = thread_obj_list;
} else { /* p is not the head of list */
}
else { /* p is not the head of list */
p_prev->next = p->next;
BH_FREE(p);
p = p_prev->next;
}
} else {
}
else {
p_prev = p;
p = p->next;
}
@ -212,7 +221,8 @@ static void thread_obj_list_reclaim()
k_mutex_unlock(&thread_obj_lock);
}
int os_thread_sys_init()
int
os_thread_sys_init()
{
if (is_thread_sys_inited)
return BHT_OK;
@ -233,7 +243,8 @@ int os_thread_sys_init()
return BHT_OK;
}
void os_thread_sys_destroy(void)
void
os_thread_sys_destroy(void)
{
if (is_thread_sys_inited) {
is_thread_sys_inited = false;
@ -247,7 +258,8 @@ thread_data_current()
return thread_data_list_lookup(tid);
}
static void os_thread_cleanup(void)
static void
os_thread_cleanup(void)
{
os_thread_data *thread_data = thread_data_current();
@ -269,32 +281,35 @@ static void os_thread_cleanup(void)
thread_data_list_remove(thread_data);
/* Set flag to true for the next thread creating to
free the thread object */
((os_thread_obj*) thread_data->tid)->to_be_freed = true;
((os_thread_obj *)thread_data->tid)->to_be_freed = true;
#if BH_ENABLE_ZEPHYR_MPU_STACK != 0
mpu_stack_free(thread_data->stack);
#endif
BH_FREE(thread_data);
}
static void os_thread_wrapper(void *start, void *arg, void *thread_data)
static void
os_thread_wrapper(void *start, void *arg, void *thread_data)
{
/* Set thread custom data */
((os_thread_data*) thread_data)->tid = k_current_get();
((os_thread_data *)thread_data)->tid = k_current_get();
thread_data_list_add(thread_data);
((thread_start_routine_t) start)(arg);
((thread_start_routine_t)start)(arg);
os_thread_cleanup();
}
int os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
unsigned int stack_size)
int
os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
unsigned int stack_size)
{
return os_thread_create_with_prio(p_tid, start, arg, stack_size,
BH_THREAD_DEFAULT_PRIORITY);
}
int os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
void *arg, unsigned int stack_size, int prio)
int
os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
void *arg, unsigned int stack_size, int prio)
{
korp_tid tid;
os_thread_data *thread_data;
@ -347,7 +362,7 @@ int os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
/* Set thread custom data */
thread_data_list_add(thread_data);
thread_obj_list_add((os_thread_obj*)tid);
thread_obj_list_add((os_thread_obj *)tid);
*p_tid = tid;
return BHT_OK;
@ -362,14 +377,16 @@ fail1:
return BHT_ERROR;
}
korp_tid os_self_thread()
korp_tid
os_self_thread()
{
return (korp_tid)k_current_get();
}
int os_thread_join(korp_tid thread, void **value_ptr)
int
os_thread_join(korp_tid thread, void **value_ptr)
{
(void) value_ptr;
(void)value_ptr;
os_thread_data *thread_data;
os_thread_wait_node *node;
@ -407,30 +424,35 @@ int os_thread_join(korp_tid thread, void **value_ptr)
return BHT_OK;
}
int os_mutex_init(korp_mutex *mutex)
int
os_mutex_init(korp_mutex *mutex)
{
k_mutex_init(mutex);
return BHT_OK;
}
int os_recursive_mutex_init(korp_mutex *mutex)
int
os_recursive_mutex_init(korp_mutex *mutex)
{
k_mutex_init(mutex);
return BHT_OK;
}
int os_mutex_destroy(korp_mutex *mutex)
int
os_mutex_destroy(korp_mutex *mutex)
{
(void) mutex;
(void)mutex;
return BHT_OK;
}
int os_mutex_lock(korp_mutex *mutex)
int
os_mutex_lock(korp_mutex *mutex)
{
return k_mutex_lock(mutex, K_FOREVER);
}
int os_mutex_unlock(korp_mutex *mutex)
int
os_mutex_unlock(korp_mutex *mutex)
{
#if KERNEL_VERSION_NUMBER >= 0x020200 /* version 2.2.0 */
return k_mutex_unlock(mutex);
@ -440,21 +462,23 @@ int os_mutex_unlock(korp_mutex *mutex)
#endif
}
int os_cond_init(korp_cond *cond)
int
os_cond_init(korp_cond *cond)
{
k_mutex_init(&cond->wait_list_lock);
cond->thread_wait_list = NULL;
return BHT_OK;
}
int os_cond_destroy(korp_cond *cond)
int
os_cond_destroy(korp_cond *cond)
{
(void) cond;
(void)cond;
return BHT_OK;
}
static int os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex,
bool timed, int mills)
static int
os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed, int mills)
{
os_thread_wait_node *node;
@ -499,12 +523,14 @@ static int os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex,
return BHT_OK;
}
int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
int
os_cond_wait(korp_cond *cond, korp_mutex *mutex)
{
return os_cond_wait_internal(cond, mutex, false, 0);
}
int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
int
os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
{
if (useconds == BHT_WAIT_FOREVER) {
@ -526,7 +552,8 @@ int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds)
}
}
int os_cond_signal(korp_cond *cond)
int
os_cond_signal(korp_cond *cond)
{
/* Signal the head wait node of wait list */
k_mutex_lock(&cond->wait_list_lock, K_FOREVER);
@ -537,13 +564,13 @@ int os_cond_signal(korp_cond *cond)
return BHT_OK;
}
uint8 *os_thread_get_stack_boundary()
uint8 *
os_thread_get_stack_boundary()
{
#if defined(CONFIG_THREAD_STACK_INFO)
korp_tid thread = k_current_get();
return (uint8*)thread->stack_info.start;
return (uint8 *)thread->stack_info.start;
#else
return NULL;
#endif
}

View File

@ -10,4 +10,3 @@ os_time_get_boot_microsecond()
{
return k_uptime_get() * 1000;
}