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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-newlib/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [linux/] [linuxthreads/] [td_thr_tsd.c] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 jlechner
/* 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.
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
 
23
 
24
td_err_e
25
td_thr_tsd (const td_thrhandle_t *th, const thread_key_t tk, void **data)
26
{
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;
35
 
36
  LOG ("td_thr_tsd");
37
 
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?  */
42
 
43
  /* Check correct value of key.  */
44
  if (tk >= pthread_keys_max)
45
    return TD_BADKEY;
46
 
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?  */
51
 
52
  /* Fail if this key is not at all used.  */
53
  if (! key.in_use)
54
    return TD_BADKEY;
55
 
56
  /* Compute the indeces.  */
57
  idx1st = tk / pthread_key_2ndlevel_size;
58
  idx2nd = tk % pthread_key_2ndlevel_size;
59
 
60
  /* Check the pointer to the second level array.  */
61
  if (pds.p_specific[idx1st] == NULL)
62
    return TD_NOTSD;
63
 
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;
71
 
72
  if (p != NULL)
73
    *data = p;
74
 
75
  return p != NULL ? TD_OK : TD_NOTSD;
76
}

powered by: WebSVN 2.1.0

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