1 /* This test is designed to test multi-level preemption threshold. The protection placed
2    by a thread must be preserved after higher-priority thread preemption that is above the threshold.  */
3 
4 #include   <stdio.h>
5 #include   "tx_api.h"
6 #include   "tx_thread.h"
7 
8 #ifndef TX_DISABLE_PREEMPTION_THRESHOLD
9 
10 static unsigned long   thread_0_counter =  0;
11 static TX_THREAD       thread_1;
12 static TX_THREAD       thread_2;
13 static void    thread_1_entry(ULONG thread_input);
14 static void    thread_2_entry(ULONG thread_input);
15 static void    thread_3_entry(ULONG thread_input);
16 static void    thread_2a_entry(ULONG thread_input);
17 static void    thread_4_entry(ULONG thread_input);
18 static unsigned long   thread_1_counter =  0;
19 
20 static unsigned long   thread_2_counter =  0;
21 
22 static unsigned long   thread_2a_counter =  0;
23 static TX_THREAD       thread_2a;
24 
25 static unsigned long   thread_3_counter =  0;
26 static TX_THREAD       thread_3;
27 
28 static unsigned long   thread_4_counter =  0;
29 static TX_THREAD       thread_4;
30 
31 #endif
32 
33 static TX_THREAD       thread_0;
34 
35 
36 #ifndef TX_DISABLE_PREEMPTION_THRESHOLD
37 
38 /* Define new preemption-threshold threads for complete bit map checking.  */
39 
40 static TX_THREAD       thread_1_0;
41 static TX_THREAD       thread_2_1;
42 static TX_THREAD       thread_3_2;
43 static TX_THREAD       thread_4_3;
44 static TX_THREAD       thread_6_5;
45 static TX_THREAD       thread_8_7;
46 static TX_THREAD       thread_10_9;
47 static TX_THREAD       thread_12_11;
48 static TX_THREAD       thread_14_13;
49 static TX_THREAD       thread_16_15;
50 static TX_THREAD       thread_18_17;
51 static TX_THREAD       thread_20_19;
52 static TX_THREAD       thread_22_21;
53 static TX_THREAD       thread_24_23;
54 static TX_THREAD       thread_26_25;
55 static TX_THREAD       thread_28_27;
56 static TX_THREAD       thread_30_29;
57 
58 
59 /* Define timer for preemption of priority 1 test.  */
60 
61 static TX_TIMER         timer_0;
62 
63 
64 /* Define counters.  */
65 
66 static unsigned long   timer_0_counter =     0;
67 static unsigned long   thread_1_0_counter =  0;
68 static unsigned long   thread_2_1_counter =  0;
69 static unsigned long   thread_3_2_counter =  0;
70 static unsigned long   thread_4_3_counter =  0;
71 static unsigned long   thread_6_5_counter =  0;
72 static unsigned long   thread_8_7_counter =  0;
73 static unsigned long   thread_10_9_counter =  0;
74 static unsigned long   thread_12_11_counter =  0;
75 static unsigned long   thread_14_13_counter =  0;
76 static unsigned long   thread_16_15_counter =  0;
77 static unsigned long   thread_18_17_counter =  0;
78 static unsigned long   thread_20_19_counter =  0;
79 static unsigned long   thread_22_21_counter =  0;
80 static unsigned long   thread_24_23_counter =  0;
81 static unsigned long   thread_26_25_counter =  0;
82 static unsigned long   thread_28_27_counter =  0;
83 static unsigned long   thread_30_29_counter =  0;
84 
85 
86 /* Define new preemption-threshold test thread entry points.  */
87 
88 static void    thread_1_0_entry(ULONG thread_input);
89 static void    thread_2_1_entry(ULONG thread_input);
90 static void    thread_3_2_entry(ULONG thread_input);
91 static void    thread_4_3_entry(ULONG thread_input);
92 static void    thread_6_5_entry(ULONG thread_input);
93 static void    thread_8_7_entry(ULONG thread_input);
94 static void    thread_10_9_entry(ULONG thread_input);
95 static void    thread_12_11_entry(ULONG thread_input);
96 static void    thread_14_13_entry(ULONG thread_input);
97 static void    thread_16_15_entry(ULONG thread_input);
98 static void    thread_18_17_entry(ULONG thread_input);
99 static void    thread_20_19_entry(ULONG thread_input);
100 static void    thread_22_21_entry(ULONG thread_input);
101 static void    thread_24_23_entry(ULONG thread_input);
102 static void    thread_26_25_entry(ULONG thread_input);
103 static void    thread_28_27_entry(ULONG thread_input);
104 static void    thread_30_29_entry(ULONG thread_input);
105 
106 /* Define timer 1 entry.  */
107 
108 static void    timer_0_entry(ULONG id);
109 
110 
111 #endif
112 
113 
114 /* Define thread prototypes.  */
115 
116 static void    thread_0_entry(ULONG thread_input);
117 
118 
119 /* Prototype for test control return.  */
120 void  test_control_return(UINT status);
121 
122 
123 /* Define what the initial system looks like.  */
124 
125 #ifdef CTEST
test_application_define(void * first_unused_memory)126 void test_application_define(void *first_unused_memory)
127 #else
128 void    threadx_thread_multi_level_preemption_threshold_application_define(void *first_unused_memory)
129 #endif
130 {
131 
132 UINT    status;
133 CHAR    *pointer;
134 
135 
136     /* Put first available memory address into a character pointer.  */
137     pointer =  (CHAR *) first_unused_memory;
138 
139     /* Put system definition stuff in here, e.g. thread creates and other assorted
140        create information.  */
141 
142     status =  tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
143             pointer, TEST_STACK_SIZE_PRINTF,
144             (TX_MAX_PRIORITIES-1), (TX_MAX_PRIORITIES/2), TX_NO_TIME_SLICE, TX_AUTO_START);
145     pointer = pointer + TEST_STACK_SIZE_PRINTF;
146 
147     /* Check for status.  */
148     if (status != TX_SUCCESS)
149     {
150 
151         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #1\n");
152         test_control_return(1);
153     }
154 
155 #ifndef TX_DISABLE_PREEMPTION_THRESHOLD /* skip this test and pretend it passed */
156 
157     status =  tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
158             pointer, TEST_STACK_SIZE_PRINTF,
159             (TX_MAX_PRIORITIES/2), (TX_MAX_PRIORITIES/2), TX_NO_TIME_SLICE, TX_DONT_START);
160     pointer = pointer + TEST_STACK_SIZE_PRINTF;
161 
162     /* Check for status.  */
163     if (status != TX_SUCCESS)
164     {
165 
166         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #2\n");
167         test_control_return(1);
168     }
169 
170     status =  tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
171             pointer, TEST_STACK_SIZE_PRINTF,
172             15, 10, TX_NO_TIME_SLICE, TX_DONT_START);
173     pointer = pointer + TEST_STACK_SIZE_PRINTF;
174 
175     /* Check for status.  */
176     if (status != TX_SUCCESS)
177     {
178 
179         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #3\n");
180         test_control_return(1);
181     }
182 
183     status =  tx_thread_create(&thread_2a, "thread 2a", thread_2a_entry, 2,
184             pointer, TEST_STACK_SIZE_PRINTF,
185             15, 15, TX_NO_TIME_SLICE, TX_DONT_START);
186     pointer = pointer + TEST_STACK_SIZE_PRINTF;
187 
188     /* Check for status.  */
189     if (status != TX_SUCCESS)
190     {
191 
192         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #4\n");
193         test_control_return(1);
194     }
195 
196     status =  tx_thread_create(&thread_3, "thread 3", thread_3_entry, 3,
197             pointer, TEST_STACK_SIZE_PRINTF,
198             11, 11, TX_NO_TIME_SLICE, TX_DONT_START);
199     pointer = pointer + TEST_STACK_SIZE_PRINTF;
200 
201     /* Check for status.  */
202     if (status != TX_SUCCESS)
203     {
204 
205         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #5\n");
206         test_control_return(1);
207     }
208 
209     status =  tx_thread_create(&thread_4, "thread 4", thread_4_entry, 4,
210             pointer, TEST_STACK_SIZE_PRINTF,
211             9, 9, TX_NO_TIME_SLICE, TX_DONT_START);
212     pointer = pointer + TEST_STACK_SIZE_PRINTF;
213 
214     /* Check for status.  */
215     if (status != TX_SUCCESS)
216     {
217 
218         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #6\n");
219         test_control_return(1);
220     }
221 
222     /* Create new cascading preemption-threshold test threads.  */
223 
224     status =  tx_thread_create(&thread_30_29, "thread 30-29", thread_30_29_entry, 30,
225             pointer, TEST_STACK_SIZE_PRINTF,
226             30, 29, TX_NO_TIME_SLICE, TX_DONT_START);
227     pointer = pointer + TEST_STACK_SIZE_PRINTF;
228 
229     /* Check for status.  */
230     if (status != TX_SUCCESS)
231     {
232 
233         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #7\n");
234         test_control_return(1);
235     }
236 
237     status =  tx_thread_create(&thread_28_27, "thread 28-27", thread_28_27_entry, 28,
238             pointer, TEST_STACK_SIZE_PRINTF,
239             28, 27, TX_NO_TIME_SLICE, TX_DONT_START);
240     pointer = pointer + TEST_STACK_SIZE_PRINTF;
241 
242     /* Check for status.  */
243     if (status != TX_SUCCESS)
244     {
245 
246         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #8\n");
247         test_control_return(1);
248     }
249 
250     status =  tx_thread_create(&thread_26_25, "thread 26-25", thread_26_25_entry, 26,
251             pointer, TEST_STACK_SIZE_PRINTF,
252             26, 25, TX_NO_TIME_SLICE, TX_DONT_START);
253     pointer = pointer + TEST_STACK_SIZE_PRINTF;
254 
255     /* Check for status.  */
256     if (status != TX_SUCCESS)
257     {
258 
259         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #9\n");
260         test_control_return(1);
261     }
262 
263     status =  tx_thread_create(&thread_24_23, "thread 24-23", thread_24_23_entry, 24,
264             pointer, TEST_STACK_SIZE_PRINTF,
265             24, 23, TX_NO_TIME_SLICE, TX_DONT_START);
266     pointer = pointer + TEST_STACK_SIZE_PRINTF;
267 
268     /* Check for status.  */
269     if (status != TX_SUCCESS)
270     {
271 
272         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #10\n");
273         test_control_return(1);
274     }
275 
276     status =  tx_thread_create(&thread_22_21, "thread 22-21", thread_22_21_entry, 22,
277             pointer, TEST_STACK_SIZE_PRINTF,
278             22, 21, TX_NO_TIME_SLICE, TX_DONT_START);
279     pointer = pointer + TEST_STACK_SIZE_PRINTF;
280 
281     /* Check for status.  */
282     if (status != TX_SUCCESS)
283     {
284 
285         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #11\n");
286         test_control_return(1);
287     }
288 
289     status =  tx_thread_create(&thread_20_19, "thread 20-19", thread_20_19_entry, 20,
290             pointer, TEST_STACK_SIZE_PRINTF,
291             20,19, TX_NO_TIME_SLICE, TX_DONT_START);
292     pointer = pointer + TEST_STACK_SIZE_PRINTF;
293 
294     /* Check for status.  */
295     if (status != TX_SUCCESS)
296     {
297 
298         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #12\n");
299         test_control_return(1);
300     }
301 
302     status =  tx_thread_create(&thread_18_17, "thread 18-17", thread_18_17_entry, 18,
303             pointer, TEST_STACK_SIZE_PRINTF,
304             18, 17, TX_NO_TIME_SLICE, TX_DONT_START);
305     pointer = pointer + TEST_STACK_SIZE_PRINTF;
306 
307     /* Check for status.  */
308     if (status != TX_SUCCESS)
309     {
310 
311         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #13\n");
312         test_control_return(1);
313     }
314 
315     status =  tx_thread_create(&thread_16_15, "thread 16-15", thread_16_15_entry, 16,
316             pointer, TEST_STACK_SIZE_PRINTF,
317             16, 15, TX_NO_TIME_SLICE, TX_DONT_START);
318     pointer = pointer + TEST_STACK_SIZE_PRINTF;
319 
320     /* Check for status.  */
321     if (status != TX_SUCCESS)
322     {
323 
324         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #14\n");
325         test_control_return(1);
326     }
327 
328     status =  tx_thread_create(&thread_14_13, "thread 14-13", thread_14_13_entry, 14,
329             pointer, TEST_STACK_SIZE_PRINTF,
330             14, 13, TX_NO_TIME_SLICE, TX_DONT_START);
331     pointer = pointer + TEST_STACK_SIZE_PRINTF;
332 
333     /* Check for status.  */
334     if (status != TX_SUCCESS)
335     {
336 
337         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #15\n");
338         test_control_return(1);
339     }
340 
341     status =  tx_thread_create(&thread_12_11, "thread 12-11", thread_12_11_entry, 12,
342             pointer, TEST_STACK_SIZE_PRINTF,
343             12, 11, TX_NO_TIME_SLICE, TX_DONT_START);
344     pointer = pointer + TEST_STACK_SIZE_PRINTF;
345 
346     /* Check for status.  */
347     if (status != TX_SUCCESS)
348     {
349 
350         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #16\n");
351         test_control_return(1);
352     }
353 
354     status =  tx_thread_create(&thread_10_9, "thread 10-9", thread_10_9_entry, 10,
355             pointer, TEST_STACK_SIZE_PRINTF,
356             10, 9, TX_NO_TIME_SLICE, TX_DONT_START);
357     pointer = pointer + TEST_STACK_SIZE_PRINTF;
358 
359     /* Check for status.  */
360     if (status != TX_SUCCESS)
361     {
362 
363         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #17\n");
364         test_control_return(1);
365     }
366 
367     status =  tx_thread_create(&thread_8_7, "thread 8-7", thread_8_7_entry, 8,
368             pointer, TEST_STACK_SIZE_PRINTF,
369             8, 7, TX_NO_TIME_SLICE, TX_DONT_START);
370     pointer = pointer + TEST_STACK_SIZE_PRINTF;
371 
372     /* Check for status.  */
373     if (status != TX_SUCCESS)
374     {
375 
376         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #18\n");
377         test_control_return(1);
378     }
379 
380     status =  tx_thread_create(&thread_6_5, "thread 6-5", thread_6_5_entry, 6,
381             pointer, TEST_STACK_SIZE_PRINTF,
382             6, 5, TX_NO_TIME_SLICE, TX_DONT_START);
383     pointer = pointer + TEST_STACK_SIZE_PRINTF;
384 
385     /* Check for status.  */
386     if (status != TX_SUCCESS)
387     {
388 
389         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #19\n");
390         test_control_return(1);
391     }
392 
393     status =  tx_thread_create(&thread_4_3, "thread 4-3", thread_4_3_entry, 4,
394             pointer, TEST_STACK_SIZE_PRINTF,
395             4, 3, TX_NO_TIME_SLICE, TX_DONT_START);
396     pointer = pointer + TEST_STACK_SIZE_PRINTF;
397 
398     /* Check for status.  */
399     if (status != TX_SUCCESS)
400     {
401 
402         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #20\n");
403         test_control_return(1);
404     }
405 
406     status =  tx_thread_create(&thread_3_2, "thread 3-2", thread_3_2_entry, 3,
407             pointer, TEST_STACK_SIZE_PRINTF,
408             3, 2, TX_NO_TIME_SLICE, TX_DONT_START);
409     pointer = pointer + TEST_STACK_SIZE_PRINTF;
410 
411     /* Check for status.  */
412     if (status != TX_SUCCESS)
413     {
414 
415         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #21\n");
416         test_control_return(1);
417     }
418 
419     status =  tx_thread_create(&thread_2_1, "thread 2-1", thread_2_1_entry, 2,
420             pointer, TEST_STACK_SIZE_PRINTF,
421             2, 1, TX_NO_TIME_SLICE, TX_DONT_START);
422     pointer = pointer + TEST_STACK_SIZE_PRINTF;
423 
424     /* Check for status.  */
425     if (status != TX_SUCCESS)
426     {
427 
428         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #22\n");
429         test_control_return(1);
430     }
431 
432     status =  tx_thread_create(&thread_1_0, "thread 1-0", thread_1_0_entry, 1,
433             pointer, TEST_STACK_SIZE_PRINTF,
434             1, 1, TX_NO_TIME_SLICE, TX_DONT_START);
435     pointer = pointer + TEST_STACK_SIZE_PRINTF;
436 
437     /* Check for status.  */
438     if (status != TX_SUCCESS)
439     {
440 
441         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #23\n");
442         test_control_return(1);
443     }
444 
445     status =  tx_timer_create(&timer_0, "timer 0", timer_0_entry, 0, 1, 0, TX_NO_ACTIVATE);
446 
447     /* Check for status.  */
448     if (status != TX_SUCCESS)
449     {
450 
451         printf("Running Thread Multi-Level Preemption Threshold Test................ ERROR #24\n");
452         test_control_return(1);
453     }
454 
455 #endif
456 
457 }
458 
459 
460 
461 /* Define the test threads.  */
462 
thread_0_entry(ULONG thread_input)463 static void    thread_0_entry(ULONG thread_input)
464 {
465 
466 #ifndef TX_DISABLE_PREEMPTION_THRESHOLD
467 UINT status;
468 UINT old_preempt;
469 #endif
470 
471 
472     /* Inform user.  */
473     printf("Running Thread Multi-Level Preemption Threshold Test................ ");
474 
475 #ifndef TX_DISABLE_PREEMPTION_THRESHOLD /* skip this test and pretend it passed */
476 
477     /* Wakeup Thread 1.  It has a higher-priority but should be blocked by
478        preemption threshold.  */
479     status =  tx_thread_resume(&thread_1);
480 
481     /* Check status and make sure the other run counters are proper.  */
482     if ((status != TX_SUCCESS) || (thread_1_counter) || (thread_2_counter) ||
483         (thread_3_counter) || (thread_4_counter))
484     {
485 
486         /* Thread Preempt Threshold error.  */
487         printf("ERROR #25\n");
488         test_control_return(1);
489     }
490 
491     /* Resume thread 2 which will preempt this thread.  */
492     status = tx_thread_resume(&thread_2);
493 
494     /* Check for good status and proper run counters.  All other threads except for
495        thread 1 should have executed.  */
496     if ((status != TX_SUCCESS) || (thread_1_counter) || (thread_2_counter != 1) ||
497         (thread_3_counter != 1) || (thread_4_counter != 1))
498     {
499 
500         /* Thread Preempt Threshold error.  */
501         printf("ERROR #26\n");
502         test_control_return(1);
503     }
504 
505     /* Set preemption threshold low enough to allow thread 1 to execute.  */
506     status =  tx_thread_preemption_change(&thread_0, ((TX_MAX_PRIORITIES/2)+1), &old_preempt);
507 
508     /* Check for good status and proper run counters.  All other threads except for
509        thread 1 should have executed.  */
510     if ((status != TX_SUCCESS) || (thread_1_counter != 1) || (thread_2_counter != 1) ||
511         (thread_3_counter != 1) || (thread_4_counter != 1) ||
512         (_tx_thread_preempt_disable))
513     {
514 
515         /* Thread Preempt Threshold error.  */
516         printf("ERROR #27\n");
517         test_control_return(1);
518     }
519 
520     /* Increment thread 0 counter.  */
521     thread_0_counter++;
522 
523     /* Set preemption threshold to keep new test threads from running.  */
524     status =  tx_thread_preemption_change(&thread_0, 17, &old_preempt);
525 
526     /* Now wakup the lowest priority preemption-threshold thread.  */
527     status += tx_thread_resume(&thread_30_29);
528 
529     /* Check status.  */
530     if (status != TX_SUCCESS)
531     {
532 
533         /* Thread Preempt Threshold error.  */
534         printf("ERROR #28\n");
535         test_control_return(1);
536     }
537 
538     /* Now, self suspend.  */
539     status =  tx_thread_suspend(&thread_0);
540 
541     /* Check to make sure all the preemption-threshold threads ran.  */
542     if ((thread_1_0_counter !=  1) ||
543         (thread_2_1_counter !=  1) ||
544         (thread_3_2_counter !=  1) ||
545         (thread_4_3_counter !=  1) ||
546         (thread_6_5_counter !=  1) ||
547         (thread_8_7_counter !=  1) ||
548         (thread_10_9_counter !=  1) ||
549         (thread_12_11_counter !=  1) ||
550         (thread_14_13_counter !=  1) ||
551         (thread_16_15_counter !=  1) ||
552         (thread_18_17_counter !=  1) ||
553         (thread_20_19_counter !=  1) ||
554         (thread_22_21_counter !=  1) ||
555         (thread_24_23_counter !=  1) ||
556         (thread_26_25_counter !=  1) ||
557         (thread_28_27_counter !=  1) ||
558         (thread_30_29_counter !=  1))
559     {
560 
561         /* Thread Preempt Threshold error.  */
562         printf("ERROR #29\n");
563         test_control_return(1);
564     }
565 
566 #endif
567 
568     /* Successful Thread Suspend non-current thread test.  */
569     printf("SUCCESS!\n");
570     test_control_return(0);
571 }
572 
573 #ifndef TX_DISABLE_PREEMPTION_THRESHOLD
574 
thread_1_entry(ULONG thread_input)575 static void    thread_1_entry(ULONG thread_input)
576 {
577 
578     thread_1_counter++;
579 }
580 
581 
thread_2_entry(ULONG thread_input)582 static void    thread_2_entry(ULONG thread_input)
583 {
584 
585 UINT    status;
586 
587     /* Resume thread 3 which will not preempt because of thread 2's preemption
588        threshold.  */
589     status =  tx_thread_resume(&thread_3);
590 
591     /* Resume thread 2a which will not preempt this thread because it is at
592        the same priority.  */
593     status += tx_thread_resume(&thread_2a);
594 
595     /* Check status and run counters.  */
596     if ((status != TX_SUCCESS) || (thread_1_counter != 0) || (thread_3_counter) ||
597         (thread_4_counter))
598         return;
599 
600     /* Resume thread 4 which will preempt.  We should get back here before thread
601        three runs because of preemption threshold.  */
602     status =  tx_thread_resume(&thread_4);
603 
604     /* Check status and run counters.  */
605     if ((status != TX_SUCCESS) || (thread_1_counter != 0) || (thread_3_counter) ||
606         (thread_4_counter != 1))
607         return;
608 
609     /* Relinquish to the other thread at this priority level.  This should
610        clear the preemption threshold condition and allow thread 3 to run. */
611     tx_thread_relinquish();
612 
613     /* Check status and run counters.  */
614     if ((status != TX_SUCCESS) || (thread_1_counter != 0) || (thread_2a_counter != 1) ||
615         (thread_3_counter != 1) || (thread_4_counter != 1))
616         return;
617 
618     /* If all is okay, increment thread 2's counter.  */
619     thread_2_counter++;
620 }
621 
622 
thread_2a_entry(ULONG thread_input)623 static void    thread_2a_entry(ULONG thread_input)
624 {
625 
626     if (thread_3_counter == 1)
627         thread_2a_counter++;
628 }
629 
630 
thread_3_entry(ULONG thread_input)631 static void    thread_3_entry(ULONG thread_input)
632 {
633 
634     thread_3_counter++;
635 }
636 
637 
thread_4_entry(ULONG thread_input)638 static void    thread_4_entry(ULONG thread_input)
639 {
640 
641     thread_4_counter++;
642 }
643 
644 
645 
timer_0_entry(ULONG id)646 static void    timer_0_entry(ULONG id)
647 {
648 
649     /* Pretend like a preemption occurred on a thread priority of 1 with preemption-threshold set to 0.  */
650     _tx_thread_preempted_maps[0] =  _tx_thread_preempted_maps[0] | 2;
651 
652     /* Set the thread's preemption threshold as well.  */
653     thread_1_0.tx_thread_preempt_threshold =  0;
654 
655     /* Increment timer 0 counter.  */
656     timer_0_counter++;
657 }
658 
659 
thread_1_0_entry(ULONG thread_input)660 static void    thread_1_0_entry(ULONG thread_input)
661 {
662 
663 UINT    status;
664 
665 
666     /* Activate the timer to force a priority 0 thread to interrupt.  */
667     status =  tx_timer_activate(&timer_0);
668 
669     /* Loop to wait until timer 0 runs.  */
670     while (timer_0_counter == 0)
671     {
672     }
673 
674     /* Check for good status.  */
675     if (status == TX_SUCCESS)
676     {
677 
678         /* Increment this thread's counter.  */
679         thread_1_0_counter++;
680     }
681 }
682 
683 
thread_2_1_entry(ULONG thread_input)684 static void    thread_2_1_entry(ULONG thread_input)
685 {
686 
687     /* Increment this thread's counter.  */
688     thread_2_1_counter++;
689 }
690 
691 
thread_3_2_entry(ULONG thread_input)692 static void    thread_3_2_entry(ULONG thread_input)
693 {
694 
695 UINT    status;
696 
697 
698     /* Resume next highest priority thread.  */
699     status =  tx_thread_resume(&thread_1_0);
700 
701     /* Check for good status.  */
702     if (status == TX_SUCCESS)
703     {
704 
705         /* Increment this thread's counter.  */
706         thread_3_2_counter++;
707     }
708 }
709 
710 
thread_4_3_entry(ULONG thread_input)711 static void    thread_4_3_entry(ULONG thread_input)
712 {
713 
714 UINT    status;
715 
716 
717     /* Resume next highest priority thread.  */
718     status =  tx_thread_resume(&thread_2_1);
719 
720     /* Check for good status.  */
721     if (status == TX_SUCCESS)
722     {
723 
724         /* Increment this thread's counter.  */
725         thread_4_3_counter++;
726     }
727 }
728 
729 
thread_6_5_entry(ULONG thread_input)730 static void    thread_6_5_entry(ULONG thread_input)
731 {
732 
733 UINT    status;
734 
735 
736     /* Resume next highest priority thread.  */
737     status =  tx_thread_resume(&thread_4_3);
738 
739     /* In this particular case, we have two different preemptions to make
740        sure we exercise all the code.  */
741 
742     /* Now resume next highest priority thread.  */
743     status =  tx_thread_resume(&thread_3_2);
744 
745     /* Check for good status.  */
746     if (status == TX_SUCCESS)
747     {
748 
749         /* Increment this thread's counter.  */
750         thread_6_5_counter++;
751     }
752 }
753 
754 
thread_8_7_entry(ULONG thread_input)755 static void    thread_8_7_entry(ULONG thread_input)
756 {
757 
758 UINT    status;
759 
760 
761     /* Resume next highest priority thread.  */
762     status =  tx_thread_resume(&thread_6_5);
763 
764     /* Check for good status.  */
765     if (status == TX_SUCCESS)
766     {
767 
768         /* Increment this thread's counter.  */
769         thread_8_7_counter++;
770     }
771 }
772 
773 
thread_10_9_entry(ULONG thread_input)774 static void    thread_10_9_entry(ULONG thread_input)
775 {
776 
777 UINT    status;
778 
779 
780     /* Resume next highest priority thread.  */
781     status =  tx_thread_resume(&thread_8_7);
782 
783     /* Check for good status.  */
784     if (status == TX_SUCCESS)
785     {
786 
787         /* Increment this thread's counter.  */
788         thread_10_9_counter++;
789     }
790 }
791 
thread_12_11_entry(ULONG thread_input)792 static void    thread_12_11_entry(ULONG thread_input)
793 {
794 
795 UINT    status;
796 
797 
798     /* Resume next highest priority thread.  */
799     status =  tx_thread_resume(&thread_10_9);
800 
801     /* Check for good status.  */
802     if (status == TX_SUCCESS)
803     {
804 
805         /* Increment this thread's counter.  */
806         thread_12_11_counter++;
807     }
808 }
809 
810 
thread_14_13_entry(ULONG thread_input)811 static void    thread_14_13_entry(ULONG thread_input)
812 {
813 
814 UINT    status;
815 
816 
817     /* Resume next highest priority thread.  */
818     status =  tx_thread_resume(&thread_12_11);
819 
820     /* Check for good status.  */
821     if (status == TX_SUCCESS)
822     {
823 
824         /* Increment this thread's counter.  */
825         thread_14_13_counter++;
826     }
827 }
828 
829 
thread_16_15_entry(ULONG thread_input)830 static void    thread_16_15_entry(ULONG thread_input)
831 {
832 
833 UINT    status;
834 
835 
836     /* Resume next highest priority thread.  */
837     status =  tx_thread_resume(&thread_14_13);
838 
839     /* Check for good status.  */
840     if (status == TX_SUCCESS)
841     {
842 
843         /* Increment this thread's counter.  */
844         thread_16_15_counter++;
845     }
846 }
847 
848 
thread_18_17_entry(ULONG thread_input)849 static void    thread_18_17_entry(ULONG thread_input)
850 {
851 
852 UINT    status;
853 
854 
855     /* Resume next highest priority thread.  */
856     status =  tx_thread_resume(&thread_16_15);
857 
858     /* Check for good status.  */
859     if (status == TX_SUCCESS)
860     {
861 
862         /* Increment this thread's counter.  */
863         thread_18_17_counter++;
864     }
865 }
866 
867 
thread_20_19_entry(ULONG thread_input)868 static void    thread_20_19_entry(ULONG thread_input)
869 {
870 
871 UINT    status;
872 
873 
874     /* Resume next highest priority thread.  */
875     status =  tx_thread_resume(&thread_18_17);
876 
877     /* Check for good status.  */
878     if (status == TX_SUCCESS)
879     {
880 
881         /* Increment this thread's counter.  */
882         thread_20_19_counter++;
883     }
884 }
885 
886 
thread_22_21_entry(ULONG thread_input)887 static void    thread_22_21_entry(ULONG thread_input)
888 {
889 
890 UINT    status;
891 
892 
893     /* Resume next highest priority thread.  */
894     status =  tx_thread_resume(&thread_20_19);
895 
896     /* Check for good status.  */
897     if (status == TX_SUCCESS)
898     {
899 
900         /* Increment this thread's counter.  */
901         thread_22_21_counter++;
902     }
903 }
904 
905 
thread_24_23_entry(ULONG thread_input)906 static void    thread_24_23_entry(ULONG thread_input)
907 {
908 
909 UINT    status;
910 
911 
912     /* Resume next highest priority thread.  */
913     status =  tx_thread_resume(&thread_22_21);
914 
915     /* Check for good status.  */
916     if (status == TX_SUCCESS)
917     {
918 
919         /* Increment this thread's counter.  */
920         thread_24_23_counter++;
921     }
922 }
923 
thread_26_25_entry(ULONG thread_input)924 static void    thread_26_25_entry(ULONG thread_input)\
925 {
926 
927 UINT    status;
928 
929 
930     /* Resume next highest priority thread.  */
931     status =  tx_thread_resume(&thread_24_23);
932 
933     /* Check for good status.  */
934     if (status == TX_SUCCESS)
935     {
936 
937         /* Increment this thread's counter.  */
938         thread_26_25_counter++;
939     }
940 }
941 
thread_28_27_entry(ULONG thread_input)942 static void    thread_28_27_entry(ULONG thread_input)
943 {
944 
945 UINT    status;
946 
947 
948     /* Resume next highest priority thread.  */
949     status =  tx_thread_resume(&thread_26_25);
950 
951     /* Check for good status.  */
952     if (status == TX_SUCCESS)
953     {
954 
955         /* Increment this thread's counter.  */
956         thread_28_27_counter++;
957     }
958 }
959 
thread_30_29_entry(ULONG thread_input)960 static void    thread_30_29_entry(ULONG thread_input)
961 {
962 
963 UINT    status;
964 
965 
966     /* Resume next highest priority thread.  */
967     status =  tx_thread_resume(&thread_28_27);
968 
969     /* Check for good status.  */
970     if (status == TX_SUCCESS)
971     {
972 
973         /* Increment this thread's counter.  */
974         thread_30_29_counter++;
975     }
976 
977     /* Resume thread_0.  */
978     tx_thread_resume(&thread_0);
979 }
980 
981 
982 #endif
983