source: rtems/c/src/exec/posix/src/keycreate.c @ aa1d76e

4.104.114.84.95
Last change on this file since aa1d76e was 70af0ea1, checked in by Joel Sherrill <joel.sherrill@…>, on 01/10/00 at 18:47:58

Don't look at the object information structure for threads/tasks
for APIs that are not configured. This resulted in weird behavior
when ITRON was disabled on some targets.

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