source: rtems/testsuites/sptests/spintrcritical16/init.c @ cc366ec

4.115
Last change on this file since cc366ec was cc366ec, checked in by Sebastian Huber <sebastian.huber@…>, on 04/24/15 at 10:02:20

score: New thread queue implementation

Use thread wait flags for synchronization. The enqueue operation is now
part of the initial critical section. This is the key change and
enables fine grained locking on SMP for objects using a thread queue
like semaphores and message queues.

Update #2273.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
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 <tmacros.h>
15#include <intrcritical.h>
16
17#include <rtems/score/threadimpl.h>
18
19const char rtems_test_name[] = "SPINTRCRITICAL 16";
20
21static Thread_Control *Main_TCB;
22
23static rtems_id Semaphore;
24
25static bool case_hit;
26
27static bool interrupts_blocking_op(void)
28{
29  Thread_Wait_flags flags = _Thread_Wait_flags_get( Main_TCB );
30
31  return
32    flags == ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK );
33}
34
35static rtems_timer_service_routine test_release_from_isr(
36  rtems_id  timer,
37  void     *arg
38)
39{
40  if ( interrupts_blocking_op() ) {
41    case_hit = true;
42    (void) rtems_semaphore_release( Semaphore );
43  }
44
45  if ( Main_TCB->Wait.queue != NULL ) {
46    _Thread_Timeout( 0, Main_TCB );
47  }
48}
49
50static bool test_body( void *arg )
51{
52  rtems_status_code sc;
53
54  (void) arg;
55
56  sc = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 2 );
57  rtems_test_assert( sc == RTEMS_SUCCESSFUL || sc == RTEMS_TIMEOUT );
58
59  return case_hit;
60}
61
62static rtems_task Init(
63  rtems_task_argument ignored
64)
65{
66  rtems_status_code     sc;
67
68  TEST_BEGIN();
69  puts(
70    "Init - Trying to generate timeout of a thread that had its blocking\n"
71    "Init -   request satisfied while blocking but before time timeout"
72  );
73
74  puts( "Init - rtems_semaphore_create - OK" );
75  sc = rtems_semaphore_create(
76    rtems_build_name( 'S', 'M', '1', ' ' ),
77    0,
78    RTEMS_DEFAULT_ATTRIBUTES,
79    RTEMS_NO_PRIORITY,
80    &Semaphore
81  );
82  directive_failed( sc, "rtems_semaphore_create of SM1" );
83
84  Main_TCB  = _Thread_Get_executing();
85
86  interrupt_critical_section_test( test_body, NULL, test_release_from_isr );
87
88  if ( case_hit ) {
89    puts( "Init - Case hit" );
90    TEST_END();
91  } else
92    puts( "Init - Case not hit - ran too long" );
93
94
95  rtems_test_exit(0);
96}
97
98/* configuration information */
99
100#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
101#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
102
103#define CONFIGURE_MAXIMUM_TASKS          1
104#define CONFIGURE_MAXIMUM_TIMERS         1
105#define CONFIGURE_MAXIMUM_SEMAPHORES     1
106#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
107#define CONFIGURE_MICROSECONDS_PER_TICK  1000
108#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
109
110#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
111
112#define CONFIGURE_INIT
113#include <rtems/confdefs.h>
114
115/* global variables */
Note: See TracBrowser for help on using the repository browser.