source: rtems/cpukit/posix/src/keycreate.c @ 77c330ce

4.115
Last change on this file since 77c330ce was 77c330ce, checked in by Joel Sherrill <joel.sherrill@…>, on 07/26/10 at 22:03:18

2010-07-26 Joel Sherrill <joel.sherrill@…>

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