source: rtems/cpukit/posix/src/keyrundestructors.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.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Thread-Specific Data Key Create
5 * @ingroup POSIX_KEY Key
6 */
7
8/*
9 * Copyright (c) 2012 Zhongwei Yao.
10 * Copyright (c) 2010 embedded brains GmbH.
11 *
12 * COPYRIGHT (c) 1989-2007.
13 * On-Line Applications Research Corporation (OAR).
14 *
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.
18 */
19
20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <rtems/system.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/wkspace.h>
27#include <rtems/score/chain.h>
28#include <rtems/posix/key.h>
29#include <rtems/posix/threadsup.h>
30
31/*
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 */
39void _POSIX_Keys_Run_destructors(
40  Thread_Control *thread
41)
42{
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;
49
50  _Thread_Disable_dispatch();
51
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 );
69
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();
85
86    /**
87     * put back this node to keypool
88     */
89    _Freechain_Put( &_POSIX_Keys_Keypool.super_fc,
90                    (void *)iter );
91
92    iter = next;
93  }
94  _Thread_Enable_dispatch();
95}
Note: See TracBrowser for help on using the repository browser.