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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.8 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.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
25void _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( &_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( 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( 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( iter, RBT_RIGHT );
57    _RBTree_Extract( &_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}
Note: See TracBrowser for help on using the repository browser.