source: rtems/testsuites/psxtests/psxkey04/init.c @ b5c9064

4.115
Last change on this file since b5c9064 was b5c9064, checked in by Zhongwei Yao <ashi08104@…>, on 08/05/13 at 13:20:45

Unlimited objects support for POSIX keys

This patch enables unlimited model in POSIX key manger and have a decent
runtime on POSIX key searching, adding and deleting operations. Memory
overhead is lower than current implementation when the size of key and key
value becomes big.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  Copyright (c) 2012 Zhongwei Yao.
3 *  COPYRIGHT (c) 1989-2012.
4 *  On-Line Applications Research Corporation (OAR).
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.rtems.com/license/LICENSE.
9 */
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15#include <pthread.h>
16#include <errno.h>
17#include "tmacros.h"
18#include "pmacros.h"
19
20/* forward declarations to avoid warnings */
21void *POSIX_Init(void *argument);
22void *Test_Thread1(void *argument);
23void *Test_Thread2(void *argument);
24
25int Data_array[2] = {1, 2};
26pthread_t        thread1, thread2;
27
28pthread_key_t Key;
29
30void *Test_Thread1(
31  void *argument
32)
33{
34  int sc;
35  int *value;
36  struct timespec  delay_request;
37  /*
38   * Detach ourselves so we don't wait for a join that won't happen.
39   */
40  pthread_detach( pthread_self() );
41
42  puts( "Test_Thread 1 - pthread_setspecific - OK" );
43  sc = pthread_setspecific( Key, &Data_array[0] );
44  rtems_test_assert( !sc );
45
46  puts( "Test_Thread 1 - sleep - let thread 2 run - OK" );
47  delay_request.tv_sec = 0;
48  delay_request.tv_nsec = 4 * 100000000;
49  sc = nanosleep( &delay_request, NULL );
50  rtems_test_assert( !sc );
51
52  puts( "Test_Thread 1 - pthread_getspecific - OK" );
53  value = pthread_getspecific( Key );
54  rtems_test_assert( *value == Data_array[0] );
55
56  return NULL;
57}
58
59void *Test_Thread2(
60  void *argument
61)
62{
63  int sc;
64  int *value;
65  /*
66   * Detach ourselves so we don't wait for a join that won't happen.
67   */
68  pthread_detach( pthread_self() );
69
70  puts( "Test_Thread 2 - pthread_setspecific - OK" );
71  sc = pthread_setspecific( Key, &Data_array[1] );
72  rtems_test_assert( !sc );
73
74  puts( "Test_Thread 2 - pthread_getspecific - OK" );
75  value = pthread_getspecific( Key );
76  rtems_test_assert( *value == Data_array[1] );
77
78  return NULL;
79}
80
81void *POSIX_Init(
82  void *ignored
83)
84{
85  int              sc;
86  struct timespec  delay_request;
87
88  puts( "\n\n*** TEST KEY 04 ***" );
89
90  puts( "Init - pthread_key_create - OK" );
91  sc = pthread_key_create( &Key, NULL );
92  rtems_test_assert( !sc );
93
94  puts( "Init - pthread_create - OK" );
95  sc = pthread_create( &thread1, NULL, Test_Thread1, NULL );
96  rtems_test_assert( !sc );
97
98  sc = pthread_create( &thread2, NULL, Test_Thread2, NULL );
99  rtems_test_assert( !sc );
100
101  puts( "Init - sleep - let thread run - OK" );
102  delay_request.tv_sec = 0;
103  delay_request.tv_nsec = 8 * 100000000;
104  sc = nanosleep( &delay_request, NULL );
105  rtems_test_assert( !sc );
106
107  puts( "Init - pthread_key_delete - OK" );
108  sc = pthread_key_delete( Key );
109  rtems_test_assert( sc == 0 );
110
111  puts( "*** END OF TEST KEY 04 ***" );
112  rtems_test_exit(0);
113}
114
115/* configuration information */
116
117#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
118#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
119
120#define CONFIGURE_MAXIMUM_POSIX_THREADS  3
121#define CONFIGURE_MAXIMUM_POSIX_KEYS     1
122
123#define CONFIGURE_POSIX_INIT_THREAD_TABLE
124
125#define CONFIGURE_INIT
126#include <rtems/confdefs.h>
127
128/* global variables */
Note: See TracBrowser for help on using the repository browser.