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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [tests/] [psxtests/] [psx06/] [init.c] - Blame information for rev 609

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

Line No. Rev Author Line
1 30 unneback
/*
2
 *  COPYRIGHT (c) 1989-1999.
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.OARcorp.com/rtems/license.html.
8
 *
9
 *  $Id: init.c,v 1.2 2001-09-27 12:02:24 chris Exp $
10
 */
11
 
12
#define CONFIGURE_INIT
13
#include "system.h"
14
#include <errno.h>
15
 
16
void Key_destructor(
17
   void *key_data
18
)
19
{
20
  Destructor_invoked++;
21
 
22
  /*
23
   *  This checks out that we only run the destructor multiple times
24
   *  when the key data is non null.
25
   */
26
 
27
  if ( Destructor_invoked == 5 )
28
     (void) pthread_setspecific( Key_id, NULL );
29
}
30
 
31
void *POSIX_Init(
32
  void *argument
33
)
34
{
35
  int               status;
36
  unsigned int      remaining;
37
  rtems_unsigned32 *key_data;
38
 
39
  puts( "\n\n*** POSIX TEST 6 ***" );
40
 
41
  /* set the time of day, and print our buffer in multiple ways */
42
 
43
  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
44
 
45
  /* get id of this thread */
46
 
47
  Init_id = pthread_self();
48
  printf( "Init's ID is 0x%08x\n", Init_id );
49
 
50
  /* create a couple of threads */
51
 
52
  status = pthread_create( &Task_id, NULL, Task_1, NULL );
53
  assert( !status );
54
 
55
  status = pthread_create( &Task2_id, NULL, Task_2, NULL );
56
  assert( !status );
57
 
58
  /* create a key */
59
 
60
  empty_line();
61
 
62
  Destructor_invoked = 0;
63
  puts( "Init: pthread_key_create - SUCCESSFUL" );
64
  status = pthread_key_create( &Key_id, Key_destructor );
65
  if ( status )
66
    printf( "status = %d\n", status );
67
  assert( !status );
68
 
69
  printf( "Destructor invoked %d times\n", Destructor_invoked );
70
 
71
  puts( "Init: pthread_key_create - EAGAIN (too many keys)" );
72
  status = pthread_key_create( &Key_id, Key_destructor );
73
  assert( status == EAGAIN );
74
 
75
  puts( "Init: pthread_setspecific - EINVAL (invalid key)" );
76
  status = pthread_setspecific( -1, &Data_array[ 0 ] );
77
  assert( status == EINVAL );
78
 
79
  puts( "Init: pthread_getspecific - EINVAL (invalid key)" );
80
  key_data = pthread_getspecific( -1 );
81
  assert( !key_data );
82
 
83
  puts( "Init: pthread_key_delete - EINVAL (invalid key)" );
84
  status = pthread_key_delete( -1 );
85
  assert( status == EINVAL );
86
 
87
  printf( "Init: Setting the key to %d\n", 0 );
88
  status = pthread_setspecific( Key_id, &Data_array[ 0 ] );
89
  if ( status )
90
    printf( "status = %d\n", status );
91
  assert( !status );
92
 
93
     /* switch to task 1 */
94
 
95
  key_data = pthread_getspecific( Key_id );
96
  printf( "Init: Got the key value of %ld\n",
97
          (unsigned long) ((rtems_unsigned32 *)key_data - Data_array) );
98
 
99
  remaining = sleep( 3 );
100
  if ( remaining )
101
     printf( "seconds remaining = %d\n", remaining );
102
  assert( !remaining );
103
 
104
     /* switch to task 1 */
105
 
106
  /* delete the key */
107
 
108
  puts( "Init: pthread_key_delete - SUCCESSFUL" );
109
  status = pthread_key_delete( Key_id );
110
  if ( status )
111
    printf( "status = %d\n", status );
112
  assert( !status );
113
 
114
  printf( "Destructor invoked %d times\n", Destructor_invoked );
115
 
116
  puts( "*** END OF POSIX TEST 6 ***" );
117
  exit( 0 );
118
 
119
  return NULL; /* just so the compiler thinks we returned something */
120
}

powered by: WebSVN 2.1.0

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