Lines Matching +full:key +full:- +full:int

5  * SPDX-License-Identifier: Apache-2.0
20 /* This is non-standard (i.e. an implementation detail) */
21 #define PTHREAD_KEY_INITIALIZER (-1)
36 return k - posix_key_pool; in posix_key_to_offset()
39 static inline size_t to_posix_key_idx(pthread_key_t key) in to_posix_key_idx() argument
41 return mark_pthread_obj_uninitialized(key); in to_posix_key_idx()
44 static pthread_key_obj *get_posix_key(pthread_key_t key) in get_posix_key() argument
46 int actually_initialized; in get_posix_key()
47 size_t bit = to_posix_key_idx(key); in get_posix_key()
50 if (!is_pthread_obj_initialized(key)) { in get_posix_key()
51 LOG_DBG("Key is uninitialized (%x)", key); in get_posix_key()
57 LOG_DBG("Key is invalid (%x)", key); in get_posix_key()
63 LOG_DBG("Key claims to be initialized (%x)", key); in get_posix_key()
70 static pthread_key_obj *to_posix_key(pthread_key_t *key) in to_posix_key() argument
75 if (*key != PTHREAD_KEY_INITIALIZER) { in to_posix_key()
76 return get_posix_key(*key); in to_posix_key()
86 *key = mark_pthread_obj_initialized(bit); in to_posix_key()
96 * @brief Create a key for thread-specific data
100 int pthread_key_create(pthread_key_t *key, in pthread_key_create() argument
105 *key = PTHREAD_KEY_INITIALIZER; in pthread_key_create()
106 new_key = to_posix_key(key); in pthread_key_create()
111 sys_slist_init(&(new_key->key_data_l)); in pthread_key_create()
113 new_key->destructor = destructor; in pthread_key_create()
114 LOG_DBG("Initialized key %p (%x)", new_key, *key); in pthread_key_create()
120 * @brief Delete a key for thread-specific data
124 int pthread_key_delete(pthread_key_t key) in pthread_key_delete() argument
127 int ret = EINVAL; in pthread_key_delete()
133 key_obj = get_posix_key(key); in pthread_key_delete()
139 /* Delete thread-specific elements associated with the key */ in pthread_key_delete()
140 SYS_SLIST_FOR_EACH_NODE_SAFE(&(key_obj->key_data_l), node_l, next_node_l) { in pthread_key_delete()
143 key_data = (struct pthread_key_data *)sys_slist_get(&(key_obj->key_data_l)); in pthread_key_delete()
147 LOG_DBG("Freed key data %p for key %x in thread %x", key_data, key, in pthread_key_delete()
157 LOG_DBG("Deleted key %p (%x)", key_obj, key); in pthread_key_delete()
164 * @brief Associate a thread-specific value with a key
168 int pthread_setspecific(pthread_key_t key, const void *value) in pthread_setspecific() argument
174 int retval = 0; in pthread_setspecific()
181 /* Traverse the list of keys set by the thread, looking for key. in pthread_setspecific()
182 * If the key is already in the list, re-assign its value. in pthread_setspecific()
183 * Else add the key to the thread's list. in pthread_setspecific()
186 key_obj = get_posix_key(key); in pthread_setspecific()
192 SYS_SLIST_FOR_EACH_NODE(&(thread->key_list), node_l) { in pthread_setspecific()
195 if (thread_spec_data->key == key_obj) { in pthread_setspecific()
196 /* Key is already present so associate thread specific data */ in pthread_setspecific()
197 thread_spec_data->spec_data = (void *)value; in pthread_setspecific()
198 LOG_DBG("Paired key %x to value %p for thread %x", key, value, in pthread_setspecific()
206 /* Key is already present, so we are done */ in pthread_setspecific()
210 /* Key and data need to be added */ in pthread_setspecific()
214 LOG_DBG("Failed to allocate key data for key %x", key); in pthread_setspecific()
219 LOG_DBG("Allocated key data %p for key %x in thread %x", key_data, key, in pthread_setspecific()
222 /* Associate thread specific data, initialize new key */ in pthread_setspecific()
223 key_data->thread_data.key = key_obj; in pthread_setspecific()
224 key_data->thread_data.spec_data = (void *)value; in pthread_setspecific()
226 /* Append new thread key data to thread's key list */ in pthread_setspecific()
227 sys_slist_append((&thread->key_list), (sys_snode_t *)(&key_data->thread_data)); in pthread_setspecific()
229 /* Append new key data to the key object's list */ in pthread_setspecific()
230 sys_slist_append(&(key_obj->key_data_l), (sys_snode_t *)key_data); in pthread_setspecific()
232 LOG_DBG("Paired key %x to value %p for thread %x", key, value, pthread_self()); in pthread_setspecific()
239 * @brief Get the thread-specific value associated with the key
243 void *pthread_getspecific(pthread_key_t key) in pthread_getspecific() argument
257 key_obj = get_posix_key(key); in pthread_getspecific()
263 /* Traverse the list of keys set by the thread, looking for key */ in pthread_getspecific()
265 SYS_SLIST_FOR_EACH_NODE(&(thread->key_list), node_l) { in pthread_getspecific()
267 if (thread_spec_data->key == key_obj) { in pthread_getspecific()
268 /* Key is present, so get the set thread data */ in pthread_getspecific()
269 value = thread_spec_data->spec_data; in pthread_getspecific()