source: rtems/testsuites/tmtests/tm04/task1.c @ 7f6a24ab

4.104.114.84.95
Last change on this file since 7f6a24ab was 7f6a24ab, checked in by Joel Sherrill <joel.sherrill@…>, on 08/28/95 at 15:30:29

Added unused priority ceiling parameter to rtems_semaphore_create.

Rearranged code to created thread handler routines to initialize,
start, restart, and "close/delete" a thread.

Made internal threads their own object class. This now uses the
thread support routines for starting and initializing a thread.

Insured deleted tasks are freed to the Inactive pool associated with the
correct Information block.

Added an RTEMS API specific data area to the thread control block.

Beginnings of removing the word "rtems" from the core.

  • Property mode set to 100644
File size: 8.7 KB
RevLine 
[ac7d5ef0]1/*
2 *
3 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
4 *  On-Line Applications Research Corporation (OAR).
5 *  All rights assigned to U.S. Government, 1994.
6 *
7 *  This material may be reproduced by or for the U.S. Government pursuant
8 *  to the copyright license under the clause at DFARS 252.227-7013.  This
9 *  notice must appear in all copies of this file and its derivatives.
10 *
11 *  $Id$
12 */
13
14#include "system.h"
15#undef EXTERN
16#define EXTERN
17#include "conftbl.h"
18#include "gvar.h"
19
20rtems_id         Semaphore_id;
21rtems_id         Task_id[OPERATION_COUNT+1];
22rtems_unsigned32 task_count;
23rtems_id         Highest_id;
24
25rtems_task Low_tasks(
26  rtems_task_argument argument
27);
28
29rtems_task High_task(
30  rtems_task_argument argument
31);
32
33rtems_task Restart_task(
34  rtems_task_argument argument
35);
36
37void test_init();
38
39rtems_task Init(
40  rtems_task_argument argument
41)
42{
43  rtems_status_code status;
44
45  puts( "\n\n*** TIME TEST 4 ***" );
46
47  test_init();
48
49  status = rtems_task_delete( RTEMS_SELF );
50  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
51}
52
53void test_init()
54{
55  rtems_status_code status;
56  rtems_unsigned32  index;
57
58  task_count = OPERATION_COUNT;
59
60  for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) {
61
62    status = rtems_task_create(
63      rtems_build_name( 'T', 'I', 'M', 'E' ),
64      10,
65      1024,
66      RTEMS_NO_PREEMPT,
67      RTEMS_DEFAULT_ATTRIBUTES,
68      &Task_id[ index ]
69    );
70    directive_failed( status, "rtems_task_create loop" );
71
72    status = rtems_task_start( Task_id[ index ], Low_tasks, 0 );
73    directive_failed( status, "rtems_task_start loop" );
74  }
75
76  status = rtems_semaphore_create(
77    rtems_build_name( 'S', 'M', '1', ' ' ),
78    0,
79    RTEMS_DEFAULT_ATTRIBUTES,
[7f6a24ab]80    RTEMS_NO_PRIORITY,
[ac7d5ef0]81    &Semaphore_id
82  );
83  directive_failed( status, "rtems_semaphore_create of SM1" );
84}
85
86rtems_task Highest_task(
87  rtems_task_argument argument
88)
89{
90  rtems_task_priority old_priority;
91  rtems_status_code   status;
92
93  if ( argument == 1 ) {
94
95    end_time = Read_timer();
96
97    put_time(
98      "rtems_task_restart (blocked, preempt)",
99      end_time,
100      1,
101      0,
102      CALLING_OVERHEAD_TASK_RESTART
103    );
104
105    status = rtems_task_set_priority(
106      RTEMS_CURRENT_PRIORITY,
107      254,
108      &old_priority
109    );
110    directive_failed( status, "rtems_task_set_priority" );
111
112 } else if ( argument == 2 ) {
113
114  end_time = Read_timer();
115
116    put_time(
117      "rtems_task_restart (ready, preempt)",
118      end_time,
119      1,
120      0,
121      CALLING_OVERHEAD_TASK_RESTART
122    );
123
124    status = rtems_task_delete( RTEMS_SELF );
125    directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
126
127  } else
128    (void) rtems_semaphore_obtain(
129      Semaphore_id,
130      RTEMS_DEFAULT_OPTIONS,
131      RTEMS_NO_TIMEOUT
132    );
133
134}
135
136rtems_task High_task(
137  rtems_task_argument argument
138)
139{
140  rtems_status_code   status;
141  rtems_unsigned32    index;
142  rtems_name          name;
143  rtems_task_priority old_priority;
144
145  Timer_initialize();
146    (void) rtems_task_restart( Highest_id, 1 );
147  /* preempted by Higher_task */
148
149  Timer_initialize();
150    (void) rtems_task_restart( Highest_id, 2 );
151  /* preempted by Higher_task */
152
153  Timer_initialize();
154    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
155      (void) Empty_function();
156  overhead = Read_timer();
157
158  Timer_initialize();
159    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
160      rtems_semaphore_release( Semaphore_id );
161  end_time = Read_timer();
162
163  put_time(
164    "rtems_semaphore_release (readying)",
165    end_time,
166    OPERATION_COUNT,
167    0,
168    CALLING_OVERHEAD_SEMAPHORE_RELEASE
169  );
170
171  name = rtems_build_name( 'T', 'I', 'M', 'E' );
172
173  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
174    status = rtems_task_delete( Task_id[index] );
175    directive_failed( status, "rtems_task_delete" );
176  }
177
178  Timer_initialize();
179    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
180     rtems_task_create(
181        name,
182        10,
183        1024,
184        RTEMS_NO_PREEMPT,
185        RTEMS_DEFAULT_ATTRIBUTES,
186        &Task_id[ index ]
187      );
188  end_time = Read_timer();
189
190  put_time(
191    "rtems_task_create",
192    end_time,
193    OPERATION_COUNT,
194    overhead,
195    CALLING_OVERHEAD_TASK_CREATE
196  );
197
198  Timer_initialize();
199    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
200      rtems_task_start( Task_id[ index ], Low_tasks, 0 );
201
202  end_time = Read_timer();
203
204  put_time(
205    "rtems_task_start",
206    end_time,
207    OPERATION_COUNT,
208    overhead,
209    CALLING_OVERHEAD_TASK_START
210  );
211
212  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
213    status = rtems_task_delete( Task_id[ index ] );
214    directive_failed( status, "rtems_task_delete" );
215  }
216
217  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
218    status = rtems_task_create(
219      name,
220      250,
221      1024,
222      RTEMS_NO_PREEMPT,
223      RTEMS_DEFAULT_ATTRIBUTES,
224      &Task_id[ index ]
225    );
226    directive_failed( status, "rtems_task_create LOOP" );
227
228    status = rtems_task_start( Task_id[ index ], Restart_task, 0 );
229    directive_failed( status, "rtems_task_start LOOP" );
230
231    status = rtems_task_suspend( Task_id[ index ] );
232    directive_failed( status, "rtems_task_suspend LOOP" );
233  }
234
235  Timer_initialize();
236    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
237      (void) rtems_task_restart( Task_id[ index ], 0 );
238  end_time = Read_timer();
239
240  put_time(
241    "rtems_task_restart (suspended)",
242    end_time,
243    OPERATION_COUNT,
244    overhead,
245    CALLING_OVERHEAD_TASK_RESTART
246  );
247
248  for ( index=1 ; index <= OPERATION_COUNT ; index++ )
249    (void) rtems_task_suspend( Task_id[ index ] );
250
251  Timer_initialize();
252    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
253      (void) rtems_task_delete( Task_id[ index ] );
254  end_time = Read_timer();
255
256  put_time(
257    "rtems_task_delete (suspended)",
258    end_time,
259    OPERATION_COUNT,
260    overhead,
261    CALLING_OVERHEAD_TASK_DELETE
262  );
263
264  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
265    status = rtems_task_create(
266      name,
267      250,
268      1024,
269      RTEMS_DEFAULT_MODES,
270      RTEMS_DEFAULT_ATTRIBUTES,
271      &Task_id[ index ]
272    );
273    directive_failed( status, "rtems_task_create LOOP" );
274
275    status = rtems_task_start( Task_id[ index ], Restart_task, 0 );
276    directive_failed( status, "rtems_task_start LOOP" );
277  }
278
279  Timer_initialize();
280    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
281      (void) rtems_task_restart( Task_id[ index ], 1 );
282  end_time = Read_timer();
283
284  put_time(
285    "rtems_task_restart (ready)",
286    end_time,
287    OPERATION_COUNT,
288    overhead,
289    CALLING_OVERHEAD_TASK_RESTART
290  );
291
292  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
293    status = rtems_task_set_priority( Task_id[ index ], 5, &old_priority );
294    directive_failed( status, "rtems_task_set_priority loop" );
295  }
296
297  /* yield processor -- tasks block */
298  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
299  directive_failed( status, "rtems_task_wake_after" );
300
301  Timer_initialize();
302    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
303      (void) rtems_task_restart( Task_id[ index ], 1 );
304  end_time = Read_timer();
305
306  put_time(
307    "rtems_task_restart (blocked, no preempt)",
308    end_time,
309    OPERATION_COUNT,
310    overhead,
311    CALLING_OVERHEAD_TASK_RESTART
312  );
313
314  /* yield processor -- tasks block */
315  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
316  directive_failed( status, "rtems_task_wake_after" );
317
318  Timer_initialize();
319    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
320      (void) rtems_task_delete( Task_id[ index ] );
321  end_time = Read_timer();
322
323  put_time(
324    "rtems_task_delete (blocked)",
325    end_time,
326    OPERATION_COUNT,
327    overhead,
328    CALLING_OVERHEAD_TASK_DELETE
329  );
330
331  exit( 0 );
332}
333
334rtems_task Low_tasks(
335  rtems_task_argument argument
336)
337{
338  rtems_id          id;
339  rtems_status_code status;
340
341  task_count--;
342
343  if ( task_count == 0 ) {
344    status = rtems_task_create(
345      rtems_build_name( 'H', 'I', ' ', ' ' ),
346      5,
347      2048,
348      RTEMS_DEFAULT_MODES,
349      RTEMS_DEFAULT_ATTRIBUTES,
350      &id
351    );
352    directive_failed( status, "rtems_task_create HI" );
353
354    status = rtems_task_start( id, High_task, 0 );
355    directive_failed( status, "rtems_task_start HI" );
356
357    status = rtems_task_create(
358      rtems_build_name( 'H', 'I', 'G', 'H' ),
359      3,
360      2048,
361      RTEMS_DEFAULT_MODES,
362      RTEMS_DEFAULT_ATTRIBUTES,
363      &Highest_id
364    );
365    directive_failed( status, "rtems_task_create HIGH" );
366
367    status = rtems_task_start( Highest_id, Highest_task, 0 );
368    directive_failed( status, "rtems_task_start HIGH" );
369
370  }
371  (void) rtems_semaphore_obtain(
372    Semaphore_id,
373    RTEMS_DEFAULT_OPTIONS,
374    RTEMS_NO_TIMEOUT
375  );
376}
377
378rtems_task Restart_task(
379  rtems_task_argument argument
380)
381{
382  if ( argument == 1 )
383    (void) rtems_semaphore_obtain(
384      Semaphore_id,
385      RTEMS_DEFAULT_OPTIONS,
386      RTEMS_NO_TIMEOUT
387    );
388}
Note: See TracBrowser for help on using the repository browser.