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.org/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 *p; |
---|
30 | RBTree_Node *iter, *next; |
---|
31 | Objects_Id key_id; |
---|
32 | |
---|
33 | key_id = the_key->Object.id; |
---|
34 | iter = _POSIX_Keys_Find( key_id, 0 ); |
---|
35 | if ( !iter ) |
---|
36 | return; |
---|
37 | /** |
---|
38 | * find the smallest thread_id node in the rbtree. |
---|
39 | */ |
---|
40 | next = _RBTree_Next( iter, RBT_LEFT ); |
---|
41 | p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( next ); |
---|
42 | while ( next != NULL && p->key == key_id) { |
---|
43 | iter = next; |
---|
44 | next = _RBTree_Next( iter, RBT_LEFT ); |
---|
45 | p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( next ); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * delete all nodes belongs to the_key from the rbtree and chain. |
---|
50 | */ |
---|
51 | p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( iter ); |
---|
52 | while ( iter != NULL && p->key == key_id ) { |
---|
53 | next = _RBTree_Next( iter, RBT_RIGHT ); |
---|
54 | |
---|
55 | _POSIX_Keys_Free_key_value_pair( p ); |
---|
56 | |
---|
57 | iter = next; |
---|
58 | p = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( iter ); |
---|
59 | } |
---|
60 | } |
---|