mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 08:38:38 +08:00
pthread: add pthread_self/pthread_gettid_np function
explicitly defined functions can support assignment as function pointers Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
parent
c3b05bde44
commit
e14ae3e681
6 changed files with 104 additions and 3 deletions
|
@ -563,8 +563,8 @@ void pthread_yield(void);
|
|||
|
||||
/* A thread may obtain a copy of its own thread handle. */
|
||||
|
||||
#define pthread_self() ((pthread_t)gettid())
|
||||
#define pthread_gettid_np(thread) ((pid_t)(thread))
|
||||
pthread_t pthread_self(void);
|
||||
pid_t pthread_gettid_np(pthread_t thread);
|
||||
|
||||
/* Compare two thread IDs. */
|
||||
|
||||
|
|
|
@ -214,6 +214,7 @@
|
|||
"pthread_create","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_t *","FAR const pthread_attr_t *","pthread_startroutine_t","pthread_addr_t"
|
||||
"pthread_getname_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","char *","size_t"
|
||||
"pthread_getspecific","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && CONFIG_TLS_NELEM > 0","FAR void *","pthread_key_t"
|
||||
"pthread_gettid_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","pid_t","pthread_t"
|
||||
"pthread_key_create","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && CONFIG_TLS_NELEM > 0","int","FAR pthread_key_t *","FAR void (*) (void *)|FAR void *"
|
||||
"pthread_key_delete","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && CONFIG_TLS_NELEM > 0","int","pthread_key_t"
|
||||
"pthread_mutex_lock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t *"
|
||||
|
@ -228,6 +229,7 @@
|
|||
"pthread_rwlock_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_rwlock_t *restrict","FAR const pthread_rwlockattr_t *"
|
||||
"pthread_rwlock_rdlock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_rwlock_t *"
|
||||
"pthread_rwlock_unlock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_rwlock_t *"
|
||||
"pthread_self","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","pthread_t","void"
|
||||
"pthread_setname_np","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","const char *"
|
||||
"pthread_setspecific","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && CONFIG_TLS_NELEM > 0","int","pthread_key_t","FAR const void *"
|
||||
"pthread_yield","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","void"
|
||||
|
|
Can't render this file because it has a wrong number of fields in line 3.
|
|
@ -93,7 +93,9 @@ if(NOT CONFIG_DISABLE_PTHREAD)
|
|||
pthread_setcancelstate.c
|
||||
pthread_setcanceltype.c
|
||||
pthread_testcancel.c
|
||||
pthread_getcpuclockid.c)
|
||||
pthread_getcpuclockid.c
|
||||
pthread_self.c
|
||||
pthread_gettid_np.c)
|
||||
|
||||
if(CONFIG_SMP)
|
||||
list(APPEND SRCS pthread_attr_getaffinity.c pthread_attr_setaffinity.c)
|
||||
|
|
|
@ -58,6 +58,7 @@ CSRCS += pthread_rwlockattr_getpshared.c pthread_rwlockattr_setpshared.c
|
|||
CSRCS += pthread_rwlock.c pthread_rwlock_rdlock.c pthread_rwlock_wrlock.c
|
||||
CSRCS += pthread_setcancelstate.c pthread_setcanceltype.c
|
||||
CSRCS += pthread_testcancel.c pthread_getcpuclockid.c
|
||||
CSRCS += pthread_self.c pthread_gettid_np.c
|
||||
|
||||
ifeq ($(CONFIG_SMP),y)
|
||||
CSRCS += pthread_attr_getaffinity.c pthread_attr_setaffinity.c
|
||||
|
|
48
libs/libc/pthread/pthread_gettid_np.c
Normal file
48
libs/libc/pthread/pthread_gettid_np.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/pthread/pthread_gettid_np.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pthread_gettid_np
|
||||
*
|
||||
* Description:
|
||||
* Return the thread ID of the specified thread.
|
||||
*
|
||||
* Input Parameters:
|
||||
* thread - The thread for which to return the thread ID
|
||||
*
|
||||
* Returned Value:
|
||||
* The ID of the thread.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
pid_t pthread_gettid_np(pthread_t thread)
|
||||
{
|
||||
return (pid_t)thread;
|
||||
}
|
48
libs/libc/pthread/pthread_self.c
Normal file
48
libs/libc/pthread/pthread_self.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/pthread/pthread_self.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pthread_self
|
||||
*
|
||||
* Description:
|
||||
* Return the thread ID of the calling thread.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* ID of the calling thread.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
pthread_t pthread_self(void)
|
||||
{
|
||||
return (pthread_t)gettid();
|
||||
}
|
Loading…
Reference in a new issue