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

5
Last change on this file since de59c065 was de59c065, checked in by Sebastian Huber <sebastian.huber@…>, on 09/27/17 at 13:08:33

posix: Implement self-contained POSIX mutex

POSIX mutexes are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3112.

  • Property mode set to 100644
File size: 2.7 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/btimer.h>
21
22const char rtems_test_name[] = "PSXTMMUTEX 02";
23
24/* forward declarations to avoid warnings */
25void *POSIX_Init(void *argument);
26void *Middle(void *argument);
27void *Low(void *argument);
28
29pthread_mutex_t MutexId;
30
31void *Low(
32  void *argument
33)
34{
35  benchmark_timer_t end_time;
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(
48    "pthread_mutex_lock: unavailable block",
49    end_time,
50    OPERATION_COUNT,
51    0,
52    0
53  );
54
55  TEST_END();
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  status = pthread_mutex_lock( &MutexId );
76  rtems_test_assert( !status );
77
78  return NULL;
79}
80
81void *POSIX_Init(
82  void *argument
83)
84{
85  int        i;
86  int        status;
87  pthread_t  threadId;
88
89  TEST_BEGIN();
90
91  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
92    status = pthread_create( &threadId, NULL, Middle, NULL );
93    rtems_test_assert( !status );
94  }
95 
96  status = pthread_create( &threadId, NULL, Low, NULL );
97  rtems_test_assert( !status );
98
99  /*
100   * Deliberately create the mutex after the threads.  This way if the
101   * threads do run before we intend, they will get an error.
102   */
103  status = pthread_mutex_init( &MutexId, NULL );
104  rtems_test_assert( !status );
105
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  status = pthread_mutex_lock( &MutexId );
116  rtems_test_assert( !status );
117
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_POSIX_INIT_THREAD_TABLE
128
129#define CONFIGURE_INIT
130
131#include <rtems/confdefs.h>
132  /* end of file */
Note: See TracBrowser for help on using the repository browser.