source: rtems/cpukit/posix/src/keysetspecific.c @ ed7a028

4.115
Last change on this file since ed7a028 was 64939bc, checked in by Sebastian Huber <sebastian.huber@…>, on 07/12/14 at 19:22:22

rbtree: Reduce RBTree_Control size

Remove compare function and is unique indicator from the control
structure. Rename RBTree_Compare_function to RBTree_Compare. Rename
rtems_rbtree_compare_function to rtems_rbtree_compare. Provide C++
compatible initializers. Add compare function and is unique indicator
to _RBTree_Find(), _RBTree_Insert(), rtems_rbtree_find() and
rtems_rbtree_insert(). Remove _RBTree_Is_unique() and
rtems_rbtree_is_unique(). Remove compare function and is unique
indicator from _RBTree_Initialize_empty() and
rtems_rbtree_initialize_empty().

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Set Specific Key
5 * @ingroup POSIXAPI
6 */
7
8/*
9 * Copyright (c) 2012 Zhongwei Yao.
10 * COPYRIGHT (c) 1989-2014.
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/thread.h>
24#include <rtems/score/chainimpl.h>
25
26#include <errno.h>
27
28/*
29 *  17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165
30 */
31
32int pthread_setspecific(
33  pthread_key_t  key,
34  const void    *value
35)
36{
37  POSIX_Keys_Control          *the_key;
38  Objects_Locations            location;
39  POSIX_Keys_Key_value_pair   *value_pair_ptr;
40  RBTree_Node                 *p;
41  POSIX_Keys_Key_value_pair    search_node;
42
43  the_key = _POSIX_Keys_Get( key, &location );
44  switch ( location ) {
45
46    case OBJECTS_LOCAL:
47      p = _POSIX_Keys_Find( key, _Thread_Executing->Object.id, &search_node );
48      if ( p != NULL ) {
49        value_pair_ptr = _RBTree_Container_of( p,
50                                          POSIX_Keys_Key_value_pair,
51                                          Key_value_lookup_node );
52
53        value_pair_ptr->value = value;
54      } else {
55        value_pair_ptr = _POSIX_Keys_Key_value_pair_allocate();
56
57        if ( !value_pair_ptr ) {
58          _Objects_Put( &the_key->Object );
59
60          return ENOMEM;
61        }
62
63        value_pair_ptr->key = key;
64        value_pair_ptr->thread_id = _Thread_Executing->Object.id;
65        value_pair_ptr->value = value;
66        /* The insert can only go wrong if the same node is already in a unique
67         * tree. This has been already checked with the _RBTree_Find() */
68        _RBTree_Insert(
69          &_POSIX_Keys_Key_value_lookup_tree,
70          &value_pair_ptr->Key_value_lookup_node,
71          _POSIX_Keys_Key_value_compare,
72          true
73        );
74
75        /** append rb_node to the thread API extension's chain */
76        _Chain_Append_unprotected(
77          &_Thread_Executing->Key_Chain,
78          &value_pair_ptr->Key_values_per_thread_node
79        );
80      }
81
82      _Objects_Put( &the_key->Object );
83
84      return 0;
85
86#if defined(RTEMS_MULTIPROCESSING)
87    case OBJECTS_REMOTE:   /* should never happen */
88#endif
89    case OBJECTS_ERROR:
90      break;
91  }
92
93  return EINVAL;
94}
Note: See TracBrowser for help on using the repository browser.