Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/src/pthread/keys.c

    rda54714 r9b8be79  
    3636#include <pthread.h>
    3737#include <errno.h>
    38 #include <fibril.h>
    39 #include <stdatomic.h>
    4038#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];
    5539
    5640void *pthread_getspecific(pthread_key_t key)
    5741{
    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;
    6444}
    6545
    6646int pthread_setspecific(pthread_key_t key, const void *data)
    6747{
    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;
    7550}
    7651
    7752int pthread_key_delete(pthread_key_t key)
    7853{
    79         /* see https://github.com/HelenOS/helenos/pull/245#issuecomment-2706795848 */
    8054        not_implemented();
    81         return EOK;
     55        return ENOTSUP;
    8256}
    8357
    8458int pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
    8559{
    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;
    10362}
    10463
Note: See TracChangeset for help on using the changeset viewer.