source: rtems/testsuites/psxtmtests/psxtmbarrier04/init.c @ 086494d5

4.115
Last change on this file since 086494d5 was 086494d5, checked in by Joel Sherrill <joel.sherrill@…>, on 11/30/13 at 22:06:23

psxtmbarrier04/init.c: Fix warnings

  • Property mode set to 100644
File size: 2.3 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.com/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
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
20/* forward declarations to avoid warnings */
21void *POSIX_Init(void *argument);
22void *Blocker(void *argument);
23
24#define N  2
25pthread_barrier_t     barrier;
26
27void *Blocker(
28  void *argument
29)
30{
31  benchmark_timer_t end_time;
32
33  /* block on barrier wait, switch back to first thread */
34  (void) pthread_barrier_wait( &barrier );
35
36
37  /* preempt first thread and stop time */
38  end_time = benchmark_timer_read();
39  put_time(
40    "pthread_barrier_wait – releasing, preempt",
41    end_time,
42    1,
43    0,
44    0
45  );
46  puts( "*** END OF POSIX TIME TEST PSXTMBARRIER 04 ***" );
47  rtems_test_exit( 0 );
48
49}
50
51void *POSIX_Init(
52  void *argument
53)
54{
55  int        status;
56  pthread_t  threadId;
57  int policy;
58  struct sched_param param;
59
60  puts( "\n\n*** POSIX TIME TEST PSXTMBARRIER 04 ***" );
61
62  status = pthread_create( &threadId, NULL, Blocker, NULL );
63  rtems_test_assert( status == 0 );
64  status = pthread_barrier_init( &barrier, NULL, N );
65  rtems_test_assert( status == 0 );
66
67  /* yield to second thread so it can start up and block */
68  sched_yield();
69
70  pthread_getschedparam(threadId, &policy, &param);
71  param.sched_priority = sched_get_priority_max(policy) - 1;
72  /* preempt doesn't occur here due to second thread being blocked */
73  pthread_setschedparam(threadId, policy, &param);
74
75  /* as soon as this thread waits on barrier, release occurs, 2nd thread
76   * preempts this one due to having a higher priority
77   */
78  benchmark_timer_initialize();
79  status = pthread_barrier_wait( &barrier );
80
81  /* avoid warning but should not be executed */
82  return NULL;
83}
84
85/* configuration information */
86
87#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
88#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
89
90#define CONFIGURE_MAXIMUM_POSIX_THREADS     2
91#define CONFIGURE_MAXIMUM_POSIX_BARRIERS    1
92#define CONFIGURE_POSIX_INIT_THREAD_TABLE
93
94#define CONFIGURE_INIT
95
96#include <rtems/confdefs.h>
97/* end of file */
Note: See TracBrowser for help on using the repository browser.