1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2013. |
---|
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.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <timesys.h> |
---|
15 | #include <tmacros.h> |
---|
16 | #include <rtems/timerdrv.h> |
---|
17 | #include "test_support.h" |
---|
18 | |
---|
19 | #include <pthread.h> |
---|
20 | #include <sched.h> |
---|
21 | |
---|
22 | const char rtems_test_name[] = "PSXTMBARRIER 02"; |
---|
23 | |
---|
24 | /* forward declarations to avoid warnings */ |
---|
25 | void *POSIX_Init(void *argument); |
---|
26 | void *Middle(void *argument); |
---|
27 | void *Low(void *argument); |
---|
28 | |
---|
29 | pthread_barrier_t barrier; |
---|
30 | |
---|
31 | void *Low( |
---|
32 | void *argument |
---|
33 | ) |
---|
34 | { |
---|
35 | benchmark_timer_t end_time; |
---|
36 | |
---|
37 | /* |
---|
38 | * Now we have finished the thread startup overhead, |
---|
39 | * so let other threads run. When we return, we can |
---|
40 | * finish the benchmark. |
---|
41 | */ |
---|
42 | sched_yield(); |
---|
43 | /* let other threads run */ |
---|
44 | |
---|
45 | end_time = benchmark_timer_read(); |
---|
46 | |
---|
47 | put_time( |
---|
48 | "pthread_barrier_wait: blocking", |
---|
49 | end_time, |
---|
50 | OPERATION_COUNT, |
---|
51 | 0, |
---|
52 | 0 |
---|
53 | ); |
---|
54 | |
---|
55 | TEST_END(); |
---|
56 | |
---|
57 | rtems_test_exit( 0 ); |
---|
58 | return NULL; |
---|
59 | } |
---|
60 | |
---|
61 | void *Middle( |
---|
62 | void *argument |
---|
63 | ) |
---|
64 | { |
---|
65 | /* |
---|
66 | * Now we have finished the thread startup overhead, |
---|
67 | * so let other threads run. When we return, we can |
---|
68 | * finish the benchmark. |
---|
69 | */ |
---|
70 | sched_yield(); |
---|
71 | /* let other threads run */ |
---|
72 | |
---|
73 | (void) pthread_barrier_wait( &barrier ); |
---|
74 | |
---|
75 | /* should never return */ |
---|
76 | rtems_test_assert( FALSE ); |
---|
77 | return NULL; |
---|
78 | } |
---|
79 | |
---|
80 | void *POSIX_Init( |
---|
81 | void *argument |
---|
82 | ) |
---|
83 | { |
---|
84 | int i; |
---|
85 | int status; |
---|
86 | pthread_t threadId; |
---|
87 | pthread_barrierattr_t attr; |
---|
88 | |
---|
89 | TEST_BEGIN(); |
---|
90 | |
---|
91 | for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) { |
---|
92 | status = pthread_create( &threadId, NULL, Middle, NULL ); |
---|
93 | rtems_test_assert( !status ); |
---|
94 | } |
---|
95 | |
---|
96 | status = pthread_create( &threadId, NULL, Low, NULL ); |
---|
97 | rtems_test_assert( !status ); |
---|
98 | |
---|
99 | /* |
---|
100 | * Create the barrier with default attributes and deliberately |
---|
101 | * create it after the Threads so if they run too early, they |
---|
102 | * wull fail with an error. |
---|
103 | */ |
---|
104 | status = pthread_barrierattr_init( &attr ); |
---|
105 | rtems_test_assert( status == 0 ); |
---|
106 | |
---|
107 | /* |
---|
108 | * Set threshold on count higher than number of threads so all will |
---|
109 | * block. |
---|
110 | */ |
---|
111 | status = pthread_barrier_init( &barrier,&attr, OPERATION_COUNT + 2 ); |
---|
112 | rtems_test_assert( status == 0 ); |
---|
113 | |
---|
114 | /* |
---|
115 | * Let other threads run through their initialization |
---|
116 | */ |
---|
117 | sched_yield(); |
---|
118 | |
---|
119 | /* |
---|
120 | * Start the timer and start the blocking barrier wait chain through |
---|
121 | * all the other tasks. |
---|
122 | */ |
---|
123 | benchmark_timer_initialize(); |
---|
124 | /* blocking barrier call */ |
---|
125 | status = pthread_barrier_wait( &barrier ); |
---|
126 | rtems_test_assert( status == 0 ); |
---|
127 | return NULL; |
---|
128 | } |
---|
129 | |
---|
130 | /* configuration information */ |
---|
131 | |
---|
132 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
133 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
134 | |
---|
135 | #define CONFIGURE_MAXIMUM_POSIX_THREADS OPERATION_COUNT + 2 |
---|
136 | #define CONFIGURE_MAXIMUM_POSIX_BARRIERS 1 |
---|
137 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
138 | |
---|
139 | #define CONFIGURE_INIT |
---|
140 | |
---|
141 | #include <rtems/confdefs.h> |
---|
142 | /* end of file */ |
---|