source: rtems/testsuites/psxtmtests/psxtmrwlock05/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.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 <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 05";
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_timedwrlock: 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 write lock operation will be blocked
76   * because the other write operation has the lock
77   */
78    status = pthread_rwlock_timedwrlock(&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   * 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 
125  /* start the timer and switch through all the other tasks */
126  benchmark_timer_initialize();
127
128  /* write lock operation, this could be any write lock
129   * I decided to use timedwrlock just to continue in the timed line  */
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.