source: rtems/testsuites/psxtmtests/psxtmcond03/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) 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/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  int status;
34
35  status = pthread_mutex_lock(&MutexID);
36  rtems_test_assert( status == 0 );
37 
38  /* Unlock mutex, block, wait for CondID to be signaled */
39  pthread_cond_wait(&CondID,&MutexID);
40 
41 /* should never return */
42  rtems_test_assert( FALSE );
43
44  return NULL;
45}
46
47void *POSIX_Init(
48  void *argument
49)
50{
51  int        status;
52  pthread_t  threadId;
53  long       end_time;
54  struct sched_param param;
55  int policy;
56
57  puts( "\n\n*** POSIX TIME TEST PSXTMCOND03 ***" );
58
59  status = pthread_create( &threadId, NULL, Blocker, NULL );
60  rtems_test_assert( status == 0 );
61 
62  status = pthread_mutex_init(&MutexID, NULL);
63  rtems_test_assert( status == 0 );
64
65  status = pthread_cond_init(&CondID, NULL); /* Create condition variable */
66  rtems_test_assert( status == 0 );
67
68  /*
69   * Let the other thread start so the thread startup overhead,
70   * is accounted for.  When we return, we can start the benchmark.
71   */
72  sched_yield();
73    /* let other thread run */
74
75  /* To be extra sure we don't get preempted on the signal */
76  status = pthread_getschedparam(pthread_self(), &policy, &param);
77  rtems_test_assert( status == 0);
78  param.sched_priority = sched_get_priority_max(policy) - 1;
79  status = pthread_setschedparam(pthread_self(), policy, &param);
80  rtems_test_assert( status == 0);
81
82  benchmark_timer_initialize();
83  status = pthread_cond_signal(&CondID);
84  end_time = benchmark_timer_read();
85  rtems_test_assert( status == 0 );
86
87  put_time(
88    "pthread_cond_signal: thread waiting no preempt",
89    end_time,
90    1,
91    0,
92    0
93  );
94
95  puts( "*** END OF POSIX TIME TEST PSXTMCOND03 ***" );
96  rtems_test_exit( 0 );
97
98  return NULL;
99}
100
101/* configuration information */
102
103#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
104#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
105
106#define CONFIGURE_MAXIMUM_POSIX_THREADS     2
107#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 2
108#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 2
109#define CONFIGURE_POSIX_INIT_THREAD_TABLE
110
111#define CONFIGURE_INIT
112
113#include <rtems/confdefs.h>
114  /* end of file */
Note: See TracBrowser for help on using the repository browser.