source: rtems/testsuites/psxtmtests/psxtmrwlock01/init.c @ 8fbe2e6

4.115
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/14 at 13:59:49

Use correct prototype of benchmark_timer_read()

This change starts with removing the effectively empty file
timerdrv.h. The prototypes for benchmark_timer_XXX() were in
btimer.h which was not universally used. Thus every use of
timerdrv.h had to be changed to btimer.h. Then the prototypes
for benchmark_timer_read() had to be adjusted to return
benchmark_timer_t rather than int or uint32_t.

I took this opportunity to also correct the file headers to
separate the copyright from the file description comments which
is needed to ensure the copyright isn't propagated into Doxygen
output.

  • Property mode set to 100644
File size: 6.1 KB
Line 
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#include <errno.h>
14#include <timesys.h>
15#include <rtems/btimer.h>
16#include <pthread.h>
17#include "test_support.h"
18
19const char rtems_test_name[] = "PSXTMRWLOCK 01";
20
21/* forward declarations to avoid warnings */
22void *POSIX_Init(void *argument);
23
24pthread_rwlock_t     rwlock;
25
26static void benchmark_pthread_rwlock_init(void)
27{
28  benchmark_timer_t end_time;
29  int  status;
30  pthread_rwlockattr_t attr;
31
32  pthread_rwlockattr_init( &attr );
33  benchmark_timer_initialize();
34    status = pthread_rwlock_init( &rwlock, &attr );
35  end_time = benchmark_timer_read();
36  rtems_test_assert( status == 0 );
37
38  put_time(
39    "pthread_rwlock_init: only case",
40    end_time,
41    1,        /* Only executed once */
42    0,
43    0
44  );
45
46}
47
48static void benchmark_pthread_rwlock_rdlock(void)
49{
50  benchmark_timer_t end_time;
51  int  status;
52
53  benchmark_timer_initialize();
54    status = pthread_rwlock_rdlock(&rwlock);
55  end_time = benchmark_timer_read();
56  rtems_test_assert( status == 0 );
57
58  put_time(
59    "pthread_rwlock_rdlock: available",
60    end_time,
61    1,        /* Only executed once */
62    0,
63    0
64  );
65
66}
67
68static void benchmark_pthread_rwlock_unlock(int print)
69{
70  benchmark_timer_t end_time;
71  int  status;
72
73  benchmark_timer_initialize();
74    status = pthread_rwlock_unlock(&rwlock);
75  end_time = benchmark_timer_read();
76  rtems_test_assert( status == 0 );
77  if ( print == 1 ){
78    put_time(
79      "pthread_rwlock_unlock: available",
80      end_time,
81      1,        /* Only executed once */
82      0,
83      0
84    );
85  }
86}
87
88static void benchmark_pthread_rwlock_tryrdlock(void)
89{
90  benchmark_timer_t end_time;
91  int  status;
92
93  benchmark_timer_initialize();
94    status = pthread_rwlock_tryrdlock(&rwlock);
95  end_time = benchmark_timer_read();
96  rtems_test_assert( status == 0 || status == EBUSY );
97  if (status == EBUSY) {
98    put_time(
99      "pthread_rwlock_tryrdlock: not available",
100      end_time,
101      1,        /* Only executed once */
102      0,
103      0
104    );
105  } else if (status == 0) {
106    put_time(
107      "pthread_rwlock_tryrdlock: available",
108      end_time,
109      1,        /* Only executed once */
110      0,
111      0
112    );
113  }
114}
115
116static void benchmark_pthread_rwlock_timedrdlock(void)
117{
118  benchmark_timer_t end_time;
119  int  status;
120
121  benchmark_timer_initialize();
122    status = pthread_rwlock_timedrdlock(&rwlock, 0);
123  end_time = benchmark_timer_read();
124  rtems_test_assert( status == 0 );
125
126  put_time(
127    "pthread_rwlock_timedrdlock: available",
128    end_time,
129    1,        /* Only executed once */
130    0,
131    0
132  );
133
134}
135
136static void benchmark_pthread_rwlock_wrlock(void)
137{
138  benchmark_timer_t end_time;
139  int  status;
140
141  benchmark_timer_initialize();
142    status = pthread_rwlock_wrlock(&rwlock);
143  end_time = benchmark_timer_read();
144  rtems_test_assert( status == 0 );
145
146  put_time(
147    "pthread_rwlock_wrlock: available",
148    end_time,
149    1,        /* Only executed once */
150    0,
151    0
152  );
153
154}
155
156static void benchmark_pthread_rwlock_trywrlock(void)
157{
158  benchmark_timer_t end_time;
159  int  status;
160
161  benchmark_timer_initialize();
162    status = pthread_rwlock_trywrlock(&rwlock);
163  end_time = benchmark_timer_read();
164
165  rtems_test_assert( status == 0 || status == EBUSY );
166  if ( status == EBUSY ) {
167    put_time(
168      "pthread_rwlock_trywrlock: not available ",
169      end_time,
170      1,        /* Only executed once */
171      0,
172      0
173    );
174  } else if ( status == 0 ) {
175    put_time(
176      "pthread_rwlock_trywrlock: available",
177      end_time,
178      1,        /* Only executed once */
179      0,
180      0
181    );
182  }
183}
184
185static void benchmark_pthread_rwlock_timedwrlock(void)
186{
187  benchmark_timer_t end_time;
188  int  status;
189
190  benchmark_timer_initialize();
191    status = pthread_rwlock_timedwrlock(&rwlock,0);
192  end_time = benchmark_timer_read();
193  rtems_test_assert( status == 0 );
194
195  put_time(
196    "pthread_rwlock_timedwrlock: available",
197    end_time,
198    1,        /* Only executed once */
199    0,
200    0
201  );
202}
203
204static void benchmark_pthread_rwlock_destroy(void)
205{
206  benchmark_timer_t end_time;
207  int  status;
208
209  benchmark_timer_initialize();
210    status = pthread_rwlock_destroy(&rwlock);
211  end_time = benchmark_timer_read();
212  rtems_test_assert( status == 0 );
213
214  put_time(
215    "pthread_rwlock_destroy: only case",
216    end_time,
217    1,        /* Only executed once */
218    0,
219    0
220  );
221}
222
223void *POSIX_Init(
224  void *argument
225)
226{
227
228  TEST_BEGIN();
229
230  /* initializing rwlock */
231  benchmark_pthread_rwlock_init();
232  /* applying a read lock */
233  benchmark_pthread_rwlock_rdlock();
234  /* unlocking rwlock */
235  benchmark_pthread_rwlock_unlock(0);
236  /* trying to apply a read lock when it is available*/
237  benchmark_pthread_rwlock_tryrdlock();
238  /* unlocking rwlock */
239  benchmark_pthread_rwlock_unlock(0);
240  /* applying a timed read lock */
241  benchmark_pthread_rwlock_timedrdlock();
242  /* unlocking rwlock */
243  benchmark_pthread_rwlock_unlock(0);
244  /* applying a write lock */
245  benchmark_pthread_rwlock_wrlock();
246  /* trying to get read lock, when is not available*/
247  benchmark_pthread_rwlock_tryrdlock();
248  /* unlocking rwlock */
249  benchmark_pthread_rwlock_unlock(0);
250  /* trying to apply a write lock, when it is available*/
251  benchmark_pthread_rwlock_trywrlock();
252  /* trying to get write lock, when it is not available*/
253  benchmark_pthread_rwlock_trywrlock();
254  /* unlocking rwlock */
255  benchmark_pthread_rwlock_unlock(0);
256  /* applying a timed write lock */
257  benchmark_pthread_rwlock_timedwrlock();
258  /* unlocking rwlock */
259  benchmark_pthread_rwlock_unlock(1);
260  /* destroying rwlock */
261  benchmark_pthread_rwlock_destroy();
262
263  TEST_END();
264
265  rtems_test_exit(0);
266}
267
268/* configuration information */
269
270#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
271#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
272
273#define CONFIGURE_MAXIMUM_POSIX_THREADS     1
274#define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
275#define CONFIGURE_POSIX_INIT_THREAD_TABLE
276
277#define CONFIGURE_INIT
278
279#include <rtems/confdefs.h>
280/* end of file */
Note: See TracBrowser for help on using the repository browser.