source: rtems/cpukit/posix/src/key.c @ fdb45d6

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

score: Freechain handler API changes

Replace the extend function with an allocator since this fits better
to the current use case.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Keys Manager Initialization
5 * @ingroup POSIX_KEY Key
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/config.h>
23
24#include <rtems/posix/keyimpl.h>
25#include <rtems/score/chainimpl.h>
26#include <rtems/score/objectimpl.h>
27#include <rtems/score/wkspace.h>
28
29RBTREE_DEFINE_EMPTY( _POSIX_Keys_Key_value_lookup_tree );
30
31/**
32 * @brief This routine compares the rbtree node by comparing POSIX key first
33 * and comparing thread id second.
34 *
35 * if either of the input nodes's thread_id member is 0, then it will only
36 * compare the pthread_key_t member. That is when we pass thread_id = 0 node
37 * as a search node, the search is done only by pthread_key_t.
38 *
39 * @param[in] node1 The node to be compared
40 * @param[in] node2 The node to be compared
41 * @retval positive if first node has higher key than second
42 * @retval negative if lower
43 * @retval 0 if equal,and for all the thread id is unique, then return 0 is
44 * impossible
45 */
46
47RBTree_Compare_result _POSIX_Keys_Key_value_compare(
48  const RBTree_Node *node1,
49  const RBTree_Node *node2
50)
51{
52  POSIX_Keys_Key_value_pair *n1;
53  POSIX_Keys_Key_value_pair *n2;
54  Thread_Control *thread1;
55  Thread_Control *thread2;
56  RBTree_Compare_result diff;
57
58  n1 = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node1 );
59  n2 = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node2 );
60
61  diff = n1->key - n2->key;
62  if ( diff )
63    return diff;
64
65  thread1 = n1->thread;
66  thread2 = n2->thread;
67
68  /*
69   * If thread1 or thread2 equals to NULL, only key1 and key2 is valued.  It
70   * enables us search node only by pthread_key_t type key.  Exploit that the
71   * thread control alignment is at least two to avoid integer overflows.
72   */
73  if ( thread1 != NULL && thread2 != NULL )
74    return (RBTree_Compare_result) ( (uintptr_t) thread1 >> 1 )
75      - (RBTree_Compare_result) ( (uintptr_t) thread2 >> 1 );
76
77  return 0;
78}
79
80static uint32_t _POSIX_Keys_Get_keypool_bump_count( void )
81{
82  uint32_t max = Configuration.maximum_key_value_pairs;
83
84  return _Objects_Is_unlimited( max ) ?
85    _Objects_Maximum_per_allocation( max ) : 0;
86}
87
88static uint32_t _POSIX_Keys_Get_initial_keypool_size( void )
89{
90  uint32_t max = Configuration.maximum_key_value_pairs;
91
92  return _Objects_Maximum_per_allocation( max );
93}
94
95static void _POSIX_Keys_Initialize_keypool( void )
96{
97  _Freechain_Initialize(
98    &_POSIX_Keys_Keypool,
99    _Workspace_Allocate_or_fatal_error,
100    _POSIX_Keys_Get_initial_keypool_size(),
101    sizeof( POSIX_Keys_Key_value_pair )
102  );
103}
104
105POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_pair_allocate( void )
106{
107  return (POSIX_Keys_Key_value_pair *) _Freechain_Get(
108    &_POSIX_Keys_Keypool,
109    _Workspace_Allocate,
110    _POSIX_Keys_Get_keypool_bump_count(),
111    sizeof( POSIX_Keys_Key_value_pair )
112  );
113}
114
115/**
116 * @brief This routine performs the initialization necessary for this manager.
117 */
118void _POSIX_Key_Manager_initialization(void)
119{
120  _Objects_Initialize_information(
121    &_POSIX_Keys_Information,   /* object information table */
122    OBJECTS_POSIX_API,          /* object API */
123    OBJECTS_POSIX_KEYS,         /* object class */
124    Configuration.maximum_keys,
125                                /* maximum objects of this class */
126    sizeof( POSIX_Keys_Control ),
127                                /* size of this object's control block */
128    true,                       /* true if names for this object are strings */
129    _POSIX_PATH_MAX             /* maximum length of each object's name */
130#if defined(RTEMS_MULTIPROCESSING)
131    ,
132    false,                      /* true if this is a global object class */
133    NULL                        /* Proxy extraction support callout */
134#endif
135  );
136
137  _POSIX_Keys_Initialize_keypool();
138}
Note: See TracBrowser for help on using the repository browser.