1 /* Copyright (C) 2002-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
21 #include <shlib-compat.h>
24 ___pthread_setspecific (pthread_key_t key
, const void *value
)
29 struct pthread_key_data
*level2
;
34 /* Special case access to the first 2nd-level block. This is the
36 if (__glibc_likely (key
< PTHREAD_KEY_2NDLEVEL_SIZE
))
38 /* Verify the key is sane. */
39 if (KEY_UNUSED ((seq
= __pthread_keys
[key
].seq
)))
43 level2
= &self
->specific_1stblock
[key
];
45 /* Remember that we stored at least one set of data. */
47 THREAD_SETMEM (self
, specific_used
, true);
51 if (key
>= PTHREAD_KEYS_MAX
52 || KEY_UNUSED ((seq
= __pthread_keys
[key
].seq
)))
56 idx1st
= key
/ PTHREAD_KEY_2NDLEVEL_SIZE
;
57 idx2nd
= key
% PTHREAD_KEY_2NDLEVEL_SIZE
;
59 /* This is the second level array. Allocate it if necessary. */
60 level2
= THREAD_GETMEM_NC (self
, specific
, idx1st
);
64 /* We don't have to do anything. The value would in any case
65 be NULL. We can save the memory allocation. */
69 = (struct pthread_key_data
*) calloc (PTHREAD_KEY_2NDLEVEL_SIZE
,
74 THREAD_SETMEM_NC (self
, specific
, idx1st
, level2
);
77 /* Pointer to the right array element. */
78 level2
= &level2
[idx2nd
];
80 /* Remember that we stored at least one set of data. */
81 THREAD_SETMEM (self
, specific_used
, true);
84 /* Store the data and the sequence number so that we can recognize
87 level2
->data
= (void *) value
;
91 versioned_symbol (libc
, ___pthread_setspecific
, pthread_setspecific
,
93 libc_hidden_ver (___pthread_setspecific
, __pthread_setspecific
)
95 strong_alias (___pthread_setspecific
, __pthread_setspecific
)
98 #if OTHER_SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_34)
99 compat_symbol (libpthread
, ___pthread_setspecific
, __pthread_setspecific
,
101 compat_symbol (libpthread
, ___pthread_setspecific
, pthread_setspecific
,