source: rtems/testsuites/psxtests/psxkey03/init.c @ 0c11618

4.104.115
Last change on this file since 0c11618 was b6912c40, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/25/09 at 06:25:04

Remove unused vars.
Add missing prototypes.

  • Property mode set to 100644
File size: 2.2 KB
Line 
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
17pthread_key_t Key;
18volatile bool destructor_ran;
19
20void destructor(void *value)
21{
22  destructor_ran = true;
23}
24
25void *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
39void *POSIX_Init(
40  void *ignored
41)
42{
43  pthread_t     thread;
44  int           sc;
45
46  puts( "\n\n*** TEST KEY 03 ***" );
47 
48  /*
49   *  Key with NULL destructor
50   */
51  puts( "Init - pthread_key_create with NULL destructor - OK" );
52  sc = pthread_key_create( &Key, NULL );
53  assert( !sc );
54
55  puts( "Init - pthread_create - OK" );
56  sc = pthread_create( &thread, NULL, Test_Thread, &sc );
57  assert( !sc );
58
59  puts( "Init - sleep - let thread run - OK" );
60  usleep(500000);
61
62  puts( "Init - pthread_key_delete - OK" );
63  sc = pthread_key_delete( Key );
64  assert( sc == 0 );
65
66  /*
67   *  Key with non-NULL destructor
68   */
69  destructor_ran = false;
70  puts( "Init - pthread_key_create with non-NULL destructor - OK" );
71  sc = pthread_key_create( &Key, destructor );
72  assert( !sc );
73
74  puts( "Init - pthread_create - OK" );
75  sc = pthread_create( &thread, NULL, Test_Thread, NULL );
76  assert( !sc );
77
78  puts( "Init - sleep - let thread run - OK" );
79  usleep(500000);
80
81  puts( "Init - verify destructor did NOT ran" );
82  assert( destructor_ran == false );
83
84  puts( "Init - pthread_key_delete - OK" );
85  sc = pthread_key_delete( Key );
86  assert( sc == 0 );
87
88  puts( "*** END OF TEST KEY 03 ***" );
89  rtems_test_exit(0);
90}
91
92/* configuration information */
93
94#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
95#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
96
97#define CONFIGURE_MAXIMUM_POSIX_THREADS  2
98#define CONFIGURE_MAXIMUM_POSIX_KEYS     1
99
100#define CONFIGURE_POSIX_INIT_THREAD_TABLE
101
102#define CONFIGURE_INIT
103#include <rtems/confdefs.h>
104
105/* global variables */
Note: See TracBrowser for help on using the repository browser.