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