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

4.11
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2014 at 1:59:49 PM

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: 3.0 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 <coverhd.h>
14#include <errno.h>
15#include <timesys.h>
16#include <tmacros.h>
17#include <pthread.h>
18#include <sched.h>
19#include <rtems/btimer.h>
20#include "test_support.h"
21
22const char rtems_test_name[] = "PSXTMRWLOCK 02";
23
24/* forward declarations to avoid warnings */
25void *POSIX_Init(void *argument);
26void *Middle(void *argument);
27void *Low(void *argument);
28
29pthread_rwlock_t     rwlock;
30
31void *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_rwlock_rdlock: not available blocks",
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
61void *Middle(
62  void *argument
63)
64{
65  int status;
66
67  /*
68   * Now we have finished the thread startup overhead,
69   * so let other threads run.  When we return, we can
70   * finish the benchmark.
71   */
72  sched_yield();
73    /* let other threads run */
74  /* this read lock operation will be blocked
75   * cause a write operation has the lock */
76    status = pthread_rwlock_rdlock(&rwlock);
77  rtems_test_assert( status == 0 );
78  return NULL;
79}
80
81void *POSIX_Init(
82  void *argument
83)
84{
85  int        i;
86  int        status;
87  pthread_t  threadId;
88  pthread_rwlockattr_t attr;
89
90  TEST_BEGIN();
91
92  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
93    status = pthread_create( &threadId, NULL, Middle, NULL );
94    rtems_test_assert( !status );
95  }
96
97  status = pthread_create( &threadId, NULL, Low, NULL );
98  rtems_test_assert( !status );
99
100  /*
101   * Deliberately create the rwlock after the threads.  This way if the
102   * threads do run before we intend, they will get an error.
103   */
104  status = pthread_rwlockattr_init( &attr );
105  rtems_test_assert( status == 0 );
106    status = pthread_rwlock_init( &rwlock, &attr );
107  rtems_test_assert( status == 0 );
108  /*
109   * Let the other threads start so the thread startup overhead,
110   * is accounted for.  When we return, we can start the benchmark.
111   */
112  sched_yield();
113    /* let other threads run */
114
115  /* start the timer and switch through all the other tasks */
116  benchmark_timer_initialize();
117  /* write lock operation */
118    status = pthread_rwlock_wrlock(&rwlock);
119  rtems_test_assert( status == 0 );
120  return NULL;
121}
122
123/* configuration information */
124
125#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
126#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
127
128#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
129#define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
130#define CONFIGURE_POSIX_INIT_THREAD_TABLE
131
132#define CONFIGURE_INIT
133
134#include <rtems/confdefs.h>
135  /* end of file */
Note: See TracBrowser for help on using the repository browser.