source: rtems/testsuites/sptests/sp36/strict_order_mut.c @ d5ae827

4.104.115
Last change on this file since d5ae827 was 86ad26ac, checked in by Ralf Corsepius <ralf.corsepius@…>, on 06/30/08 at 15:08:08

2008-06-30 Ralf Corsépius <ralf.corsepius@…>

  • sp36/strict_order_mut.c: Reflect STRICT_ORDER_MUTEX having been renamed into RTEMS_STRICT_ORDER_MUTEX.
  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 *  Simple test program to demonstrate strict order mutex
3 *
4 */
5
6#define CONFIGURE_INIT
7
8#include <bsp.h>
9#include <stdio.h>
10#include "tmacros.h"
11#include <rtems/score/coremutex.h>
12
13#define BACK_TYPE(_type_in_ptr,_type_out,_type_in_name)         \
14  ((_type_out *)((unsigned int)_type_in_ptr - (unsigned int)(&((_type_out *)0)->_type_in_name)))
15
16
17/* configuration information */
18
19#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
20#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
21
22#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
23
24#define CONFIGURE_EXTRA_TASK_STACKS (RTEMS_MINIMUM_STACK_SIZE * 3)
25
26#define CONFIGURE_MAXIMUM_TASKS 10
27#define CONFIGURE_MAXIMUM_SEMAPHORES 10
28
29
30void p_mutex_chain(Thread_Control *the_thread);
31rtems_task Task0(rtems_task_argument ignored);
32rtems_task Task1(rtems_task_argument ignored);
33rtems_task Init(rtems_task_argument ignored);
34rtems_task_priority Get_current_pri(void);
35
36
37#include <rtems/confdefs.h>
38
39
40
41rtems_id Task_id[4];
42rtems_name Task_name[4];
43
44rtems_id Mutex_id[4];
45rtems_name Mutex_name[4];
46
47rtems_task Init(rtems_task_argument ignored)
48{
49  rtems_status_code status;
50  printf("\n----------------TEST 36 ------------\n");
51
52  Mutex_name[0] = rtems_build_name( 'S','0',' ',' ');
53  status = rtems_semaphore_create(
54                                  Mutex_name[0],
55                                  1,
56                                  RTEMS_LOCAL|
57                                  RTEMS_SIMPLE_BINARY_SEMAPHORE|
58                                  RTEMS_INHERIT_PRIORITY|
59                                  RTEMS_PRIORITY,
60                                  0,
61                                  &Mutex_id[0]);
62  directive_failed( status, "rtems_semaphore_create of S0");
63  printf("Create S0, Inherit_priority\n");
64
65  Mutex_name[1] = rtems_build_name( 'S','1',' ',' ');
66  status = rtems_semaphore_create(
67                                  Mutex_name[1],
68                                  1,
69                                  RTEMS_LOCAL|
70                                  RTEMS_SIMPLE_BINARY_SEMAPHORE|
71                                  RTEMS_PRIORITY_CEILING|
72                                  RTEMS_PRIORITY,
73                                  1,
74                                  &Mutex_id[1]);
75  directive_failed( status, "rtems_semaphore_create of S1");
76  printf("Create S1, Priority_celling  is 1\n");
77
78  Mutex_name[2] = rtems_build_name( 'S','Y','N','C');
79
80                                 
81  Task_name[0] = rtems_build_name( 'T','0',' ',' ');
82  status = rtems_task_create(
83                             Task_name[0],
84                             4,
85                             RTEMS_MINIMUM_STACK_SIZE *2,
86                             RTEMS_DEFAULT_MODES,
87                             RTEMS_DEFAULT_ATTRIBUTES,
88                             &Task_id[0]
89                             );
90  directive_failed( status,"rtems_task_create of T0");
91  printf("Create T0,priority is 4\n");
92
93 
94
95  status = rtems_task_start( Task_id[0],Task0, 0);
96  directive_failed( status,"rtems_task_start of T0");
97
98  status = rtems_task_delete( RTEMS_SELF);
99  directive_failed( status,"rtems_task_delete of INIT");
100}
101
102
103rtems_task Task0(rtems_task_argument ignored)
104{
105  rtems_status_code status;
106 
107 
108  status = rtems_semaphore_obtain(
109                                  Mutex_id[0],
110                                  RTEMS_WAIT,
111                                  0);
112  printf("T0 rtems_semaphore_obtain - S0\n");
113  directive_failed( status,"rtems_semaphore_obtain of S0\n");
114  printf("The current priority of T0 is %d\n",Get_current_pri());
115 
116  status = rtems_semaphore_obtain(
117                                  Mutex_id[1],
118                                  RTEMS_WAIT,
119                                  0);
120  printf("T0 rtems_semaphore_obtain - S1\n");
121  directive_failed( status,"rtems_semaphore_obtain of S1");
122  printf("The current priority of T0 is %d\n",Get_current_pri());
123
124#ifdef __RTEMS_STRICT_ORDER_MUTEX__
125  status = rtems_semaphore_release( Mutex_id[0] );
126  printf("T0 - rtems_semaphore_release - S0\n");
127  if(status == CORE_MUTEX_RELEASE_NOT_ORDER)
128    printf("T0 releasing S0 not in order\n");
129#endif
130
131  status = rtems_semaphore_release(Mutex_id[1]);
132  printf("T0 - rtems_semaphore_release - S1\n");
133  directive_failed( status,"rtems_semaphore_release of S1\n");
134  printf("The current priority of T0 is %d\n",Get_current_pri());
135 
136
137  Task_name[1] = rtems_build_name( 'T','1',' ',' ');
138  status = rtems_task_create(
139                             Task_name[1],
140                             1,
141                             RTEMS_MINIMUM_STACK_SIZE *2,
142                             RTEMS_DEFAULT_MODES,
143                             RTEMS_DEFAULT_ATTRIBUTES,
144                             &Task_id[1]
145                             );
146  directive_failed( status , "rtems_task_create of T1\n");
147  printf("Create S1,priority is 1\n");
148 
149
150  status = rtems_task_start( Task_id[1],Task1, 0);
151  directive_failed( status, "rtems_task_start of T1\n");
152
153  printf("The current priority of T0 is %d\n",Get_current_pri());
154
155  status = rtems_semaphore_release(Mutex_id[0]);
156  printf("T0 - rtems_semaphore_release - S0\n");
157  directive_failed( status, "rtems_semaphore_release of S0\n");
158 
159}
160 
161
162rtems_task Task1(rtems_task_argument ignored)
163{
164
165  rtems_status_code status;
166  status =  rtems_semaphore_obtain(
167                         Mutex_id[0],
168                         RTEMS_WAIT,
169                         0);
170  printf("T1 - rtems_semaphore_obtain - S0");
171  directive_failed( status," rtems_semaphore_obtain S0");
172}
173
174
175rtems_task_priority Get_current_pri(void)
176{
177  rtems_status_code status;
178  rtems_task_priority pri;
179  status = rtems_task_set_priority(RTEMS_SELF,
180                                   RTEMS_CURRENT_PRIORITY,
181                                   &pri);
182  directive_failed( status, " rtems_task_set_priority ");
183  return pri;
184}
185
186/*void p_mutex_chain(Thread_Control *the_thread)
187{
188  Chain_Control *con = &the_thread->lock_mutex;
189  Chain_Node  * node = con->first;
190  CORE_mutex_Control * p_mutex ;
191
192  if(!_Chain_Is_empty(&the_thread->lock_mutex)){
193    while(node != _Chain_Tail(con)){
194      p_mutex = BACK_TYPE(node,CORE_mutex_Control,queue);
195      printf("node:Id=%p,priority_before=%d,"
196             "holder_id=%d,holder's current priority=%d\n",node,
197             ((CORE_mutex_order_list *)node)->priority_before,p_mutex->holder_id,p_mutex->holder->current_priority);
198      node = node->next;   
199    }
200  }
201  else
202    printf("the Chain is empty\n");
203}
204*/ 
Note: See TracBrowser for help on using the repository browser.