]>
Commit | Line | Data |
---|---|---|
33574c17 | 1 | /* pthread_key internal declatations for the Hurd version. |
2b778ceb | 2 | Copyright (C) 2002-2021 Free Software Foundation, Inc. |
33574c17 ST |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
ad2b41bf ST |
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. | |
33574c17 ST |
9 | |
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 | |
ad2b41bf | 13 | Lesser General Public License for more details. |
33574c17 | 14 | |
ad2b41bf ST |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
33574c17 ST |
18 | |
19 | #include <pthread.h> | |
20 | #include <libc-lockP.h> | |
f6fb29d2 | 21 | #include <pthreadP.h> |
33574c17 ST |
22 | |
23 | #define PTHREAD_KEY_MEMBERS \ | |
24 | void **thread_specifics; /* This is only resized by the thread, and always growing */ \ | |
25 | unsigned thread_specifics_size; /* Number of entries in thread_specifics */ | |
26 | ||
27 | #define PTHREAD_KEY_INVALID (void *) (-1) | |
28 | ||
29 | ||
30 | /* __PTHREAD_KEY_DESTRUCTORS is an array of destructors with | |
31 | __PTHREAD_KEY_SIZE elements. If an element with index less than | |
32 | __PTHREAD_KEY_COUNT is invalid, it shall contain the value | |
33 | PTHREAD_KEY_INVALID which shall be distinct from NULL. | |
34 | ||
35 | Normally, we just add new keys to the end of the array and realloc | |
36 | it as necessary. The pthread_key_create routine may decide to | |
37 | rescan the array if __PTHREAD_KEY_FREE is large. */ | |
38 | extern void (**__pthread_key_destructors) (void *arg); | |
39 | extern int __pthread_key_size; | |
40 | extern int __pthread_key_count; | |
41 | /* Number of invalid elements in the array. Does not include elements | |
42 | for which memory has been allocated but which have not yet been | |
43 | used (i.e. those elements with indexes greater than | |
44 | __PTHREAD_KEY_COUNT). */ | |
45 | extern int __pthread_key_invalid_count; | |
46 | ||
47 | /* Protects the above variables. This must be a recursive lock: the | |
48 | destructors may call pthread_key_delete. */ | |
49 | extern pthread_mutex_t __pthread_key_lock; | |
50 | \f | |
51 | #include <assert.h> | |
52 | ||
53 | static inline void | |
54 | __pthread_key_lock_ready (void) | |
55 | { | |
56 | static pthread_once_t o = PTHREAD_ONCE_INIT; | |
57 | ||
58 | void do_init (void) | |
59 | { | |
60 | int err; | |
61 | pthread_mutexattr_t attr; | |
62 | ||
63 | err = __pthread_mutexattr_init (&attr); | |
64 | assert_perror (err); | |
65 | ||
66 | err = __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); | |
67 | assert_perror (err); | |
68 | ||
e775f443 | 69 | err = __pthread_mutex_init (&__pthread_key_lock, &attr); |
33574c17 ST |
70 | assert_perror (err); |
71 | ||
72 | err = __pthread_mutexattr_destroy (&attr); | |
73 | assert_perror (err); | |
74 | } | |
75 | ||
76 | __pthread_once (&o, do_init); | |
77 | } |