source: rtems/testsuites/psxtmtests/psxtmrwlock03/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.3 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 <sched.h>
18#include <pthread.h>
19#include <rtems/btimer.h>
20#include "test_support.h"
21
22const char rtems_test_name[] = "PSXTMRWLOCK 03";
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;
30struct timespec      abstime;
31
32void *Low(
33  void *argument
34)
35{
36  benchmark_timer_t end_time;
37
38  /*
39   * Now we have finished the thread startup overhead,
40   * so let other threads run.  When we return, we can
41   * finish the benchmark.
42   */
43  sched_yield();
44    /* let other threads run */
45
46  end_time = benchmark_timer_read();
47
48  put_time(
49    "pthread_rwlock_timedrdlock: not available blocks",
50    end_time,
51    OPERATION_COUNT,
52    0,
53    0
54  );
55
56  TEST_END();
57
58  rtems_test_exit( 0 );
59  return NULL;
60}
61
62void *Middle(
63  void *argument
64)
65{
66  int status;
67
68  /*
69   * Now we have finished the thread startup overhead,
70   * so let other threads run.  When we return, we can
71   * finish the benchmark.
72   */
73  sched_yield();
74    /* let other threads run */
75
76  /* this timed read lock operation will be blocked
77   * cause a write operation has the lock */
78    status = pthread_rwlock_timedrdlock(&rwlock, &abstime);
79  rtems_test_assert( status == 0 );
80  return NULL;
81}
82
83void *POSIX_Init(
84  void *argument
85)
86{
87  int        i;
88  int        status;
89  pthread_t  threadId;
90  pthread_rwlockattr_t attr;
91
92  TEST_BEGIN();
93
94  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
95    status = pthread_create( &threadId, NULL, Middle, NULL );
96    rtems_test_assert( !status );
97  }
98
99  status = pthread_create( &threadId, NULL, Low, NULL );
100  rtems_test_assert( !status );
101
102  /*
103   *  Timeout for 5 seconds from now.
104   */
105  status = clock_gettime( CLOCK_REALTIME, &abstime );
106  rtems_test_assert( !status );
107  abstime.tv_sec += 5;
108
109  /*
110   * Deliberately create the rwlock after the threads.  This way if the
111   * threads do run before we intend, they will get an error.
112   */
113  status = pthread_rwlockattr_init( &attr );
114  rtems_test_assert( status == 0 );
115    status = pthread_rwlock_init( &rwlock, &attr );
116  rtems_test_assert( status == 0 );
117
118  /*
119   * Let the other threads start so the thread startup overhead,
120   * is accounted for.  When we return, we can start the benchmark.
121   */
122  sched_yield();
123    /* let other threads run */
124
125  /* start the timer and switch through all the other tasks */
126  benchmark_timer_initialize();
127
128  /*
129   * Write lock operation, this could be any write lock
130   */
131    status = pthread_rwlock_timedwrlock(&rwlock,0);
132  rtems_test_assert( status == 0 );
133  return NULL;
134}
135
136/* configuration information */
137
138#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
139#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
140
141#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
142#define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
143#define CONFIGURE_POSIX_INIT_THREAD_TABLE
144
145#define CONFIGURE_INIT
146
147#include <rtems/confdefs.h>
148/* end of file */
Note: See TracBrowser for help on using the repository browser.