OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [posix/] [src/] [keycreate.c] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  $Id: keycreate.c,v 1.2 2001-09-27 11:59:17 chris Exp $
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
 
20
int 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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.