source: rtems/testsuites/psxtests/psx06/init.c @ c65a0cee

4.104.114.84.95
Last change on this file since c65a0cee was c65a0cee, checked in by Joel Sherrill <joel.sherrill@…>, on 07/31/96 at 17:17:48

added key test

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
3 *  On-Line Applications Research Corporation (OAR).
4 *  All rights assigned to U.S. Government, 1994.
5 *
6 *  This material may be reproduced by or for the U.S. Government pursuant
7 *  to the copyright license under the clause at DFARS 252.227-7013.  This
8 *  notice must appear in all copies of this file and its derivatives.
9 *
10 *  $Id$
11 */
12
13#define CONFIGURE_INIT
14#include "system.h"
15#include <errno.h>
16
17void Key_destructor(
18   void *key_data
19)
20{
21  Destructor_invoked++;
22
23  /*
24   *  This checks out that we only run the destructor multiple times
25   *  when the key data is non null.
26   */
27
28  if ( Destructor_invoked == 5 )
29     (void) pthread_setspecific( Key_id, NULL );
30}
31
32void *POSIX_Init(
33  void *argument
34)
35{
36  int               status;
37  unsigned int      remaining;
38  rtems_unsigned32 *key_data;
39
40  puts( "\n\n*** POSIX TEST 6 ***" );
41
42  /* set the time of day, and print our buffer in multiple ways */
43
44  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
45
46  /* get id of this thread */
47
48  Init_id = pthread_self();
49  printf( "Init's ID is 0x%08x\n", Init_id );
50 
51  /* create a couple of threads */
52
53  status = pthread_create( &Task_id, NULL, Task_1, NULL );
54  assert( !status );
55
56  status = pthread_create( &Task2_id, NULL, Task_2, NULL );
57  assert( !status );
58
59  /* create a key */
60
61  empty_line();
62
63  Destructor_invoked = 0;
64  printf( "Init: Creating a key\n" );
65  status = pthread_key_create( &Key_id, Key_destructor );
66  if ( status )
67    printf( "status = %d\n", status );
68  assert( !status );
69
70  printf( "Destructor invoked %d times\n", Destructor_invoked );
71
72  printf( "Init: Setting the key to %d\n", 0 );
73  status = pthread_setspecific( Key_id, &Data_array[ 0 ] );
74  if ( status )
75    printf( "status = %d\n", status );
76  assert( !status );
77
78     /* switch to task 1 */
79
80  key_data = pthread_getspecific( Key_id );
81  printf( "Init: Got the key value of %d\n",
82          (rtems_unsigned32 *)key_data - Data_array );
83
84  remaining = sleep( 3 );
85  if ( remaining )
86     printf( "seconds remaining = %d\n", remaining );
87  assert( !remaining );
88
89     /* switch to task 1 */
90
91  /* delete the key */
92
93  printf( "Init: Deleting a key\n" );
94  status = pthread_key_delete( Key_id );
95  if ( status )
96    printf( "status = %d\n", status );
97  assert( !status );
98
99  printf( "Destructor invoked %d times\n", Destructor_invoked );
100
101  puts( "*** END OF POSIX TEST 6 ***" );
102  exit( 0 );
103
104  return NULL; /* just so the compiler thinks we returned something */
105}
Note: See TracBrowser for help on using the repository browser.