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