* @brief Creates a thread-specific data key. * * This function allocates a unique key for thread-specific data (TSD). * Each thread can use this key to access its own specific data associated with it. * * @param[out] key * A pointer to a variable where the newly created key will be stored. * On success, `*key` will hold the newly allocated key. * @param[in] destructor * An opt
| 154 | * @see pthread_setspecific(), pthread_getspecific(), pthread_key_delete() |
| 155 | */ |
| 156 | int pthread_key_create(pthread_key_t *key, void (*destructor)(void*)) |
| 157 | { |
| 158 | rt_uint32_t index; |
| 159 | |
| 160 | rt_enter_critical(); |
| 161 | for (index = 0; index < PTHREAD_KEY_MAX; index ++) |
| 162 | { |
| 163 | if (_thread_keys[index].is_used == 0) |
| 164 | { |
| 165 | _thread_keys[index].is_used = 1; |
| 166 | _thread_keys[index].destructor = destructor; |
| 167 | |
| 168 | *key = index; |
| 169 | |
| 170 | rt_exit_critical(); |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | rt_exit_critical(); |
| 177 | |
| 178 | return EAGAIN; |
| 179 | } |
| 180 | RTM_EXPORT(pthread_key_create); |
| 181 | |
| 182 | /** |
no test coverage detected