Enable shared memory && add pthread support (#282)

This commit is contained in:
Xu Jun
2020-06-15 19:04:04 +08:00
committed by GitHub
parent f4d4d69736
commit d98ab63e5c
41 changed files with 3081 additions and 289 deletions

View File

@ -242,16 +242,16 @@ os_mutex_destroy(korp_mutex *mutex)
return BHT_OK;
}
void
int
os_mutex_lock(korp_mutex *mutex)
{
aos_mutex_lock(mutex, AOS_WAIT_FOREVER);
return aos_mutex_lock(mutex, AOS_WAIT_FOREVER);
}
void
int
os_mutex_unlock(korp_mutex *mutex)
{
aos_mutex_unlock(mutex);
return aos_mutex_unlock(mutex);
}
int

View File

@ -19,10 +19,12 @@ typedef struct {
static void *os_thread_wrapper(void *arg)
{
thread_wrapper_arg * targ = arg;
thread_start_routine_t start_func = targ->start;
void *thread_arg = targ->arg;
printf("THREAD CREATE %p\n", &targ);
targ->stack = (void *)((uintptr_t)(&arg) & (uintptr_t)~0xfff);
targ->start(targ->arg);
BH_FREE(targ);
start_func(thread_arg);
return NULL;
}
@ -114,7 +116,7 @@ int os_mutex_destroy(korp_mutex *mutex)
locking the mutex indicates some logic error present in
the program somewhere.
Don't try to recover error for an existing unknown error.*/
void os_mutex_lock(korp_mutex *mutex)
int os_mutex_lock(korp_mutex *mutex)
{
int ret;
@ -124,13 +126,14 @@ void os_mutex_lock(korp_mutex *mutex)
printf("vm mutex lock failed (ret=%d)!\n", ret);
exit(-1);
}
return ret;
}
/* Returned error (EINVAL, EAGAIN and EPERM) from
unlocking the mutex indicates some logic error present
in the program somewhere.
Don't try to recover error for an existing unknown error.*/
void os_mutex_unlock(korp_mutex *mutex)
int os_mutex_unlock(korp_mutex *mutex)
{
int ret;
@ -140,6 +143,7 @@ void os_mutex_unlock(korp_mutex *mutex)
printf("vm mutex unlock failed (ret=%d)!\n", ret);
exit(-1);
}
return ret;
}
int os_cond_init(korp_cond *cond)
@ -221,6 +225,16 @@ int os_thread_join(korp_tid thread, void **value_ptr)
return pthread_join(thread, value_ptr);
}
int os_thread_detach(korp_tid thread)
{
return pthread_detach(thread);
}
void os_thread_exit(void *retval)
{
return pthread_exit(retval);
}
uint8 *os_thread_get_stack_boundary()
{
pthread_t self = pthread_self();

View File

@ -68,6 +68,22 @@ int os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
*/
int os_thread_join(korp_tid thread, void **retval);
/**
* Detach the thread specified by thread
*
* @param thread the thread to detach
*
* @return return 0 if success
*/
int os_thread_detach(korp_tid);
/**
* Exit current thread
*
* @param retval the return value of the current thread
*/
void os_thread_exit(void *retval);
/**
* Suspend execution of the calling thread for (at least)
* usec microseconds

View File

@ -82,9 +82,9 @@ int os_mutex_init(korp_mutex *mutex);
int os_mutex_destroy(korp_mutex *mutex);
void os_mutex_lock(korp_mutex *mutex);
int os_mutex_lock(korp_mutex *mutex);
void os_mutex_unlock(korp_mutex *mutex);
int os_mutex_unlock(korp_mutex *mutex);
/**************************************************

View File

@ -24,14 +24,14 @@ int os_mutex_destroy(korp_mutex *mutex)
return BHT_OK;
}
void os_mutex_lock(korp_mutex *mutex)
int os_mutex_lock(korp_mutex *mutex)
{
sgx_thread_mutex_lock(mutex);
return sgx_thread_mutex_lock(mutex);
}
void os_mutex_unlock(korp_mutex *mutex)
int os_mutex_unlock(korp_mutex *mutex)
{
sgx_thread_mutex_unlock(mutex);
return sgx_thread_mutex_unlock(mutex);
}
int os_cond_init(korp_cond *cond)

View File

@ -350,14 +350,14 @@ int os_mutex_destroy(korp_mutex *mutex)
return BHT_OK;
}
void os_mutex_lock(korp_mutex *mutex)
int os_mutex_lock(korp_mutex *mutex)
{
k_mutex_lock(mutex, K_FOREVER);
return k_mutex_lock(mutex, K_FOREVER);
}
void os_mutex_unlock(korp_mutex *mutex)
int os_mutex_unlock(korp_mutex *mutex)
{
k_mutex_unlock(mutex);
return k_mutex_unlock(mutex);
}
int os_cond_init(korp_cond *cond)