source: rtems/testsuites/psxtmtests/psxtmmutex02/init.c @ c499856

4.115
Last change on this file since c499856 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: 2.8 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
14#include <coverhd.h>
15#include <tmacros.h>
16#include <timesys.h>
17#include "test_support.h"
18#include <pthread.h>
19#include <sched.h>
20#include <rtems/timerdrv.h>
21
22/* forward declarations to avoid warnings */
23void *POSIX_Init(void *argument);
24void *Middle(void *argument);
25void *Low(void *argument);
26
27pthread_mutex_t MutexId;
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_mutex_lock: unavailable block",
47    end_time,
48    OPERATION_COUNT,
49    0,
50    0
51  );
52
53  puts( "*** END OF POSIX TIME TEST PSXTMMUTEX02 ***" );
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
73  status = pthread_mutex_lock( &MutexId );
74  rtems_test_assert( !status );
75
76  return NULL;
77}
78
79void *POSIX_Init(
80  void *argument
81)
82{
83  int        i;
84  int        status;
85  pthread_t  threadId;
86
87  puts( "\n\n*** POSIX TIME TEST PSXTMMUTEX02 ***" );
88
89  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
90    status = pthread_create( &threadId, NULL, Middle, NULL );
91    rtems_test_assert( !status );
92  }
93 
94  status = pthread_create( &threadId, NULL, Low, NULL );
95  rtems_test_assert( !status );
96
97  /*
98   * Deliberately create the mutex after the threads.  This way if the
99   * threads do run before we intend, they will get an error.
100   */
101  status = pthread_mutex_init( &MutexId, NULL );
102  rtems_test_assert( !status );
103
104  /*
105   * Let the other threads start so the thread startup overhead,
106   * is accounted for.  When we return, we can start the benchmark.
107   */
108  sched_yield();
109    /* let other threads run */
110
111  /* start the timer and switch through all the other tasks */
112  benchmark_timer_initialize();
113  status = pthread_mutex_lock( &MutexId );
114  rtems_test_assert( !status );
115
116  return NULL;
117}
118
119/* configuration information */
120
121#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
122#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
123
124#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
125#define CONFIGURE_MAXIMUM_POSIX_MUTEXES     1
126#define CONFIGURE_POSIX_INIT_THREAD_TABLE
127
128#define CONFIGURE_INIT
129
130#include <rtems/confdefs.h>
131  /* end of file */
Note: See TracBrowser for help on using the repository browser.