Changeset da54714 in mainline for uspace/lib/posix/src/pthread/keys.c
- Timestamp:
- 2025-03-11T10:50:28Z (30 hours ago)
- Branches:
- master
- Parents:
- 0ae9e18
- git-author:
- Matěj Volf <git@…> (2025-03-11 10:50:28)
- git-committer:
- GitHub <noreply@…> (2025-03-11 10:50:28)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/src/pthread/keys.c
r0ae9e18 rda54714 36 36 #include <pthread.h> 37 37 #include <errno.h> 38 #include <fibril.h> 39 #include <stdatomic.h> 38 40 #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 improved 49 * in the future by implementing a dynamically growing array with 50 * reallocations, but that will require more synchronization. 51 */ 52 #define PTHREAD_KEYS_MAX 100 53 54 static fibril_local void *key_data[PTHREAD_KEYS_MAX]; 39 55 40 56 void *pthread_getspecific(pthread_key_t key) 41 57 { 42 not_implemented(); 43 return NULL; 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]; 44 64 } 45 65 46 66 int pthread_setspecific(pthread_key_t key, const void *data) 47 67 { 48 not_implemented(); 49 return ENOTSUP; 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; 50 75 } 51 76 52 77 int pthread_key_delete(pthread_key_t key) 53 78 { 79 /* see https://github.com/HelenOS/helenos/pull/245#issuecomment-2706795848 */ 54 80 not_implemented(); 55 return E NOTSUP;81 return EOK; 56 82 } 57 83 58 84 int pthread_key_create(pthread_key_t *key, void (*destructor)(void *)) 59 85 { 60 not_implemented(); 61 return ENOTSUP; 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; 62 103 } 63 104
Note:
See TracChangeset
for help on using the changeset viewer.