add musl for XiUOS, support arm32 and riscv64 from Tu_yuyang

it is OK
This commit is contained in:
xuedongliang
2022-08-01 19:58:58 +08:00
595 changed files with 42447 additions and 176 deletions

View File

@@ -101,12 +101,12 @@ int PrivTaskDelay(int32_t ms)
{
UserTaskDelay(ms);
}
#ifndef SEPARATE_COMPILE
uint32_t PrivGetTickTime()
{
return CalculteTimeMsFromTick(CurrentTicksGain());
}
#endif
/*********************fs**************************/
#ifdef FS_VFS
/************************Driver Posix Transform***********************/

View File

@@ -22,6 +22,7 @@
#define TRANSFORM_H
#include <pthread.h>
#include <signal.h>
#include <semaphore.h>
#include <stddef.h>
#include <stdint.h>

View File

@@ -29,10 +29,10 @@ extern "C" {
#include <time.h>
#include <sys/time.h>
#if defined(ARCH_ARM)
#if defined(ARCH_ARM) && !defined(LIB_MUSLLIB)
#include "pthread arm.h"
#endif
// enum {
// PTHREAD_BARRIER_SERIAL_THREAD,
// PTHREAD_CANCEL_ASYNCHRONOUS,
@@ -94,7 +94,7 @@ int pthread_setname_np(pthread_t thread, const char *name);
int pthread_timedjoin_np(pthread_t thread, void **retval, const struct timespec *abstime);
/* function in pthread_mutex.c */
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
int pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attr);
int pthread_mutex_destroy(pthread_mutex_t *mutex);
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);
@@ -105,7 +105,7 @@ int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type);
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);
int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared);
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared);
#ifdef __cplusplus
}

View File

@@ -49,8 +49,8 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
return -1 ;
ret = UserTaskStartup(pid);
*thread = pid;
*thread = (pthread_t)(long)pid;
return ret;
}
@@ -63,7 +63,7 @@ void pthread_exit(void *value_ptr){
pthread_t pthread_self(void){
pthread_t pthread ;
pthread = UserGetTaskID();
pthread = (pthread_t)(long)UserGetTaskID();
return pthread;
}
@@ -112,7 +112,8 @@ int pthread_join(pthread_t thread, void **retval)
int pthread_kill(pthread_t thread, int sig)
{
/* This api should not be used, and will not be supported */
UserTaskDelete(thread);
int32_t *thread_id_tmp = (void *)&thread;
UserTaskDelete(*thread_id_tmp);
return -1;
}

View File

@@ -21,7 +21,118 @@
#include <time.h>
#include "include/pthread.h"
#include <pthread.h>
#include <string.h>
// #if defined(ARCH_ARM) && defined(LIB_MUSLLIB)
#if defined(LIB_MUSLLIB)
int pthread_mutex_init(pthread_mutex_t* p_mutex, const pthread_mutexattr_t* attr)
{
pthread_mutexattr_t mutexAttr;
uint32_t mutex_handle;
// check p_mutex
if (p_mutex == NULL) {
return EINVAL;
}
// set attr
if (attr == NULL) {
pthread_mutexattr_init(&mutexAttr);
}
else {
mutexAttr = *attr;
}
// create mutex
mutex_handle = UserMutexCreate();
if (mutex_handle < 0) {
return mutex_handle;
}
p_mutex->stAttr = mutexAttr;
p_mutex->magic = _MUX_MAGIC;
p_mutex->handle = mutex_handle;
return 0;
}
int pthread_mutex_destroy(pthread_mutex_t *p_mutex)
{
if ((p_mutex == NULL) || (p_mutex->magic != _MUX_MAGIC)) {
return EINVAL;
}
UserMutexDelete(p_mutex->handle);
p_mutex->handle = _MUX_INVALID_HANDLE;
p_mutex->magic = 0;
return 0;
}
int pthread_mutex_lock(pthread_mutex_t *p_mutex)
{
if ((p_mutex == NULL) || (p_mutex->magic != _MUX_MAGIC) ||
(p_mutex->handle == _MUX_INVALID_HANDLE)) {
return EINVAL;
}
return UserMutexObtain(p_mutex->handle, WAITING_FOREVER);
}
int pthread_mutex_unlock(pthread_mutex_t *p_mutex)
{
if ((p_mutex == NULL) || (p_mutex->magic != _MUX_MAGIC) ||
(p_mutex->handle == _MUX_INVALID_HANDLE)) {
return EINVAL;
}
return UserMutexAbandon(p_mutex->handle);
}
int pthread_mutex_trylock(pthread_mutex_t *p_mutex)
{
if ((p_mutex == NULL) || (p_mutex->magic != _MUX_MAGIC) ||
(p_mutex->handle == _MUX_INVALID_HANDLE)) {
return EINVAL;
}
return UserMutexObtain(p_mutex->handle , 0);
}
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
{
if (attr == NULL) {
return EINVAL;
}
attr->type = PTHREAD_MUTEX_DEFAULT;
return 0;
}
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
{
if (attr == NULL) {
return EINVAL;
}
memset(attr, 0, sizeof(pthread_mutexattr_t));
return 0;
}
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type)
{
if (attr == NULL) {
return EINVAL;
}
*type = attr->type;
return 0;
}
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
{
if (attr == NULL) {
return EINVAL;
}
attr->type = type;
return 0;
}
#else
int pthread_mutex_init(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr)
{
*p_mutex = UserMutexCreate();
@@ -82,9 +193,11 @@ int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
return 0;
}
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict attr, int *restrict protocol)
{
#endif
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t* restrict attr, int* restrict protocol)
{
return 0;
}
@@ -118,7 +231,7 @@ int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
return 0;
}
int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared)
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared)
{
return 0;
}