]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/htl/pt-key.h
hurd: Bump remaining LGPL2+ htl licences to LGPL 2.1+
[thirdparty/glibc.git] / sysdeps / htl / pt-key.h
CommitLineData
33574c17
ST
1/* pthread_key internal declatations for the Hurd version.
2 Copyright (C) 2002-2018 Free Software Foundation, Inc.
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
17 <http://www.gnu.org/licenses/>. */
33574c17
ST
18
19#include <pthread.h>
20#include <libc-lockP.h>
21
22#define PTHREAD_KEY_MEMBERS \
23 void **thread_specifics; /* This is only resized by the thread, and always growing */ \
24 unsigned thread_specifics_size; /* Number of entries in thread_specifics */
25
26#define PTHREAD_KEY_INVALID (void *) (-1)
27
28
29/* __PTHREAD_KEY_DESTRUCTORS is an array of destructors with
30 __PTHREAD_KEY_SIZE elements. If an element with index less than
31 __PTHREAD_KEY_COUNT is invalid, it shall contain the value
32 PTHREAD_KEY_INVALID which shall be distinct from NULL.
33
34 Normally, we just add new keys to the end of the array and realloc
35 it as necessary. The pthread_key_create routine may decide to
36 rescan the array if __PTHREAD_KEY_FREE is large. */
37extern void (**__pthread_key_destructors) (void *arg);
38extern int __pthread_key_size;
39extern int __pthread_key_count;
40/* Number of invalid elements in the array. Does not include elements
41 for which memory has been allocated but which have not yet been
42 used (i.e. those elements with indexes greater than
43 __PTHREAD_KEY_COUNT). */
44extern int __pthread_key_invalid_count;
45
46/* Protects the above variables. This must be a recursive lock: the
47 destructors may call pthread_key_delete. */
48extern pthread_mutex_t __pthread_key_lock;
49\f
50#include <assert.h>
51
52static inline void
53__pthread_key_lock_ready (void)
54{
55 static pthread_once_t o = PTHREAD_ONCE_INIT;
56
57 void do_init (void)
58 {
59 int err;
60 pthread_mutexattr_t attr;
61
62 err = __pthread_mutexattr_init (&attr);
63 assert_perror (err);
64
65 err = __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
66 assert_perror (err);
67
68 err = _pthread_mutex_init (&__pthread_key_lock, &attr);
69 assert_perror (err);
70
71 err = __pthread_mutexattr_destroy (&attr);
72 assert_perror (err);
73 }
74
75 __pthread_once (&o, do_init);
76}