1 /* 2 * Copyright (c) 2023, Meta 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <errno.h> 8 #include <threads.h> 9 10 #include <zephyr/kernel.h> 11 #include <zephyr/posix/pthread.h> 12 tss_create(tss_t * key,tss_dtor_t destructor)13int tss_create(tss_t *key, tss_dtor_t destructor) 14 { 15 switch (pthread_key_create(key, destructor)) { 16 case 0: 17 return thrd_success; 18 case EAGAIN: 19 return thrd_busy; 20 case ENOMEM: 21 return thrd_nomem; 22 default: 23 return thrd_error; 24 } 25 } 26 tss_get(tss_t key)27void *tss_get(tss_t key) 28 { 29 return pthread_getspecific(key); 30 } 31 tss_set(tss_t key,void * val)32int tss_set(tss_t key, void *val) 33 { 34 switch (pthread_setspecific(key, val)) { 35 case 0: 36 return thrd_success; 37 case ENOMEM: 38 return thrd_nomem; 39 default: 40 return thrd_error; 41 } 42 } 43 tss_delete(tss_t key)44void tss_delete(tss_t key) 45 { 46 (void)pthread_key_delete(key); 47 } 48