source: rtems/cpukit/posix/src/keycreate.c @ 860c34e

4.104.114.95
Last change on this file since 860c34e was 1d0efc10, checked in by Joel Sherrill <joel.sherrill@…>, on 11/06/07 at 21:39:23

2007-11-06 Joel Sherrill <joel.sherrill@…>

PR 1266/cpukit

  • posix/src/keycreate.c, posix/src/keyrundestructors.c: Use API instead of class for key indexing.
  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 *  $Id$
3 */
4
5#if HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9#include <errno.h>
10#include <limits.h>
11#include <pthread.h>
12#include <string.h>
13
14#include <rtems/system.h>
15#include <rtems/score/thread.h>
16#include <rtems/score/wkspace.h>
17#include <rtems/posix/key.h>
18
19/*PAGE
20 *
21 *  17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163
22 */
23
24int pthread_key_create(
25  pthread_key_t  *key,
26  void          (*destructor)( void * )
27)
28{
29  POSIX_Keys_Control  *the_key;
30  void                *table;
31  uint32_t             the_api;
32  uint32_t             bytes_to_allocate;
33
34
35  _Thread_Disable_dispatch();
36
37  the_key = _POSIX_Keys_Allocate();
38
39  if ( !the_key ) {
40    _Thread_Enable_dispatch();
41    return EAGAIN;
42  }
43
44  the_key->destructor = destructor;
45
46  /*
47   *  This is a bit more complex than one might initially expect because
48   *  APIs are optional.  Thus there may be no ITRON tasks to have keys
49   *  for.  [NOTE: Currently RTEMS Classic API tasks are always enabled.]
50   */
51
52  for ( the_api = 1;
53        the_api <= OBJECTS_APIS_LAST;
54        the_api++ ) {
55
56    if ( _Objects_Information_table[ the_api ] &&
57         _Objects_Information_table[ the_api ][ 1 ] ) {
58      bytes_to_allocate = sizeof( void * ) *
59        (_Objects_Information_table[ the_api ][ 1 ]->maximum + 1);
60      table = _Workspace_Allocate( bytes_to_allocate );
61      if ( !table ) {
62        for ( --the_api;
63              the_api >= 1;
64              the_api-- )
65          _Workspace_Free( the_key->Values[ the_api ] );
66
67        _POSIX_Keys_Free( the_key );
68        _Thread_Enable_dispatch();
69        return ENOMEM;
70      }
71
72      the_key->Values[ the_api ] = table;
73      memset( table, '\0', bytes_to_allocate );
74    } else {
75      the_key->Values[ the_api ] = NULL;
76    }
77
78
79  }
80
81  the_key->is_active = TRUE;
82
83  _Objects_Open( &_POSIX_Keys_Information, &the_key->Object, 0 );
84
85  *key = the_key->Object.id;
86
87  _Thread_Enable_dispatch();
88
89  return 0;
90}
Note: See TracBrowser for help on using the repository browser.