OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libpthread/] [linuxthreads_db/] [td_thr_tsd.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Get a thread-specific data pointer for a thread.
2
   Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
4
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
5
 
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.
10
 
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.
15
 
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
19
   02111-1307 USA.  */
20
 
21
#include "thread_dbP.h"
22
#include "../linuxthreads/internals.h"
23
 
24
 
25
td_err_e
26
td_thr_tsd (const td_thrhandle_t *th, const thread_key_t tk, void **data)
27
{
28
  struct _pthread_descr_struct pds;
29
  struct pthread_key_struct *keys = th->th_ta_p->keys;
30
  struct pthread_key_struct key;
31
  int pthread_keys_max = th->th_ta_p->pthread_keys_max;
32
  int pthread_key_2ndlevel_size = th->th_ta_p->pthread_key_2ndlevel_size;
33
  unsigned int idx1st;
34
  unsigned int idx2nd;
35
  void *p;
36
 
37
  LOG ("td_thr_tsd");
38
 
39
  /* If there is no thread descriptor there cannot be any thread
40
     specific data.  */
41
  if (th->th_unique == NULL)
42
    return TD_BADKEY;
43
 
44
  /* Get the thread descriptor.  */
45
  if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds,
46
                 sizeof (struct _pthread_descr_struct)) != PS_OK)
47
    return TD_ERR;      /* XXX Other error value?  */
48
 
49
  /* Check correct value of key.  */
50
  if (tk >= pthread_keys_max)
51
    return TD_BADKEY;
52
 
53
  /* Get the key entry.  */
54
  if (ps_pdread (th->th_ta_p->ph, &keys[tk], &key,
55
                 sizeof (struct pthread_key_struct)) != PS_OK)
56
    return TD_ERR;      /* XXX Other error value?  */
57
 
58
  /* Fail if this key is not at all used.  */
59
  if (! key.in_use)
60
    return TD_BADKEY;
61
 
62
  /* Compute the indeces.  */
63
  idx1st = tk / pthread_key_2ndlevel_size;
64
  idx2nd = tk % pthread_key_2ndlevel_size;
65
 
66
  /* Check the pointer to the second level array.  */
67
  if (pds.p_specific[idx1st] == NULL)
68
    return TD_NOTSD;
69
 
70
  /* Now get the real key.
71
     XXX I don't know whether it's correct but there is currently no
72
     easy way to determine whether a key was never set or the value
73
     is NULL.  We return an error whenever the value is NULL.  */
74
  if (ps_pdread (th->th_ta_p->ph, &pds.p_specific[idx1st][idx2nd], &p,
75
                 sizeof (void *)) != PS_OK)
76
    return TD_ERR;
77
 
78
  if (p != NULL)
79
    *data = p;
80
 
81
  return p != NULL ? TD_OK : TD_NOTSD;
82
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.