source: rtems/testsuites/psxtmtests/psxtmcond07/init.c @ 8fbe2e6

4.115
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/14 at 13:59:49

Use correct prototype of benchmark_timer_read()

This change starts with removing the effectively empty file
timerdrv.h. The prototypes for benchmark_timer_XXX() were in
btimer.h which was not universally used. Thus every use of
timerdrv.h had to be changed to btimer.h. Then the prototypes
for benchmark_timer_read() had to be adjusted to return
benchmark_timer_t rather than int or uint32_t.

I took this opportunity to also correct the file headers to
separate the copyright from the file description comments which
is needed to ensure the copyright isn't propagated into Doxygen
output.

  • 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 <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
22#define N 1
23
24const char rtems_test_name[] = "PSXTMCOND 07";
25
26/* forward declarations to avoid warnings */
27void *POSIX_Init(void *argument);
28void *Blocker(void *argument);
29
30pthread_mutex_t MutexID;
31pthread_cond_t CondID;
32
33void *Blocker(
34  void *argument
35)
36{
37  int                status;
38  benchmark_timer_t  end_time;
39
40  status = pthread_mutex_lock(&MutexID);
41  rtems_test_assert( status == 0 );
42
43  /* Unlock mutex, block, wait for CondID to be signaled */
44  pthread_cond_wait(&CondID,&MutexID);
45
46  end_time = benchmark_timer_read();
47  put_time(
48    "pthread_cond_broadcast: threads waiting, preempt",
49    end_time,
50    1,
51    0,
52    0
53  );
54
55  TEST_END();
56  rtems_test_exit( 0 );
57  return NULL;
58
59}
60
61void *POSIX_Init(
62  void *argument
63)
64{
65  int                 status;
66  int                 i;
67  pthread_t           threadId;
68  pthread_attr_t      attr;
69  struct sched_param  param;
70
71  TEST_BEGIN();
72
73  /* Setup variables */
74  status = pthread_create( &threadId, NULL, Blocker, NULL );
75  rtems_test_assert( status == 0 );
76
77  status = pthread_mutex_init(&MutexID, NULL);
78  rtems_test_assert( status == 0 );
79
80  status = pthread_cond_init(&CondID, NULL);
81  rtems_test_assert( status == 0 );
82
83 /* Setup so threads are created with a high enough priority to preempt
84  * as they get created.
85  */
86  status = pthread_attr_init( &attr );
87  rtems_test_assert( status == 0 );
88
89  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
90  rtems_test_assert( status == 0 );
91
92  status = pthread_attr_setschedpolicy( &attr, SCHED_FIFO );
93  rtems_test_assert( status == 0 );
94
95  param.sched_priority = sched_get_priority_max(SCHED_FIFO);
96  status = pthread_attr_setschedparam( &attr, &param );
97  rtems_test_assert( status == 0 );
98
99  for ( i=0 ; i < N ; i++ ) {
100    /* Threads will preempt as they are created, start up, and block */
101    status = pthread_create(&threadId, &attr, Blocker, NULL);
102    rtems_test_assert( status == 0 );
103  }
104
105  /* broadcast will awaken all threads and one will preempt us, end time
106   * in other thread
107   */
108  benchmark_timer_initialize();
109  status = pthread_cond_broadcast(&CondID);
110
111  /* Should never reach this point */
112  rtems_test_assert( FALSE );
113  return NULL;
114}
115
116/* configuration information */
117
118#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
119#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
120
121#define CONFIGURE_MAXIMUM_POSIX_THREADS  2 + N
122#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 1
123#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 1
124#define CONFIGURE_POSIX_INIT_THREAD_TABLE
125
126#define CONFIGURE_INIT
127
128#include <rtems/confdefs.h>
129  /* end of file */
Note: See TracBrowser for help on using the repository browser.