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

Last change on this file was 94fa540, checked in by Joel Sherrill <joel@…>, on 04/07/22 at 16:16:26

testsuites/psxtmtests: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 *  COPYRIGHT (c) 1989-2013.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32#include <errno.h>
33#include <timesys.h>
34#include <tmacros.h>
35#include <pthread.h>
36#include <sched.h>
37#include <rtems/btimer.h>
38#include "test_support.h"
39
40const char rtems_test_name[] = "PSXTMRWLOCK 02";
41
42/* forward declarations to avoid warnings */
43void *POSIX_Init(void *argument);
44void *Middle(void *argument);
45void *Low(void *argument);
46
47pthread_rwlock_t     rwlock;
48
49void *Low(
50  void *argument
51)
52{
53  benchmark_timer_t end_time;
54
55  /*
56   * Now we have finished the thread startup overhead,
57   * so let other threads run.  When we return, we can
58   * finish the benchmark.
59   */
60  sched_yield();
61    /* let other threads run */
62
63  end_time = benchmark_timer_read();
64
65  put_time(
66    "pthread_rwlock_rdlock: not available blocks",
67    end_time,
68    OPERATION_COUNT,
69    0,
70    0
71  );
72
73  TEST_END();
74
75  rtems_test_exit( 0 );
76  return NULL;
77}
78
79void *Middle(
80  void *argument
81)
82{
83  int status;
84
85  /*
86   * Now we have finished the thread startup overhead,
87   * so let other threads run.  When we return, we can
88   * finish the benchmark.
89   */
90  sched_yield();
91    /* let other threads run */
92  /* this read lock operation will be blocked
93   * cause a write operation has the lock */
94    status = pthread_rwlock_rdlock(&rwlock);
95  rtems_test_assert( status == 0 );
96  return NULL;
97}
98
99void *POSIX_Init(
100  void *argument
101)
102{
103  int        i;
104  int        status;
105  pthread_t  threadId;
106  pthread_rwlockattr_t attr;
107
108  TEST_BEGIN();
109
110  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
111    status = pthread_create( &threadId, NULL, Middle, NULL );
112    rtems_test_assert( !status );
113  }
114
115  status = pthread_create( &threadId, NULL, Low, NULL );
116  rtems_test_assert( !status );
117
118  /*
119   * Deliberately create the rwlock after the threads.  This way if the
120   * threads do run before we intend, they will get an error.
121   */
122  status = pthread_rwlockattr_init( &attr );
123  rtems_test_assert( status == 0 );
124    status = pthread_rwlock_init( &rwlock, &attr );
125  rtems_test_assert( status == 0 );
126  /*
127   * Let the other threads start so the thread startup overhead,
128   * is accounted for.  When we return, we can start the benchmark.
129   */
130  sched_yield();
131    /* let other threads run */
132
133  /* start the timer and switch through all the other tasks */
134  benchmark_timer_initialize();
135  /* write lock operation */
136    status = pthread_rwlock_wrlock(&rwlock);
137  rtems_test_assert( status == 0 );
138  return NULL;
139}
140
141/* configuration information */
142
143#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
144#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
145
146#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
147#define CONFIGURE_POSIX_INIT_THREAD_TABLE
148
149#define CONFIGURE_INIT
150
151#include <rtems/confdefs.h>
152  /* end of file */
Note: See TracBrowser for help on using the repository browser.