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

5
Last change on this file since 5222488 was 5222488, checked in by Sebastian Huber <sebastian.huber@…>, on 09/26/17 at 05:49:17

posix: Implement self-contained POSIX condvar

POSIX condition variables are now available in all configurations and no
longer depend on --enable-posix.

Update #2514.
Update #3113.

  • Property mode set to 100644
File size: 2.5 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/btimer.h>
21
22const char rtems_test_name[] = "PSXTMCOND 04";
23
24/* forward declarations to avoid warnings */
25void *POSIX_Init(void *argument);
26void *Blocker(void *argument);
27
28pthread_mutex_t MutexID;
29pthread_cond_t CondID;
30
31void *Blocker(
32  void *argument
33)
34{
35
36  uint32_t end_time;
37  struct   sched_param param;
38  int      policy;
39  int      status;
40
41  status = pthread_mutex_lock(&MutexID);
42  rtems_test_assert( status == 0 );
43  status = pthread_getschedparam(pthread_self(), &policy, &param);
44  rtems_test_assert( status == 0 );
45  param.sched_priority = sched_get_priority_max(policy) - 1;
46  status = pthread_setschedparam(pthread_self(), policy, &param);
47  /* Thread blocks, unlocks mutex, waits for CondID to be signaled */
48  pthread_cond_wait(&CondID,&MutexID);
49
50  /* Once signaled, this thread preempts POSIX_Init thread */
51  end_time = benchmark_timer_read();
52  put_time(
53    "pthread_cond_signal: thread waiting preempt",
54    end_time,
55    1,
56    0,
57    0
58  );
59  TEST_END();
60  rtems_test_exit( 0 );
61  return NULL;
62}
63
64void *POSIX_Init(
65  void *argument
66)
67{
68  int        status;
69  pthread_t  threadId;
70
71  TEST_BEGIN();
72
73  status = pthread_create( &threadId, NULL, Blocker, NULL );
74  rtems_test_assert( status == 0 );
75 
76  status = pthread_mutex_init(&MutexID, NULL);
77  rtems_test_assert( status == 0 );
78
79  status = pthread_cond_init(&CondID, NULL); /* Create condition variable */
80  rtems_test_assert( status == 0 );
81
82  /*
83   * Let the other thread start so the thread startup overhead,
84   * is accounted for.  When we return, we can start the benchmark.
85   */
86  sched_yield();
87  /* let other thread run */
88
89  /* Other thread is blocked and waiting on condition to be signaled */
90  benchmark_timer_initialize();
91  status = pthread_cond_signal(&CondID);
92  rtems_test_assert ( status == 0 );
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_MUTEXES 2
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.