source: rtems/testsuites/psxtmtests/psxtmrwlock02/init.c

Last change on this file was e58e29f, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 24, 2017 at 6:58:55 AM

Remove coverhd.h

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

Update #3254.

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