source: rtems/testsuites/psxtmtests/psxtmrwlock03/init.c @ bb3484c9

5
Last change on this file since bb3484c9 was e58e29fd, checked in by Sebastian Huber <sebastian.huber@…>, on 11/24/17 at 06:58:55

Remove coverhd.h

This header file contained timing overhead values which are hard to
maintain.

Update #3254.

  • Property mode set to 100644
File size: 3.2 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 <tmacros.h>
16#include <sched.h>
17#include <pthread.h>
18#include <rtems/btimer.h>
19#include "test_support.h"
20
21const char rtems_test_name[] = "PSXTMRWLOCK 03";
22
23/* forward declarations to avoid warnings */
24void *POSIX_Init(void *argument);
25void *Middle(void *argument);
26void *Low(void *argument);
27
28pthread_rwlock_t     rwlock;
29struct timespec      abstime;
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_timedrdlock: 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
75  /* this timed read lock operation will be blocked
76   * cause a write operation has the lock */
77    status = pthread_rwlock_timedrdlock(&rwlock, &abstime);
78  rtems_test_assert( status == 0 );
79  return NULL;
80}
81
82void *POSIX_Init(
83  void *argument
84)
85{
86  int        i;
87  int        status;
88  pthread_t  threadId;
89  pthread_rwlockattr_t attr;
90
91  TEST_BEGIN();
92
93  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
94    status = pthread_create( &threadId, NULL, Middle, NULL );
95    rtems_test_assert( !status );
96  }
97
98  status = pthread_create( &threadId, NULL, Low, NULL );
99  rtems_test_assert( !status );
100
101  /*
102   *  Timeout for 5 seconds from now.
103   */
104  status = clock_gettime( CLOCK_REALTIME, &abstime );
105  rtems_test_assert( !status );
106  abstime.tv_sec += 5;
107
108  /*
109   * Deliberately create the rwlock after the threads.  This way if the
110   * threads do run before we intend, they will get an error.
111   */
112  status = pthread_rwlockattr_init( &attr );
113  rtems_test_assert( status == 0 );
114    status = pthread_rwlock_init( &rwlock, &attr );
115  rtems_test_assert( status == 0 );
116
117  /*
118   * Let the other threads start so the thread startup overhead,
119   * is accounted for.  When we return, we can start the benchmark.
120   */
121  sched_yield();
122    /* let other threads run */
123
124  /* start the timer and switch through all the other tasks */
125  benchmark_timer_initialize();
126
127  /*
128   * Write lock operation, this could be any write lock
129   */
130    status = pthread_rwlock_timedwrlock(&rwlock,0);
131  rtems_test_assert( status == 0 );
132  return NULL;
133}
134
135/* configuration information */
136
137#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
138#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
139
140#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
141#define CONFIGURE_POSIX_INIT_THREAD_TABLE
142
143#define CONFIGURE_INIT
144
145#include <rtems/confdefs.h>
146/* end of file */
Note: See TracBrowser for help on using the repository browser.