source: rtems/testsuites/psxtmtests/psxtmcond04/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  COPYRIGHT (c) 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/timerdrv.h>
21
22/* forward declarations to avoid warnings */
23void *POSIX_Init(void *argument);
24void *Blocker(void *argument);
25
26pthread_mutex_t MutexID;
27pthread_cond_t CondID;
28
29void *Blocker(
30  void *argument
31)
32{
33
34  long end_time;
35  struct sched_param param;
36  int policy;
37  int status;
38
39  status = pthread_mutex_lock(&MutexID);
40  rtems_test_assert( status == 0 );
41  status = pthread_getschedparam(pthread_self(), &policy, &param);
42  rtems_test_assert( status == 0 );
43  param.sched_priority = sched_get_priority_max(policy) - 1;
44  status = pthread_setschedparam(pthread_self(), policy, &param);
45  /* Thread blocks, unlocks mutex, waits for CondID to be signaled */
46  pthread_cond_wait(&CondID,&MutexID);
47
48  /* Once signaled, this thread preempts POSIX_Init thread */
49  end_time = benchmark_timer_read();
50  put_time(
51    "pthread_cond_signal: thread waiting preempt",
52    end_time,
53    1,
54    0,
55    0
56  );
57  puts( "*** END OF POSIX TIME TEST PSXTMCOND04 ***" );
58  rtems_test_exit( 0 );
59  return NULL;
60}
61
62void *POSIX_Init(
63  void *argument
64)
65{
66  int        status;
67  pthread_t  threadId;
68
69  puts( "\n\n*** POSIX TIME TEST PSXTMCOND04 ***" );
70
71  status = pthread_create( &threadId, NULL, Blocker, NULL );
72  rtems_test_assert( status == 0 );
73 
74  status = pthread_mutex_init(&MutexID, NULL);
75  rtems_test_assert( status == 0 );
76
77  status = pthread_cond_init(&CondID, NULL); /* Create condition variable */
78  rtems_test_assert( status == 0 );
79
80  /*
81   * Let the other thread start so the thread startup overhead,
82   * is accounted for.  When we return, we can start the benchmark.
83   */
84  sched_yield();
85  /* let other thread run */
86
87  /* Other thread is blocked and waiting on condition to be signaled */
88  benchmark_timer_initialize();
89  status = pthread_cond_signal(&CondID);
90  rtems_test_assert ( status == 0 );
91  return NULL;
92}
93
94/* configuration information */
95
96#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
97#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
98
99#define CONFIGURE_MAXIMUM_POSIX_THREADS     2
100#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 2
101#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 2
102#define CONFIGURE_POSIX_INIT_THREAD_TABLE
103
104#define CONFIGURE_INIT
105
106#include <rtems/confdefs.h>
107  /* end of file */
Note: See TracBrowser for help on using the repository browser.