* @brief Retrieves the value associated with a thread-specific data key for the calling thread. * * This function returns the value that was previously set for the specified key * in the calling thread using `pthread_setspecific`. Each thread has its own independent * value for the same key. * * @param[in] key * The thread-specific data key, created using `pthread_key_create`. * * @re
| 47 | * @see pthread_key_create(), pthread_setspecific(), pthread_key_delete() |
| 48 | */ |
| 49 | void *pthread_getspecific(pthread_key_t key) |
| 50 | { |
| 51 | struct _pthread_data* ptd; |
| 52 | |
| 53 | if (rt_thread_self() == NULL) return NULL; |
| 54 | |
| 55 | /* get pthread data from user data of thread */ |
| 56 | ptd = (_pthread_data_t *)rt_thread_self()->pthread_data; |
| 57 | RT_ASSERT(ptd != NULL); |
| 58 | |
| 59 | if (ptd->tls == NULL) |
| 60 | return NULL; |
| 61 | |
| 62 | if ((key < PTHREAD_KEY_MAX) && (_thread_keys[key].is_used)) |
| 63 | return ptd->tls[key]; |
| 64 | |
| 65 | return NULL; |
| 66 | } |
| 67 | RTM_EXPORT(pthread_getspecific); |
| 68 | |
| 69 | /** |
no test coverage detected