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

4.11
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2014 at 1:59:49 PM

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: 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.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <errno.h>
15#include <fcntl.h>
16#include <semaphore.h>
17#include <coverhd.h>
18#include <tmacros.h>
19#include <timesys.h>
20#include "test_support.h"
21#include <pthread.h>
22#include <sched.h>
23#include <rtems/btimer.h>
24
25const char rtems_test_name[] = "PSXTMSEM 04";
26
27/* forward declarations to avoid warnings */
28void *POSIX_Init(void *argument);
29void *Blocker(void *argument);
30
31#define MAX_SEMS  2
32
33sem_t           sem1;
34sem_t           *n_sem1;
35
36void *Blocker( void *argument)
37{
38  (void) sem_wait(&sem1);
39  /* should never return */
40  rtems_test_assert( FALSE );
41
42  return NULL;
43}
44
45void *POSIX_Init(void *argument)
46{
47  int        status;
48  pthread_t  threadId;
49  benchmark_timer_t end_time;
50
51  TEST_BEGIN();
52
53  status = pthread_create( &threadId, NULL, Blocker, NULL );
54  rtems_test_assert( status == 0 );
55 
56  /*
57   * Deliberately create the semaphore after the threads.  This way if the
58   * threads do run before we intend, they will get an error.
59   */
60  status = sem_init( &sem1, 0, 1 );
61  rtems_test_assert( status == 0 );
62
63  /*
64   * Ensure the semaphore is unavailable so the other threads block.
65   * Lock semaphore resource to ensure thread blocks.
66   */
67  status = sem_wait(&sem1);
68  rtems_test_assert( status == 0 );
69
70  /*
71   * Let the other thread start so the thread startup overhead,
72   * is accounted for.  When we return, we can start the benchmark.
73   */
74  sched_yield();
75    /* let other thread run */
76
77  benchmark_timer_initialize();
78    status = sem_post( &sem1 ); /* semaphore unblocking operation */
79  end_time = benchmark_timer_read();
80  rtems_test_assert( status == 0 );
81
82  put_time(
83    "sem_post: thread waiting no preempt",
84    end_time,
85    1,
86    0,
87    0
88  );
89
90  TEST_END();
91  rtems_test_exit( 0 );
92
93  return NULL;
94}
95
96/* configuration information */
97
98#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
99#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
100
101#define CONFIGURE_MAXIMUM_POSIX_THREADS     2
102#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES  MAX_SEMS
103#define CONFIGURE_POSIX_INIT_THREAD_TABLE
104
105#define CONFIGURE_INIT
106
107#include <rtems/confdefs.h>
108  /* end of file */
Note: See TracBrowser for help on using the repository browser.