1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** POSIX wrapper for THREADX */
16 /** */
17 /** */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 /* Include necessary system files. */
23
24 #include "tx_api.h" /* Threadx API */
25 #include "pthread.h" /* Posix API */
26 #include "px_int.h" /* Posix helper functions */
27
28
29 /**************************************************************************/
30 /* */
31 /* FUNCTION RELEASE */
32 /* */
33 /* pthread_self PORTABLE C */
34 /* 6.1.7 */
35 /* AUTHOR */
36 /* */
37 /* William E. Lamie, Microsoft Corporation */
38 /* */
39 /* DESCRIPTION */
40 /* */
41 /* */
42 /* This function returns thread ID of the calling pthread . */
43 /* */
44 /* */
45 /* */
46 /* */
47 /* INPUT */
48 /* */
49 /* Nothing */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* thread_ID pthread handle of the calling thread */
54 /* */
55 /* CALLS */
56 /* */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* Application Code */
61 /* */
62 /* RELEASE HISTORY */
63 /* */
64 /* DATE NAME DESCRIPTION */
65 /* */
66 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
67 /* */
68 /**************************************************************************/
pthread_self(VOID)69 pthread_t pthread_self(VOID)
70 {
71
72 TX_THREAD *thread_ptr;
73 pthread_t thread_ID;
74
75 /* Get the thread identifier of the currently running thread */
76 thread_ptr = tx_thread_identify();
77
78 /* Convert thread identifier to posix thread ID */
79
80 thread_ID = posix_thread2tid(thread_ptr);
81
82 /* Determine if this thread is actually the signal thread helper. */
83 if (((POSIX_TCB *) thread_ptr) -> signals.signal_handler)
84 {
85
86 /* Yes, override the thread_ID with the non-signal thread ID. */
87 thread_ID = (pthread_t) ((POSIX_TCB *) thread_ptr) -> signals.base_thread_ptr;
88 }
89
90
91 /* All done. */
92 return(thread_ID);
93 }
94