1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Thread-Specific Data Key Create |
---|
5 | * @ingroup POSIX_KEY Key |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (c) 2012 Zhongwei Yao. |
---|
10 | * Copyright (c) 2010 embedded brains GmbH. |
---|
11 | * |
---|
12 | * COPYRIGHT (c) 1989-2007. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.com/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #if HAVE_CONFIG_H |
---|
21 | #include "config.h" |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <rtems/posix/keyimpl.h> |
---|
25 | #include <rtems/posix/threadsup.h> |
---|
26 | #include <rtems/score/chainimpl.h> |
---|
27 | |
---|
28 | /* |
---|
29 | * _POSIX_Keys_Run_destructors |
---|
30 | * |
---|
31 | * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 |
---|
32 | * |
---|
33 | * NOTE: This is the routine executed when a thread exits to |
---|
34 | * run through all the keys and do the destructor action. |
---|
35 | */ |
---|
36 | void _POSIX_Keys_Run_destructors( |
---|
37 | Thread_Control *thread |
---|
38 | ) |
---|
39 | { |
---|
40 | Chain_Control *chain; |
---|
41 | POSIX_Keys_Key_value_pair *iter, *next; |
---|
42 | void *value; |
---|
43 | void (*destructor) (void *); |
---|
44 | POSIX_Keys_Control *the_key; |
---|
45 | Objects_Locations location; |
---|
46 | |
---|
47 | _Thread_Disable_dispatch(); |
---|
48 | |
---|
49 | chain = &( |
---|
50 | (POSIX_API_Control *)thread->API_Extensions[ THREAD_API_POSIX ] |
---|
51 | )->Key_Chain; |
---|
52 | iter = (POSIX_Keys_Key_value_pair *) _Chain_First( chain ); |
---|
53 | while ( !_Chain_Is_tail( chain, &iter->Key_values_per_thread_node ) ) { |
---|
54 | next = (POSIX_Keys_Key_value_pair *) |
---|
55 | _Chain_Next( &iter->Key_values_per_thread_node ); |
---|
56 | |
---|
57 | /** |
---|
58 | * remove key from rbtree and chain. |
---|
59 | * here Chain_Node *iter can be convert to POSIX_Keys_Key_value_pair *, |
---|
60 | * because Chain_Node is the first member of POSIX_Keys_Key_value_pair |
---|
61 | * structure. |
---|
62 | */ |
---|
63 | _RBTree_Extract_unprotected( |
---|
64 | &_POSIX_Keys_Key_value_lookup_tree, |
---|
65 | &iter->Key_value_lookup_node |
---|
66 | ); |
---|
67 | _Chain_Extract_unprotected( &iter->Key_values_per_thread_node ); |
---|
68 | |
---|
69 | /** |
---|
70 | * run key value's destructor if destructor and value are both non-null. |
---|
71 | */ |
---|
72 | the_key = _POSIX_Keys_Get( iter->key, &location ); |
---|
73 | destructor = the_key->destructor; |
---|
74 | value = iter->value; |
---|
75 | if ( destructor != NULL && value != NULL ) |
---|
76 | (*destructor)( value ); |
---|
77 | |
---|
78 | _Objects_Put( &the_key->Object ); |
---|
79 | |
---|
80 | _POSIX_Keys_Key_value_pair_free( iter ); |
---|
81 | |
---|
82 | iter = next; |
---|
83 | } |
---|
84 | |
---|
85 | _Thread_Enable_dispatch(); |
---|
86 | } |
---|