source: rtems/testsuites/psxtmtests/psxtmrwlock05/init.c @ c4b8b147

5
Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

  • 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 05";
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_timedwrlock: 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 write lock operation will be blocked
77   * because the other write operation has the lock
78   */
79    status = pthread_rwlock_timedwrlock(&rwlock, &abstime);
80  rtems_test_assert( status == 0 );
81  return NULL;
82}
83
84void *POSIX_Init(
85  void *argument
86)
87{
88  int        i;
89  int        status;
90  pthread_t  threadId;
91  pthread_rwlockattr_t attr;
92
93  TEST_BEGIN();
94
95  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
96    status = pthread_create( &threadId, NULL, Middle, NULL );
97    rtems_test_assert( !status );
98  }
99 
100  status = pthread_create( &threadId, NULL, Low, NULL );
101  rtems_test_assert( !status );
102
103  /*
104   *  Timeout for 5 seconds from now.
105   */
106  status = clock_gettime( CLOCK_REALTIME, &abstime );
107  rtems_test_assert( !status );
108  abstime.tv_sec += 5;
109
110  /*
111   * Deliberately create the rwlock after the threads.  This way if the
112   * threads do run before we intend, they will get an error.
113   */
114  status = pthread_rwlockattr_init( &attr );
115  rtems_test_assert( status == 0 );
116    status = pthread_rwlock_init( &rwlock, &attr );
117  rtems_test_assert( status == 0 );
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 
126  /* start the timer and switch through all the other tasks */
127  benchmark_timer_initialize();
128
129  /* write lock operation, this could be any write lock
130   * I decided to use timedwrlock just to continue in the timed line  */
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_SIMPLE_CONSOLE_DRIVER
139#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
140
141#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
142#define CONFIGURE_POSIX_INIT_THREAD_TABLE
143
144#define CONFIGURE_INIT
145
146#include <rtems/confdefs.h>
147  /* end of file */
Note: See TracBrowser for help on using the repository browser.