source: rtems/testsuites/psxtmtests/psxtmrwlock04/init.c @ fd46711

4.115
Last change on this file since fd46711 was fd46711, checked in by bjorn larsson <bjornlarsson@…>, on 03/21/14 at 20:35:26

psxtmtests: Add test.h support

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[a6284c9e]1/*
[50162e0]2 *  COPYRIGHT (c) 1989-2013.
[a6284c9e]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
[c499856]7 *  http://www.rtems.org/license/LICENSE.
[a6284c9e]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/timerdrv.h>
20#include "test_support.h"
21
[fd46711]22const char rtems_test_name[] = "PSXTMRWLOCK 04";
23
[991a3cc1]24/* forward declarations to avoid warnings */
25void *POSIX_Init(void *argument);
26void *Middle(void *argument);
27void *Low(void *argument);
28
[a6284c9e]29pthread_rwlock_t     rwlock;
30
31void *Low(
32  void *argument
33)
34{
[add2977]35  benchmark_timer_t end_time;
[a6284c9e]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(
[50162e0]48    "pthread_rwlock_wrlock: not available blocks",
[a6284c9e]49    end_time,
50    OPERATION_COUNT,
51    0,
52    0
53  );
54
[fd46711]55  TEST_END();
[a6284c9e]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 write lock operation will be blocked
76   * cause another write operation has the lock */
77    status = pthread_rwlock_wrlock(&rwlock);
78  rtems_test_assert( status == 0 );
79  return NULL;
80}
81
82void *POSIX_Init(
83  void *argument
84)
85{
86  int        i;
87  int        status;
88  pthread_t  threadId;
89  pthread_rwlockattr_t attr;
90
[fd46711]91  TEST_BEGIN();
[a6284c9e]92
93  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
94    status = pthread_create( &threadId, NULL, Middle, NULL );
95    rtems_test_assert( !status );
96  }
97 
98  status = pthread_create( &threadId, NULL, Low, NULL );
99  rtems_test_assert( !status );
100
101  /*
102   * Deliberately create the rwlock after the threads.  This way if the
103   * threads do run before we intend, they will get an error.
104   */
105  status = pthread_rwlockattr_init( &attr );
106  rtems_test_assert( status == 0 );
107    status = pthread_rwlock_init( &rwlock, &attr );
108  rtems_test_assert( status == 0 );
109  /*
110   * Let the other threads start so the thread startup overhead,
111   * is accounted for.  When we return, we can start the benchmark.
112   */
113  sched_yield();
114    /* let other threads run */
115 
116  /* start the timer and switch through all the other tasks */
117  benchmark_timer_initialize();
118  /* write lock operation */
119    status = pthread_rwlock_wrlock(&rwlock);
120  rtems_test_assert( status == 0 );
121  return NULL;
122}
123
124/* configuration information */
125
126#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
127#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
128
129#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
130#define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
131#define CONFIGURE_POSIX_INIT_THREAD_TABLE
132
133#define CONFIGURE_INIT
134
135#include <rtems/confdefs.h>
136/* end of file */
Note: See TracBrowser for help on using the repository browser.