[64bad68b] | 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 | #include <pthread.h> |
---|
| 13 | #include <errno.h> |
---|
| 14 | #include "tmacros.h" |
---|
| 15 | #include "pmacros.h" |
---|
| 16 | |
---|
| 17 | pthread_key_t Key; |
---|
| 18 | volatile bool destructor_ran; |
---|
| 19 | |
---|
| 20 | void destructor(void *value) |
---|
| 21 | { |
---|
| 22 | destructor_ran = true; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | void *Test_Thread( |
---|
| 26 | void *key_value |
---|
| 27 | ) |
---|
| 28 | { |
---|
| 29 | int sc; |
---|
| 30 | |
---|
| 31 | puts( "Test_Thread - pthread_setspecific - OK" ); |
---|
| 32 | sc = pthread_setspecific( Key, key_value ); |
---|
| 33 | assert( !sc ); |
---|
| 34 | |
---|
| 35 | puts( "Test_Thread - pthread_exit to run key destructors - OK" ); |
---|
| 36 | return NULL; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | void *POSIX_Init( |
---|
| 40 | void *ignored |
---|
| 41 | ) |
---|
| 42 | { |
---|
[ea7d86b] | 43 | pthread_t thread; |
---|
| 44 | int sc; |
---|
| 45 | struct timespec delay_request; |
---|
[64bad68b] | 46 | |
---|
| 47 | puts( "\n\n*** TEST KEY 03 ***" ); |
---|
| 48 | |
---|
| 49 | /* |
---|
| 50 | * Key with NULL destructor |
---|
| 51 | */ |
---|
| 52 | puts( "Init - pthread_key_create with NULL destructor - OK" ); |
---|
| 53 | sc = pthread_key_create( &Key, NULL ); |
---|
| 54 | assert( !sc ); |
---|
| 55 | |
---|
| 56 | puts( "Init - pthread_create - OK" ); |
---|
| 57 | sc = pthread_create( &thread, NULL, Test_Thread, &sc ); |
---|
| 58 | assert( !sc ); |
---|
| 59 | |
---|
| 60 | puts( "Init - sleep - let thread run - OK" ); |
---|
[ea7d86b] | 61 | delay_request.tv_sec = 0; |
---|
| 62 | delay_request.tv_nsec = 5 * 100000000; |
---|
| 63 | sc = nanosleep( &delay_request, NULL ); |
---|
| 64 | assert( !sc ); |
---|
[64bad68b] | 65 | |
---|
| 66 | puts( "Init - pthread_key_delete - OK" ); |
---|
| 67 | sc = pthread_key_delete( Key ); |
---|
| 68 | assert( sc == 0 ); |
---|
| 69 | |
---|
| 70 | /* |
---|
| 71 | * Key with non-NULL destructor |
---|
| 72 | */ |
---|
| 73 | destructor_ran = false; |
---|
| 74 | puts( "Init - pthread_key_create with non-NULL destructor - OK" ); |
---|
| 75 | sc = pthread_key_create( &Key, destructor ); |
---|
| 76 | assert( !sc ); |
---|
| 77 | |
---|
| 78 | puts( "Init - pthread_create - OK" ); |
---|
| 79 | sc = pthread_create( &thread, NULL, Test_Thread, NULL ); |
---|
| 80 | assert( !sc ); |
---|
| 81 | |
---|
| 82 | puts( "Init - sleep - let thread run - OK" ); |
---|
[ea7d86b] | 83 | sc = nanosleep( &delay_request, NULL ); |
---|
| 84 | assert( !sc ); |
---|
[64bad68b] | 85 | |
---|
| 86 | puts( "Init - verify destructor did NOT ran" ); |
---|
| 87 | assert( destructor_ran == false ); |
---|
| 88 | |
---|
| 89 | puts( "Init - pthread_key_delete - OK" ); |
---|
| 90 | sc = pthread_key_delete( Key ); |
---|
| 91 | assert( sc == 0 ); |
---|
| 92 | |
---|
| 93 | puts( "*** END OF TEST KEY 03 ***" ); |
---|
| 94 | rtems_test_exit(0); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | /* configuration information */ |
---|
| 98 | |
---|
| 99 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 100 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 101 | |
---|
| 102 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
| 103 | #define CONFIGURE_MAXIMUM_POSIX_KEYS 1 |
---|
| 104 | |
---|
| 105 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
| 106 | |
---|
| 107 | #define CONFIGURE_INIT |
---|
| 108 | #include <rtems/confdefs.h> |
---|
| 109 | |
---|
| 110 | /* global variables */ |
---|