source: rtems/testsuites/psxtmtests/psxtmmutex06/init.c @ a87d1b1

4.115
Last change on this file since a87d1b1 was a87d1b1, checked in by Joel Sherrill <joel.sherrill@…>, on 07/20/11 at 21:39:25

2011-07-20 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac, psxtmtests_plan.csv: Add benchmark of pthread_mutex_unlock where it is unblocking threads with preemption.
  • psxtmmutex06/.cvsignore, psxtmmutex06/Makefile.am, psxtmmutex06/init.c, psxtmmutex06/psxtmmutex06.doc: New files.
  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[a87d1b1]1/*
2 *  COPYRIGHT (c) 1989-2011.
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.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <coverhd.h>
17#include <tmacros.h>
18#include <timesys.h>
19#include "test_support.h"
20#include <pthread.h>
21#include <sched.h>
22#include <rtems/timerdrv.h>
23
24pthread_mutex_t MutexId;
25
26void *Low(
27  void *argument
28)
29{
30  int      status;
31  uint32_t end_time;
32
33    status = pthread_mutex_lock( &MutexId );
34  end_time = benchmark_timer_read();
35
36  rtems_test_assert( status == 0 );
37
38  put_time(
39    "pthread_mutex_unlock (unblocking, prempt)",
40    end_time,
41    OPERATION_COUNT,
42    0,
43    0
44  );
45
46  puts( "*** END OF POSIX TIME TEST MUTEX 07 ***" );
47  rtems_test_exit( 0 );
48  return NULL;
49}
50
51void *Middle(
52  void *argument
53)
54{
55  int status;
56
57  status = pthread_mutex_lock( &MutexId );
58  rtems_test_assert( status == 0 );
59
60    /* thread switch occurs */
61
62  status = pthread_mutex_unlock( &MutexId );
63  rtems_test_assert( status == 0 );
64
65    /* thread switch occurs */
66
67  return NULL;
68}
69
70void *POSIX_Init(
71  void *argument
72)
73{
74  int                 i;
75  int                 status;
76  pthread_t           threadId;
77  pthread_attr_t      attr;
78  struct sched_param  param;
79
80  puts( "\n\n*** POSIX TIME TEST MUTEX 02 ***" );
81
82  /*
83   * Deliberately create the mutex BEFORE the threads.  This way the
84   * threads should preempt this thread and block as they are created.
85   */
86  status = pthread_mutex_init( &MutexId, NULL );
87  rtems_test_assert( status == 0 );
88
89  /*
90   * Lock the mutex so the threads will block.
91   */
92  status = pthread_mutex_lock( &MutexId );
93  rtems_test_assert( status == 0 );
94
95  /*
96   * Now lower our priority
97   */
98  status = pthread_attr_init( &attr );
99  rtems_test_assert( status == 0 );
100
101  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
102  rtems_test_assert( status == 0 );
103
104  status = pthread_attr_setschedpolicy( &attr, SCHED_RR );
105  rtems_test_assert( status == 0 );
106
107  param.sched_priority = 2;
108  status = pthread_attr_setschedparam( &attr, &param );
109  rtems_test_assert( status == 0 );
110
111  /*
112   * And create rest of threads as more important than we are.  They
113   * will preempt us as they are created and block.
114   */
115  for ( i=0 ; i < OPERATION_COUNT ; i++ ) {
116
117    param.sched_priority = 3 + i;
118    status = pthread_attr_setschedparam( &attr, &param );
119    rtems_test_assert( status == 0 );
120
121    status = pthread_create(
122      &threadId,
123      &attr,
124      (i == OPERATION_COUNT - 1) ? Low : Middle,
125      NULL
126    );
127    rtems_test_assert( status == 0 );
128  }
129 
130  /*
131   * Now start the timer which will be stopped in Low
132   */
133  benchmark_timer_initialize();
134
135    status = pthread_mutex_unlock( &MutexId );
136    rtems_test_assert( status == 0 );
137
138      /* thread switch occurs */
139  return NULL;
140}
141
142/* configuration information */
143
144#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
145#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
146
147#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
148#define CONFIGURE_MAXIMUM_POSIX_MUTEXES     1
149#define CONFIGURE_POSIX_INIT_THREAD_TABLE
150
151#define CONFIGURE_INIT
152
153#include <rtems/confdefs.h>
154  /* end of file */
Note: See TracBrowser for help on using the repository browser.