* sysdeps/m68k/fpu/s_nextafterl.c: New file.
[glibc/pb-stable.git] / linuxthreads_db / td_thr_tsd.c
blob0453c981ea86200573f21411577f4d19df3a2d79
1 /* Get a thread-specific data pointer for a thread.
2 Copyright (C) 1999 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 Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 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 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include "thread_dbP.h"
24 td_err_e
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;
32 unsigned int idx1st;
33 unsigned int idx2nd;
34 void *p;
36 LOG (__FUNCTION__);
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)
45 return TD_BADKEY;
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. */
53 if (! key.in_use)
54 return TD_BADKEY;
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)
62 return TD_NOTSD;
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)
70 return TD_ERR;
72 if (p != NULL)
73 *data = p;
75 return p != NULL ? TD_OK : TD_NOTSD;