Changes in uspace/lib/posix/src/pthread/keys.c [da54714:9b8be79] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/src/pthread/keys.c
rda54714 r9b8be79 36 36 #include <pthread.h> 37 37 #include <errno.h> 38 #include <fibril.h>39 #include <stdatomic.h>40 38 #include "../internal/common.h" 41 42 #include <stdio.h>43 #define DPRINTF(format, ...) ((void) 0);44 45 static atomic_ushort next_key = 1; // skip the key 'zero'46 47 /*48 * For now, we just support maximum of 100 keys. This can be improved49 * in the future by implementing a dynamically growing array with50 * reallocations, but that will require more synchronization.51 */52 #define PTHREAD_KEYS_MAX 10053 54 static fibril_local void *key_data[PTHREAD_KEYS_MAX];55 39 56 40 void *pthread_getspecific(pthread_key_t key) 57 41 { 58 assert(key < PTHREAD_KEYS_MAX); 59 assert(key < next_key); 60 assert(key > 0); 61 62 DPRINTF("pthread_getspecific(%d) = %p\n", key, key_data[key]); 63 return key_data[key]; 42 not_implemented(); 43 return NULL; 64 44 } 65 45 66 46 int pthread_setspecific(pthread_key_t key, const void *data) 67 47 { 68 DPRINTF("pthread_setspecific(%d, %p)\n", key, data); 69 assert(key < PTHREAD_KEYS_MAX); 70 assert(key < next_key); 71 assert(key > 0); 72 73 key_data[key] = (void *) data; 74 return EOK; 48 not_implemented(); 49 return ENOTSUP; 75 50 } 76 51 77 52 int pthread_key_delete(pthread_key_t key) 78 53 { 79 /* see https://github.com/HelenOS/helenos/pull/245#issuecomment-2706795848 */80 54 not_implemented(); 81 return E OK;55 return ENOTSUP; 82 56 } 83 57 84 58 int pthread_key_create(pthread_key_t *key, void (*destructor)(void *)) 85 59 { 86 unsigned short k = atomic_fetch_add(&next_key, 1); 87 DPRINTF("pthread_key_create(%p, %p) = %d\n", key, destructor, k); 88 if (k >= PTHREAD_KEYS_MAX) { 89 atomic_store(&next_key, PTHREAD_KEYS_MAX + 1); 90 return ELIMIT; 91 } 92 if (destructor != NULL) { 93 /* Inlined not_implemented() macro to add custom message */ 94 static int __not_implemented_counter = 0; 95 if (__not_implemented_counter == 0) { 96 fprintf(stderr, "pthread_key_create: destructors not supported\n"); 97 } 98 __not_implemented_counter++; 99 } 100 101 *key = k; 102 return EOK; 60 not_implemented(); 61 return ENOTSUP; 103 62 } 104 63
Note:
See TracChangeset
for help on using the changeset viewer.