source: rtems/cpukit/posix/src/keysetspecific.c @ 2ad250e

4.115
Last change on this file since 2ad250e was 2ad250e, checked in by Sebastian Huber <sebastian.huber@…>, on 08/06/13 at 12:46:24

posix: Create key implementation header

Move implementation specific parts of key.h and key.inl into new header
file keyimpl.h. The key.h contains now only the application visible
API.

  • Property mode set to 100644
File size: 2.0 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-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 <rtems/posix/keyimpl.h>
23#include <rtems/posix/threadsup.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  Objects_Locations            location;
38  POSIX_Keys_Key_value_pair   *value_pair_ptr;
39  POSIX_API_Control           *api;
40
41  _POSIX_Keys_Get( key, &location );
42  switch ( location ) {
43
44    case OBJECTS_LOCAL:
45      value_pair_ptr = ( POSIX_Keys_Key_value_pair * )
46        _Freechain_Get( &_POSIX_Keys_Keypool.super_fc );
47      if ( !value_pair_ptr ) {
48        _Thread_Enable_dispatch();
49        return ENOMEM;
50      }
51
52      value_pair_ptr->key = key;
53      value_pair_ptr->thread_id = _Thread_Executing->Object.id;
54      value_pair_ptr->value = value;
55      if ( _RBTree_Insert_unprotected( &_POSIX_Keys_Key_value_lookup_tree,
56                                       &(value_pair_ptr->Key_value_lookup_node) ) ) {
57        _Freechain_Put( (Freechain_Control *)&_POSIX_Keys_Keypool,
58                        (void *) value_pair_ptr );
59        _Thread_Enable_dispatch();
60        return EAGAIN;
61      }
62
63      /** append rb_node to the thread API extension's chain */
64      api = (POSIX_API_Control *)\
65       (_Thread_Executing->API_Extensions[THREAD_API_POSIX]);
66      _Chain_Append_unprotected( &api->Key_Chain, &value_pair_ptr->Key_values_per_thread_node );
67
68      _Thread_Enable_dispatch();
69      return 0;
70
71#if defined(RTEMS_MULTIPROCESSING)
72    case OBJECTS_REMOTE:   /* should never happen */
73#endif
74    case OBJECTS_ERROR:
75      break;
76  }
77
78  return EINVAL;
79}
Note: See TracBrowser for help on using the repository browser.