MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pthread_key_create

Function pthread_key_create

components/libc/posix/pthreads/pthread_tls.c:156–179  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

154 * @see pthread_setspecific(), pthread_getspecific(), pthread_key_delete()
155 */
156int 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}
180RTM_EXPORT(pthread_key_create);
181
182/**

Callers 4

emutls_initFunction · 0.85
__cxa_thread_atexit_implFunction · 0.85
__ARM_TPL_tls_createFunction · 0.85
str_alloc_keyFunction · 0.85

Calls 2

rt_enter_criticalFunction · 0.50
rt_exit_criticalFunction · 0.50

Tested by

no test coverage detected