Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pthread: add pthread_self/pthread_gettid_np function #12561

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down
2 changes: 2 additions & 0 deletions libs/libc/libc.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 *"
Expand All @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion libs/libc/pthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions libs/libc/pthread/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions libs/libc/pthread/pthread_gettid_np.c
Original file line number Diff line number Diff line change
@@ -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 changes: 48 additions & 0 deletions libs/libc/pthread/pthread_self.c
Original file line number Diff line number Diff line change
@@ -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