source: rtems/cpukit/posix/src/keygetspecific.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: 1.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief Thread-Specific Data Management
5 * @ingroup POSIXAPI
6 */
7
8/*
9 * Copyright (c) 2012 Zhongwei Yao.
10 * COPYRIGHT (c) 1989-2007.
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 <errno.h>
23#include <limits.h>
24#include <pthread.h>
25#include <string.h>
26
27#include <rtems/system.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/wkspace.h>
30#include <rtems/score/rbtree.h>
31#include <rtems/posix/key.h>
32
33/*
34 *  17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165
35 */
36
37void *pthread_getspecific(
38  pthread_key_t  key
39)
40{
41  Objects_Locations            location;
42  POSIX_Keys_Key_value_pair    search_node;
43  RBTree_Node                 *p;
44  void                        *key_data;
45  POSIX_Keys_Key_value_pair   *value_pair_p;
46
47  _POSIX_Keys_Get( key, &location );
48  switch ( location ) {
49
50    case OBJECTS_LOCAL:
51      search_node.key = key;
52      search_node.thread_id = _Thread_Executing->Object.id;
53      p = _RBTree_Find_unprotected( &_POSIX_Keys_Key_value_lookup_tree,
54                                    &search_node.Key_value_lookup_node );
55      key_data = NULL;
56      if ( p ) {
57        value_pair_p = _RBTree_Container_of( p,
58                                          POSIX_Keys_Key_value_pair,
59                                          Key_value_lookup_node );
60        /* key_data = _RBTree_Container_of( p, */
61        /*                                  POSIX_Keys_Key_value_pair, */
62        /*                                  Key_value_lookup_node )->value; */
63        key_data = value_pair_p->value;
64      }
65      _Thread_Enable_dispatch();
66      return key_data;
67
68#if defined(RTEMS_MULTIPROCESSING)
69    case OBJECTS_REMOTE:   /* should never happen */
70#endif
71    case OBJECTS_ERROR:
72      break;
73  }
74
75  return NULL;
76}
Note: See TracBrowser for help on using the repository browser.