source: rtems/testsuites/psxtmtests/psxtmrwlock02/init.c @ 2ead50a

4.115
Last change on this file since 2ead50a was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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