[eb08acf] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief Thread-Specific Data Key Create |
---|
| 5 | * @ingroup POSIX_KEY Key |
---|
| 6 | */ |
---|
| 7 | |
---|
[63edcf24] | 8 | /* |
---|
[b5c9064] | 9 | * Copyright (c) 2012 Zhongwei Yao. |
---|
| 10 | * Copyright (c) 2010 embedded brains GmbH. |
---|
[05d470a5] | 11 | * |
---|
[b5c9064] | 12 | * COPYRIGHT (c) 1989-2007. |
---|
| 13 | * On-Line Applications Research Corporation (OAR). |
---|
[feaa007] | 14 | * |
---|
[b5c9064] | 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. |
---|
[63edcf24] | 18 | */ |
---|
| 19 | |
---|
[f42b726] | 20 | #if HAVE_CONFIG_H |
---|
| 21 | #include "config.h" |
---|
| 22 | #endif |
---|
| 23 | |
---|
[63edcf24] | 24 | #include <rtems/system.h> |
---|
| 25 | #include <rtems/score/thread.h> |
---|
[b5c9064] | 26 | #include <rtems/score/wkspace.h> |
---|
| 27 | #include <rtems/score/chain.h> |
---|
[63edcf24] | 28 | #include <rtems/posix/key.h> |
---|
[b5c9064] | 29 | #include <rtems/posix/threadsup.h> |
---|
[63edcf24] | 30 | |
---|
[64adc13] | 31 | /* |
---|
[63edcf24] | 32 | * _POSIX_Keys_Run_destructors |
---|
| 33 | * |
---|
| 34 | * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 |
---|
| 35 | * |
---|
| 36 | * NOTE: This is the routine executed when a thread exits to |
---|
| 37 | * run through all the keys and do the destructor action. |
---|
| 38 | */ |
---|
| 39 | void _POSIX_Keys_Run_destructors( |
---|
| 40 | Thread_Control *thread |
---|
| 41 | ) |
---|
| 42 | { |
---|
[b5c9064] | 43 | Chain_Control *chain; |
---|
| 44 | Chain_Node *iter, *next; |
---|
| 45 | void *value; |
---|
| 46 | void (*destructor) (void *); |
---|
| 47 | POSIX_Keys_Control *the_key; |
---|
| 48 | Objects_Locations location; |
---|
[05d470a5] | 49 | |
---|
[b5c9064] | 50 | _Thread_Disable_dispatch(); |
---|
[05d470a5] | 51 | |
---|
[b5c9064] | 52 | chain = &( |
---|
| 53 | (POSIX_API_Control *)thread->API_Extensions[ THREAD_API_POSIX ] |
---|
| 54 | )->Key_Chain; |
---|
| 55 | iter = _Chain_First( chain ); |
---|
| 56 | while ( !_Chain_Is_tail( chain, iter ) ) { |
---|
| 57 | next = _Chain_Next( iter ); |
---|
| 58 | /** |
---|
| 59 | * remove key from rbtree and chain. |
---|
| 60 | * here Chain_Node *iter can be convert to POSIX_Keys_Key_value_pair *, |
---|
| 61 | * because Chain_Node is the first member of POSIX_Keys_Key_value_pair |
---|
| 62 | * structure. |
---|
| 63 | */ |
---|
| 64 | _RBTree_Extract_unprotected( |
---|
| 65 | &_POSIX_Keys_Key_value_lookup_tree, |
---|
| 66 | &((POSIX_Keys_Key_value_pair *)iter)->Key_value_lookup_node |
---|
| 67 | ); |
---|
| 68 | _Chain_Extract_unprotected( iter ); |
---|
[05d470a5] | 69 | |
---|
[b5c9064] | 70 | /** |
---|
| 71 | * run key value's destructor if destructor and value are both non-null. |
---|
| 72 | */ |
---|
| 73 | the_key = _POSIX_Keys_Get( |
---|
| 74 | ((POSIX_Keys_Key_value_pair *)iter)->key, |
---|
| 75 | &location |
---|
| 76 | ); |
---|
| 77 | destructor = the_key->destructor; |
---|
| 78 | value = ((POSIX_Keys_Key_value_pair *)iter)->value; |
---|
| 79 | if ( destructor != NULL && value != NULL ) |
---|
| 80 | (*destructor)( value ); |
---|
| 81 | /** |
---|
| 82 | * disable dispatch is nested here |
---|
| 83 | */ |
---|
| 84 | _Thread_Enable_dispatch(); |
---|
[05d470a5] | 85 | |
---|
[b5c9064] | 86 | /** |
---|
| 87 | * put back this node to keypool |
---|
| 88 | */ |
---|
| 89 | _Freechain_Put( &_POSIX_Keys_Keypool.super_fc, |
---|
| 90 | (void *)iter ); |
---|
[05d470a5] | 91 | |
---|
[b5c9064] | 92 | iter = next; |
---|
[63edcf24] | 93 | } |
---|
[b5c9064] | 94 | _Thread_Enable_dispatch(); |
---|
[63edcf24] | 95 | } |
---|