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

4.11
Last change on this file since fd46711 was fd46711, checked in by bjorn larsson <bjornlarsson@…>, on Mar 21, 2014 at 8:35:26 PM

psxtmtests: Add test.h support

  • Property mode set to 100644
File size: 3.0 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 <timesys.h>
15#include <tmacros.h>
16#include <rtems/timerdrv.h>
17#include "test_support.h"
18
19#include <pthread.h>
20#include <sched.h>
21
22const char rtems_test_name[] = "PSXTMBARRIER 02";
23
24/* forward declarations to avoid warnings */
25void *POSIX_Init(void *argument);
26void *Middle(void *argument);
27void *Low(void *argument);
28
29pthread_barrier_t     barrier;
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_barrier_wait: blocking",
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  /*
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    (void) pthread_barrier_wait( &barrier );
74 
75  /* should never return */
76  rtems_test_assert( FALSE );
77  return NULL;
78}
79
80void *POSIX_Init(
81  void *argument
82)
83{
84  int        i;
85  int        status;
86  pthread_t  threadId;
87  pthread_barrierattr_t attr;
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   * Create the barrier with default attributes and deliberately
101   * create it after the Threads so if they run too early, they
102   * wull fail with an error.
103   */
104  status = pthread_barrierattr_init( &attr );
105  rtems_test_assert( status == 0 );
106
107  /*
108   * Set threshold on count higher than number of threads so all will
109   * block.
110   */
111  status = pthread_barrier_init( &barrier,&attr, OPERATION_COUNT + 2 );
112  rtems_test_assert( status == 0 );
113
114  /*
115   * Let other threads run through their initialization
116   */
117  sched_yield();
118
119  /*
120   * Start the timer and start the blocking barrier wait chain through
121   * all the other tasks.
122   */
123  benchmark_timer_initialize();
124    /* blocking barrier call */
125    status = pthread_barrier_wait( &barrier );
126  rtems_test_assert( status == 0 );
127  return NULL;
128}
129
130/* configuration information */
131
132#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
133#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
134
135#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
136#define CONFIGURE_MAXIMUM_POSIX_BARRIERS    1
137#define CONFIGURE_POSIX_INIT_THREAD_TABLE
138
139#define CONFIGURE_INIT
140
141#include <rtems/confdefs.h>
142  /* end of file */
Note: See TracBrowser for help on using the repository browser.