riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022)
[glibc.git] / sysdeps / htl / pt-key.h
blob047b7e24ba4beb86c58f8f850274ef496d0c4ad3
1 /* pthread_key internal declarations for the Hurd version.
2 Copyright (C) 2002-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <pthread.h>
20 #include <libc-lockP.h>
21 #include <pthreadP.h>
23 /* When using e.g. jemalloc, we need to be able to create and use keys before
24 being able to allocate. */
25 #define PTHREAD_STATIC_KEYS 4
27 #define PTHREAD_KEY_MEMBERS \
28 void **thread_specifics; /* This is only resized by the thread, and always growing */ \
29 unsigned thread_specifics_size; /* Number of entries in thread_specifics */ \
30 void *static_thread_specifics[PTHREAD_STATIC_KEYS]; /* Static storage for a few entries */
32 #define PTHREAD_KEY_INVALID (void *) (-1)
35 /* __PTHREAD_KEY_DESTRUCTORS is an array of destructors with
36 __PTHREAD_KEY_SIZE elements. If an element with index less than
37 __PTHREAD_KEY_COUNT is invalid, it shall contain the value
38 PTHREAD_KEY_INVALID which shall be distinct from NULL.
40 Normally, we just add new keys to the end of the array and realloc
41 it as necessary. The pthread_key_create routine may decide to
42 rescan the array if __PTHREAD_KEY_FREE is large. */
43 extern void (**__pthread_key_destructors) (void *arg);
44 extern int __pthread_key_size;
45 extern int __pthread_key_count;
46 /* Number of invalid elements in the array. Does not include elements
47 for which memory has been allocated but which have not yet been
48 used (i.e. those elements with indexes greater than
49 __PTHREAD_KEY_COUNT). */
50 extern int __pthread_key_invalid_count;
52 /* Protects the above variables. This must be a recursive lock: the
53 destructors may call pthread_key_delete. */
54 extern pthread_mutex_t __pthread_key_lock;
56 /* Protects the initialization of the mutex above. */
57 extern pthread_once_t __pthread_key_once;
59 #include <assert.h>
61 static inline void
62 __pthread_key_lock_ready (void)
64 void do_init (void)
66 int err;
67 pthread_mutexattr_t attr;
69 err = __pthread_mutexattr_init (&attr);
70 assert_perror (err);
72 err = __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
73 assert_perror (err);
75 err = __pthread_mutex_init (&__pthread_key_lock, &attr);
76 assert_perror (err);
78 err = __pthread_mutexattr_destroy (&attr);
79 assert_perror (err);
82 __pthread_once (&__pthread_key_once, do_init);