source: rtems/c/src/tests/psxtests/psx06/init.c @ f8700f77

4.104.114.84.95
Last change on this file since f8700f77 was f8700f77, checked in by Joel Sherrill <joel.sherrill@…>, on 04/07/97 at 21:33:28

corrected printf specifications and added casts as necessary to eliminate
warnings.

  • Property mode set to 100644
File size: 3.0 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  puts( "Init: pthread_key_create - SUCCESSFUL" );
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  puts( "Init: pthread_key_create - EAGAIN (too many keys)" );
73  status = pthread_key_create( &Key_id, Key_destructor );
74  assert( status == EAGAIN );
75
76  puts( "Init: pthread_setspecific - EINVAL (invalid key)" );
77  status = pthread_setspecific( -1, &Data_array[ 0 ] );
78  assert( status == EINVAL );
79
80  puts( "Init: pthread_getspecific - EINVAL (invalid key)" );
81  key_data = pthread_getspecific( -1 );
82  assert( !key_data );
83
84  puts( "Init: pthread_key_delete - EINVAL (invalid key)" );
85  status = pthread_key_delete( -1 );
86  assert( status == EINVAL );
87
88  printf( "Init: Setting the key to %d\n", 0 );
89  status = pthread_setspecific( Key_id, &Data_array[ 0 ] );
90  if ( status )
91    printf( "status = %d\n", status );
92  assert( !status );
93
94     /* switch to task 1 */
95
96  key_data = pthread_getspecific( Key_id );
97  printf( "Init: Got the key value of %ld\n",
98          (unsigned long) ((rtems_unsigned32 *)key_data - Data_array) );
99
100  remaining = sleep( 3 );
101  if ( remaining )
102     printf( "seconds remaining = %d\n", remaining );
103  assert( !remaining );
104
105     /* switch to task 1 */
106
107  /* delete the key */
108
109  puts( "Init: pthread_key_delete - SUCCESSFUL" );
110  status = pthread_key_delete( Key_id );
111  if ( status )
112    printf( "status = %d\n", status );
113  assert( !status );
114
115  printf( "Destructor invoked %d times\n", Destructor_invoked );
116
117  puts( "*** END OF POSIX TEST 6 ***" );
118  exit( 0 );
119
120  return NULL; /* just so the compiler thinks we returned something */
121}
Note: See TracBrowser for help on using the repository browser.