source: rtems/cpukit/posix/src/keycreate.c @ 5cb175bb

4.115
Last change on this file since 5cb175bb was 5cb175bb, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 10, 2013 at 7:22:31 PM

cpukit/posix: Doxygen group is POSIXAPI

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Thread-Specific Data Key Create
5 *  @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2010.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <errno.h>
22#include <limits.h>
23#include <pthread.h>
24#include <string.h>
25
26#include <rtems/system.h>
27#include <rtems/score/thread.h>
28#include <rtems/score/wkspace.h>
29#include <rtems/posix/key.h>
30
31/**
32 *  17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163
33 */
34int pthread_key_create(
35  pthread_key_t  *key,
36  void          (*destructor)( void * )
37)
38{
39  POSIX_Keys_Control  *the_key;
40  void                *table;
41  uint32_t             the_api;
42  uint32_t             bytes_to_allocate;
43
44
45  _Thread_Disable_dispatch();
46
47  the_key = _POSIX_Keys_Allocate();
48
49  if ( !the_key ) {
50    _Thread_Enable_dispatch();
51    return EAGAIN;
52  }
53
54  the_key->destructor = destructor;
55
56  /*
57   *  This is a bit more complex than one might initially expect because
58   *  APIs are optional.
59   *
60   *  NOTE: Currently RTEMS Classic API tasks are always enabled.
61   */
62  for ( the_api = 1; the_api <= OBJECTS_APIS_LAST; the_api++ ) {
63    the_key->Values[ the_api ] = NULL;
64
65    #if defined(RTEMS_DEBUG)
66      /*
67       *  Since the removal of ITRON, this cannot occur.
68       */
69      if ( !_Objects_Information_table[ the_api ] )
70        continue;
71
72      /*
73       * Currently all managers are installed if the API is installed.
74       * This would be a horrible implementation error.
75       */
76      if (_Objects_Information_table[ the_api ][ 1 ] == NULL )
77        _Internal_error_Occurred(
78          INTERNAL_ERROR_CORE,
79          true,
80          INTERNAL_ERROR_IMPLEMENTATION_KEY_CREATE_INCONSISTENCY
81        );
82    #endif
83
84    bytes_to_allocate = sizeof( void * ) *
85      (_Objects_Information_table[ the_api ][ 1 ]->maximum + 1);
86    table = _Workspace_Allocate( bytes_to_allocate );
87    if ( !table ) {
88      _POSIX_Keys_Free_memory( the_key );
89
90      _POSIX_Keys_Free( the_key );
91      _Thread_Enable_dispatch();
92      return ENOMEM;
93    }
94
95    the_key->Values[ the_api ] = table;
96    memset( table, '\0', bytes_to_allocate );
97  }
98
99  _Objects_Open_u32( &_POSIX_Keys_Information, &the_key->Object, 0 );
100  *key = the_key->Object.id;
101  _Thread_Enable_dispatch();
102  return 0;
103}
Note: See TracBrowser for help on using the repository browser.