source: rtems/testsuites/psxtmtests/psxtmmutex02/init.c @ 4a2d1ea

4.115
Last change on this file since 4a2d1ea was 4a2d1ea, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/08/11 at 08:26:13

2011-02-08 Ralf Corsépius <ralf.corsepius@…>

  • psxtmmutex02/init.c, psxtmthread03/init.c: end_time is a uint32_t.
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2010.
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#include <coverhd.h>
13#include <tmacros.h>
14#include <timesys.h>
15#include "test_support.h"
16#include <pthread.h>
17#include <sched.h>
18#include <rtems/timerdrv.h>
19
20pthread_mutex_t MutexId;
21
22void *Low(
23  void *argument
24)
25{
26  uint32_t end_time;
27
28  /*
29   * Now we have finished the thread startup overhead,
30   * so let other threads run.  When we return, we can
31   * finish the benchmark.
32   */
33  sched_yield();
34    /* let other threads run */
35
36  end_time = benchmark_timer_read();
37
38  put_time(
39    "pthread_mutex_lock (unavailable)",
40    end_time,
41    OPERATION_COUNT,
42    0,
43    0
44  );
45
46  puts( "*** END OF POSIX TIME TEST MUTEX 02 ***" );
47
48  rtems_test_exit( 0 );
49  return NULL;
50}
51
52void *Middle(
53  void *argument
54)
55{
56  int status;
57
58  /*
59   * Now we have finished the thread startup overhead,
60   * so let other threads run.  When we return, we can
61   * finish the benchmark.
62   */
63  sched_yield();
64    /* let other threads run */
65
66  status = pthread_mutex_lock( &MutexId );
67  rtems_test_assert( !status );
68
69  return NULL;
70}
71
72void *POSIX_Init(
73  void *argument
74)
75{
76  int        i;
77  int        status;
78  pthread_t  threadId;
79
80  puts( "\n\n*** POSIX TIME TEST MUTEX 02 ***" );
81
82  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
83    status = pthread_create( &threadId, NULL, Middle, NULL );
84    rtems_test_assert( !status );
85  }
86 
87  status = pthread_create( &threadId, NULL, Low, NULL );
88  rtems_test_assert( !status );
89
90  /*
91   * Deliberately create the mutex after the threads.  This way if the
92   * threads do run before we intend, they will get an error.
93   */
94  status = pthread_mutex_init( &MutexId, NULL );
95  rtems_test_assert( !status );
96
97  /*
98   * Let the other threads start so the thread startup overhead,
99   * is accounted for.  When we return, we can start the benchmark.
100   */
101  sched_yield();
102    /* let other threads run */
103
104  /* start the timer and switch through all the other tasks */
105  benchmark_timer_initialize();
106  status = pthread_mutex_lock( &MutexId );
107  rtems_test_assert( !status );
108
109  return NULL;
110}
111
112/* configuration information */
113
114#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
115#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
116
117#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
118#define CONFIGURE_MAXIMUM_POSIX_MUTEXES     1
119#define CONFIGURE_POSIX_INIT_THREAD_TABLE
120
121#define CONFIGURE_INIT
122
123#include <rtems/confdefs.h>
124  /* end of file */
Note: See TracBrowser for help on using the repository browser.