1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Thread-Specific Data Management |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (c) 2012 Zhongwei Yao. |
---|
10 | * COPYRIGHT (c) 1989-2007. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #if HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <errno.h> |
---|
23 | #include <limits.h> |
---|
24 | #include <pthread.h> |
---|
25 | #include <string.h> |
---|
26 | |
---|
27 | #include <rtems/system.h> |
---|
28 | #include <rtems/score/thread.h> |
---|
29 | #include <rtems/score/wkspace.h> |
---|
30 | #include <rtems/score/rbtree.h> |
---|
31 | #include <rtems/posix/key.h> |
---|
32 | |
---|
33 | /* |
---|
34 | * 17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165 |
---|
35 | */ |
---|
36 | |
---|
37 | void *pthread_getspecific( |
---|
38 | pthread_key_t key |
---|
39 | ) |
---|
40 | { |
---|
41 | Objects_Locations location; |
---|
42 | POSIX_Keys_Key_value_pair search_node; |
---|
43 | RBTree_Node *p; |
---|
44 | void *key_data; |
---|
45 | POSIX_Keys_Key_value_pair *value_pair_p; |
---|
46 | |
---|
47 | _POSIX_Keys_Get( key, &location ); |
---|
48 | switch ( location ) { |
---|
49 | |
---|
50 | case OBJECTS_LOCAL: |
---|
51 | search_node.key = key; |
---|
52 | search_node.thread_id = _Thread_Executing->Object.id; |
---|
53 | p = _RBTree_Find_unprotected( &_POSIX_Keys_Key_value_lookup_tree, |
---|
54 | &search_node.Key_value_lookup_node ); |
---|
55 | key_data = NULL; |
---|
56 | if ( p ) { |
---|
57 | value_pair_p = _RBTree_Container_of( p, |
---|
58 | POSIX_Keys_Key_value_pair, |
---|
59 | Key_value_lookup_node ); |
---|
60 | /* key_data = _RBTree_Container_of( p, */ |
---|
61 | /* POSIX_Keys_Key_value_pair, */ |
---|
62 | /* Key_value_lookup_node )->value; */ |
---|
63 | key_data = value_pair_p->value; |
---|
64 | } |
---|
65 | _Thread_Enable_dispatch(); |
---|
66 | return key_data; |
---|
67 | |
---|
68 | #if defined(RTEMS_MULTIPROCESSING) |
---|
69 | case OBJECTS_REMOTE: /* should never happen */ |
---|
70 | #endif |
---|
71 | case OBJECTS_ERROR: |
---|
72 | break; |
---|
73 | } |
---|
74 | |
---|
75 | return NULL; |
---|
76 | } |
---|