source: rtems/cpukit/posix/src/keyfreememory.c @ b5c9064

4.115
Last change on this file since b5c9064 was b5c9064, checked in by Zhongwei Yao <ashi08104@…>, on Aug 5, 2013 at 1:20:45 PM

Unlimited objects support for POSIX keys

This patch enables unlimited model in POSIX key manger and have a decent
runtime on POSIX key searching, adding and deleting operations. Memory
overhead is lower than current implementation when the size of key and key
value becomes big.

  • Property mode set to 100644
File size: 2.0 KB
Line 
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/system.h>
23#include <rtems/score/thread.h>
24#include <rtems/score/wkspace.h>
25#include <rtems/score/rbtree.h>
26#include <rtems/posix/key.h>
27
28void _POSIX_Keys_Free_memory(
29  POSIX_Keys_Control *the_key
30)
31{
32  POSIX_Keys_Key_value_pair search_node;
33  POSIX_Keys_Key_value_pair *p;
34  RBTree_Node *iter, *next;
35
36  search_node.key = the_key->Object.id;
37  search_node.thread_id = 0;
38  iter = _RBTree_Find_unprotected( &_POSIX_Keys_Key_value_lookup_tree, &search_node.Key_value_lookup_node );
39  if ( !iter )
40    return;
41  /**
42   * find the smallest thread_id node in the rbtree.
43   */
44  next = _RBTree_Next_unprotected( iter, RBT_LEFT );
45  p = _RBTree_Container_of( next, POSIX_Keys_Key_value_pair, Key_value_lookup_node );
46  while ( p->key == the_key->Object.id) {
47    iter = next;
48    next = _RBTree_Next_unprotected( iter, RBT_LEFT );
49    p = _RBTree_Container_of( next, POSIX_Keys_Key_value_pair, Key_value_lookup_node );
50  }
51
52  /**
53   * delete all nodes belongs to the_key from the rbtree and chain.
54   */
55  p = _RBTree_Container_of( iter, POSIX_Keys_Key_value_pair, Key_value_lookup_node );
56  while ( p->key == the_key->Object.id ) {
57    next = _RBTree_Next_unprotected( iter, RBT_RIGHT );
58    _RBTree_Extract_unprotected( &_POSIX_Keys_Key_value_lookup_tree, iter );
59    _Chain_Extract_unprotected( &p->Key_values_per_thread_node );
60    /* append the node to _POSIX_Keys_Keypool */
61    _Freechain_Put( &_POSIX_Keys_Keypool.super_fc,
62                    ( void * )p);
63    iter = next;
64    p = _RBTree_Container_of( iter, POSIX_Keys_Key_value_pair, Key_value_lookup_node );
65  }
66}
Note: See TracBrowser for help on using the repository browser.