1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * COPYRIGHT (c) 1989-2013. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions |
---|
9 | * are met: |
---|
10 | * 1. Redistributions of source code must retain the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer. |
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer in the |
---|
14 | * documentation and/or other materials provided with the distribution. |
---|
15 | * |
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
26 | * POSSIBILITY OF SUCH DAMAGE. |
---|
27 | */ |
---|
28 | |
---|
29 | #ifdef HAVE_CONFIG_H |
---|
30 | #include "config.h" |
---|
31 | #endif |
---|
32 | #include <errno.h> |
---|
33 | #include <timesys.h> |
---|
34 | #include <tmacros.h> |
---|
35 | #include <sched.h> |
---|
36 | #include <pthread.h> |
---|
37 | #include <rtems/btimer.h> |
---|
38 | #include "test_support.h" |
---|
39 | |
---|
40 | const char rtems_test_name[] = "PSXTMRWLOCK 03"; |
---|
41 | |
---|
42 | /* forward declarations to avoid warnings */ |
---|
43 | void *POSIX_Init(void *argument); |
---|
44 | void *Middle(void *argument); |
---|
45 | void *Low(void *argument); |
---|
46 | |
---|
47 | pthread_rwlock_t rwlock; |
---|
48 | struct timespec abstime; |
---|
49 | |
---|
50 | void *Low( |
---|
51 | void *argument |
---|
52 | ) |
---|
53 | { |
---|
54 | benchmark_timer_t end_time; |
---|
55 | |
---|
56 | /* |
---|
57 | * Now we have finished the thread startup overhead, |
---|
58 | * so let other threads run. When we return, we can |
---|
59 | * finish the benchmark. |
---|
60 | */ |
---|
61 | sched_yield(); |
---|
62 | /* let other threads run */ |
---|
63 | |
---|
64 | end_time = benchmark_timer_read(); |
---|
65 | |
---|
66 | put_time( |
---|
67 | "pthread_rwlock_timedrdlock: not available blocks", |
---|
68 | end_time, |
---|
69 | OPERATION_COUNT, |
---|
70 | 0, |
---|
71 | 0 |
---|
72 | ); |
---|
73 | |
---|
74 | TEST_END(); |
---|
75 | |
---|
76 | rtems_test_exit( 0 ); |
---|
77 | return NULL; |
---|
78 | } |
---|
79 | |
---|
80 | void *Middle( |
---|
81 | void *argument |
---|
82 | ) |
---|
83 | { |
---|
84 | int status; |
---|
85 | |
---|
86 | /* |
---|
87 | * Now we have finished the thread startup overhead, |
---|
88 | * so let other threads run. When we return, we can |
---|
89 | * finish the benchmark. |
---|
90 | */ |
---|
91 | sched_yield(); |
---|
92 | /* let other threads run */ |
---|
93 | |
---|
94 | /* this timed read lock operation will be blocked |
---|
95 | * cause a write operation has the lock */ |
---|
96 | status = pthread_rwlock_timedrdlock(&rwlock, &abstime); |
---|
97 | rtems_test_assert( status == 0 ); |
---|
98 | return NULL; |
---|
99 | } |
---|
100 | |
---|
101 | void *POSIX_Init( |
---|
102 | void *argument |
---|
103 | ) |
---|
104 | { |
---|
105 | int i; |
---|
106 | int status; |
---|
107 | pthread_t threadId; |
---|
108 | pthread_rwlockattr_t attr; |
---|
109 | |
---|
110 | TEST_BEGIN(); |
---|
111 | |
---|
112 | for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) { |
---|
113 | status = pthread_create( &threadId, NULL, Middle, NULL ); |
---|
114 | rtems_test_assert( !status ); |
---|
115 | } |
---|
116 | |
---|
117 | status = pthread_create( &threadId, NULL, Low, NULL ); |
---|
118 | rtems_test_assert( !status ); |
---|
119 | |
---|
120 | /* |
---|
121 | * Timeout for 5 seconds from now. |
---|
122 | */ |
---|
123 | status = clock_gettime( CLOCK_REALTIME, &abstime ); |
---|
124 | rtems_test_assert( !status ); |
---|
125 | abstime.tv_sec += 5; |
---|
126 | |
---|
127 | /* |
---|
128 | * Deliberately create the rwlock after the threads. This way if the |
---|
129 | * threads do run before we intend, they will get an error. |
---|
130 | */ |
---|
131 | status = pthread_rwlockattr_init( &attr ); |
---|
132 | rtems_test_assert( status == 0 ); |
---|
133 | status = pthread_rwlock_init( &rwlock, &attr ); |
---|
134 | rtems_test_assert( status == 0 ); |
---|
135 | |
---|
136 | /* |
---|
137 | * Let the other threads start so the thread startup overhead, |
---|
138 | * is accounted for. When we return, we can start the benchmark. |
---|
139 | */ |
---|
140 | sched_yield(); |
---|
141 | /* let other threads run */ |
---|
142 | |
---|
143 | /* start the timer and switch through all the other tasks */ |
---|
144 | benchmark_timer_initialize(); |
---|
145 | |
---|
146 | /* |
---|
147 | * Write lock operation, this could be any write lock |
---|
148 | */ |
---|
149 | status = pthread_rwlock_timedwrlock(&rwlock,0); |
---|
150 | rtems_test_assert( status == 0 ); |
---|
151 | return NULL; |
---|
152 | } |
---|
153 | |
---|
154 | /* configuration information */ |
---|
155 | |
---|
156 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
157 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
158 | |
---|
159 | #define CONFIGURE_MAXIMUM_POSIX_THREADS OPERATION_COUNT + 2 |
---|
160 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
161 | |
---|
162 | #define CONFIGURE_INIT |
---|
163 | |
---|
164 | #include <rtems/confdefs.h> |
---|
165 | /* end of file */ |
---|