1 /* Get a thread-specific data pointer for a thread.
2 Copyright (C) 1999, 2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include "thread_dbP.h"
25 td_thr_tsd (const td_thrhandle_t
*th
, const thread_key_t tk
, void **data
)
27 struct _pthread_descr_struct pds
;
28 struct pthread_key_struct
*keys
= th
->th_ta_p
->keys
;
29 struct pthread_key_struct key
;
30 int pthread_keys_max
= th
->th_ta_p
->pthread_keys_max
;
31 int pthread_key_2ndlevel_size
= th
->th_ta_p
->pthread_key_2ndlevel_size
;
38 /* Get the thread descriptor. */
39 if (ps_pdread (th
->th_ta_p
->ph
, th
->th_unique
, &pds
,
40 sizeof (struct _pthread_descr_struct
)) != PS_OK
)
41 return TD_ERR
; /* XXX Other error value? */
43 /* Check correct value of key. */
44 if (tk
>= pthread_keys_max
)
47 /* Get the key entry. */
48 if (ps_pdread (th
->th_ta_p
->ph
, keys
, &key
,
49 sizeof (struct pthread_key_struct
)) != PS_OK
)
50 return TD_ERR
; /* XXX Other error value? */
52 /* Fail if this key is not at all used. */
56 /* Compute the indeces. */
57 idx1st
= tk
/ pthread_key_2ndlevel_size
;
58 idx2nd
= tk
% pthread_key_2ndlevel_size
;
60 /* Check the pointer to the second level array. */
61 if (pds
.p_specific
[idx1st
] == NULL
)
64 /* Now get the real key.
65 XXX I don't know whether it's correct but there is currently no
66 easy way to determine whether a key was never set or the value
67 is NULL. We return an error whenever the value is NULL. */
68 if (ps_pdread (th
->th_ta_p
->ph
, &pds
.p_specific
[idx1st
][idx2nd
], &p
,
69 sizeof (void *)) != PS_OK
)
75 return p
!= NULL
? TD_OK
: TD_NOTSD
;