1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief POSIX Function Keys Free Memory |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (c) 2012 Zhongwei Yao. |
---|
10 | * COPYRIGHT (c) 1989-2010. |
---|
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 <rtems/posix/keyimpl.h> |
---|
23 | #include <rtems/score/chainimpl.h> |
---|
24 | |
---|
25 | void _POSIX_Keys_Free_memory( |
---|
26 | POSIX_Keys_Control *the_key |
---|
27 | ) |
---|
28 | { |
---|
29 | POSIX_Keys_Key_value_pair search_node; |
---|
30 | POSIX_Keys_Key_value_pair *p; |
---|
31 | RBTree_Node *iter, *next; |
---|
32 | Objects_Id key_id; |
---|
33 | |
---|
34 | key_id = the_key->Object.id; |
---|
35 | search_node.key = key_id; |
---|
36 | search_node.thread_id = 0; |
---|
37 | iter = _RBTree_Find_unprotected( &_POSIX_Keys_Key_value_lookup_tree, &search_node.Key_value_lookup_node ); |
---|
38 | if ( !iter ) |
---|
39 | return; |
---|
40 | /** |
---|
41 | * find the smallest thread_id node in the rbtree. |
---|
42 | */ |
---|
43 | next = _RBTree_Next_unprotected( iter, RBT_LEFT ); |
---|
44 | p = _RBTree_Container_of( next, POSIX_Keys_Key_value_pair, Key_value_lookup_node ); |
---|
45 | while ( next != NULL && p->key == key_id) { |
---|
46 | iter = next; |
---|
47 | next = _RBTree_Next_unprotected( iter, RBT_LEFT ); |
---|
48 | p = _RBTree_Container_of( next, POSIX_Keys_Key_value_pair, Key_value_lookup_node ); |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * delete all nodes belongs to the_key from the rbtree and chain. |
---|
53 | */ |
---|
54 | p = _RBTree_Container_of( iter, POSIX_Keys_Key_value_pair, Key_value_lookup_node ); |
---|
55 | while ( iter != NULL && p->key == key_id ) { |
---|
56 | next = _RBTree_Next_unprotected( iter, RBT_RIGHT ); |
---|
57 | _RBTree_Extract_unprotected( &_POSIX_Keys_Key_value_lookup_tree, iter ); |
---|
58 | _Chain_Extract_unprotected( &p->Key_values_per_thread_node ); |
---|
59 | _POSIX_Keys_Key_value_pair_free( p ); |
---|
60 | |
---|
61 | iter = next; |
---|
62 | p = _RBTree_Container_of( iter, POSIX_Keys_Key_value_pair, Key_value_lookup_node ); |
---|
63 | } |
---|
64 | } |
---|