libc: Move pthread_create to user space

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Change-Id: I5c447d94077debc79158686935f288e4c8e51e01
This commit is contained in:
Gregory Nutt
2020-06-29 08:26:29 -06:00
committed by patacongo
parent a876f0253a
commit bb9b58bdde
50 changed files with 239 additions and 269 deletions
+5 -9
View File
@@ -38,19 +38,20 @@ CSRCS += pthread_barrierattr_init.c pthread_barrierattr_destroy.c
CSRCS += pthread_barrierattr_getpshared.c pthread_barrierattr_setpshared.c
CSRCS += pthread_barrierinit.c pthread_barrierdestroy.c pthread_barrierwait.c
CSRCS += pthread_condattr_init.c pthread_condattr_destroy.c
CSRCS += pthread_condattr_setclock.c pthread_condattr_getclock.c
CSRCS += pthread_condinit.c pthread_conddestroy.c pthread_condtimedwait.c
CSRCS += pthread_create.c
CSRCS += pthread_get_stackaddr_np.c pthread_get_stacksize_np.c
CSRCS += pthread_mutexattr_init.c pthread_mutexattr_destroy.c
CSRCS += pthread_mutexattr_getpshared.c pthread_mutexattr_setpshared.c
CSRCS += pthread_mutexattr_setprotocol.c pthread_mutexattr_getprotocol.c
CSRCS += pthread_mutexattr_settype.c pthread_mutexattr_gettype.c
CSRCS += pthread_mutexattr_setrobust.c pthread_mutexattr_getrobust.c
CSRCS += pthread_mutex_lock.c
CSRCS += pthread_once.c pthread_yield.c
CSRCS += pthread_rwlock.c pthread_rwlock_rdlock.c pthread_rwlock_wrlock.c
CSRCS += pthread_setcancelstate.c pthread_setcanceltype.c
CSRCS += pthread_testcancel.c
CSRCS += pthread_rwlock.c pthread_rwlock_rdlock.c pthread_rwlock_wrlock.c
CSRCS += pthread_once.c pthread_yield.c
CSRCS += pthread_get_stackaddr_np.c pthread_get_stacksize_np.c
CSRCS += pthread_condattr_setclock.c pthread_condattr_getclock.c
ifeq ($(CONFIG_SMP),y)
CSRCS += pthread_attr_getaffinity.c pthread_attr_setaffinity.c
@@ -60,14 +61,9 @@ ifeq ($(CONFIG_PTHREAD_SPINLOCKS),y)
CSRCS += pthread_spinlock.c
endif
ifeq ($(CONFIG_BUILD_PROTECTED),y)
CSRCS += pthread_startup.c
endif
endif # CONFIG_DISABLE_PTHREAD
# Add the pthread directory to the build
DEPPATH += --dep-path pthread
VPATH += :pthread
@@ -1,5 +1,5 @@
/****************************************************************************
* libs/libc/pthread/pthread_startup.c
* libs/libc/pthread/pthread_create.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -24,70 +24,68 @@
#include <nuttx/config.h>
#include <pthread.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/userspace.h>
#if !defined(CONFIG_BUILD_FLAT) && !defined(__KERNEL__)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
#include <nuttx/pthread.h>
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pthread_startup
*
* Description:
* This function is the user-space, pthread startup function. It is called
* from up_pthread_start() in user-mode.
* This function is the user space pthread startup function. Its purpose
* is to catch the return from the pthread main function so that
* pthread_exit() can be called from user space
*
* Input Parameters:
* entrypt - The user-space address of the pthread entry point
* arg - Standard argument for the pthread entry point
* entry - The user-space address of the pthread entry point
* arg - Standard argument for the pthread entry point
*
* Returned Value:
* None. This function does not return.
*
****************************************************************************/
void pthread_startup(pthread_startroutine_t entrypt, pthread_addr_t arg)
static void pthread_startup(pthread_startroutine_t entry,
pthread_addr_t arg)
{
pthread_addr_t exit_status;
DEBUGASSERT(entry != NULL);
DEBUGASSERT(entrypt);
/* Pass control to the thread entry point. Handle any returned value. */
/* Pass control to the thread entry point. */
exit_status = entrypt(arg);
/* The pthread has returned */
pthread_exit(exit_status);
pthread_exit(entry(arg));
}
#endif /* !CONFIG_BUILD_FLAT && !__KERNEL__ */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pthread_create
*
* Description:
* This function creates and activates a new thread with specified
* attributes. It is simply a wrapper around the nx_pthread_create system
* call.
*
* Input Parameters:
* thread
* attr
* pthread_entry
* arg
*
* Returned Value:
* OK (0) on success; a (non-negated) errno value on failure. The errno
* variable is not set.
*
****************************************************************************/
int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
pthread_startroutine_t pthread_entry, pthread_addr_t arg)
{
return nx_pthread_create(pthread_startup, thread, attr, pthread_entry,
arg);
}