source: rtems/cpukit/posix/src/keysetspecific.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.2 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 <errno.h>
23#include <limits.h>
24#include <pthread.h>
25#include <string.h>
26#include <stddef.h>
27
28#include <rtems/system.h>
29#include <rtems/score/thread.h>
30#include <rtems/score/wkspace.h>
31#include <rtems/score/rbtree.h>
32#include <rtems/posix/key.h>
33#include <rtems/posix/threadsup.h>
34
35/*
36 *  17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165
37 */
38
39int pthread_setspecific(
40  pthread_key_t  key,
41  const void    *value
42)
43{
44  Objects_Locations            location;
45  POSIX_Keys_Key_value_pair   *value_pair_ptr;
46  POSIX_API_Control           *api;
47
48  _POSIX_Keys_Get( key, &location );
49  switch ( location ) {
50
51    case OBJECTS_LOCAL:
52      value_pair_ptr = ( POSIX_Keys_Key_value_pair * )
53        _Freechain_Get( &_POSIX_Keys_Keypool.super_fc );
54      if ( !value_pair_ptr ) {
55        _Thread_Enable_dispatch();
56        return ENOMEM;
57      }
58
59      value_pair_ptr->key = key;
60      value_pair_ptr->thread_id = _Thread_Executing->Object.id;
61      value_pair_ptr->value = value;
62      if ( _RBTree_Insert_unprotected( &_POSIX_Keys_Key_value_lookup_tree,
63                                       &(value_pair_ptr->Key_value_lookup_node) ) ) {
64        _Freechain_Put( (Freechain_Control *)&_POSIX_Keys_Keypool,
65                        (void *) value_pair_ptr );
66        _Thread_Enable_dispatch();
67        return EAGAIN;
68      }
69
70      /** append rb_node to the thread API extension's chain */
71      api = (POSIX_API_Control *)\
72       (_Thread_Executing->API_Extensions[THREAD_API_POSIX]);
73      _Chain_Append_unprotected( &api->Key_Chain, &value_pair_ptr->Key_values_per_thread_node );
74
75      _Thread_Enable_dispatch();
76      return 0;
77
78#if defined(RTEMS_MULTIPROCESSING)
79    case OBJECTS_REMOTE:   /* should never happen */
80#endif
81    case OBJECTS_ERROR:
82      break;
83  }
84
85  return EINVAL;
86}
Note: See TracBrowser for help on using the repository browser.