1 | /* |
---|
2 | * Scheduler Handler |
---|
3 | * |
---|
4 | * Copyright (C) 2010 Gedare Bloom. |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in the file LICENSE in this distribution or at |
---|
8 | * http://www.rtems.com/license/LICENSE. |
---|
9 | * |
---|
10 | * $Id$ |
---|
11 | */ |
---|
12 | |
---|
13 | #if HAVE_CONFIG_H |
---|
14 | #include "config.h" |
---|
15 | #endif |
---|
16 | |
---|
17 | #include <rtems/system.h> |
---|
18 | #include <rtems/score/apiext.h> |
---|
19 | #include <rtems/score/context.h> |
---|
20 | #include <rtems/score/interr.h> |
---|
21 | #include <rtems/score/isr.h> |
---|
22 | #include <rtems/score/object.h> |
---|
23 | #include <rtems/score/priority.h> |
---|
24 | #include <rtems/score/scheduler.h> |
---|
25 | #include <rtems/score/states.h> |
---|
26 | #include <rtems/score/sysstate.h> |
---|
27 | #include <rtems/score/thread.h> |
---|
28 | #include <rtems/score/threadq.h> |
---|
29 | #include <rtems/score/userext.h> |
---|
30 | #include <rtems/score/wkspace.h> |
---|
31 | |
---|
32 | /* |
---|
33 | * _Scheduler_priority_Yield |
---|
34 | * |
---|
35 | * This kernel routine will remove the running THREAD from the ready queue |
---|
36 | * and place it immediately at the rear of this chain. Reset timeslice |
---|
37 | * and yield the processor functions both use this routine, therefore if |
---|
38 | * reset is true and this is the only thread on the queue then the |
---|
39 | * timeslice counter is reset. The heir THREAD will be updated if the |
---|
40 | * running is also the currently the heir. |
---|
41 | * |
---|
42 | * Input parameters: |
---|
43 | * the_scheduler - pointer to scheduler control |
---|
44 | * |
---|
45 | * Output parameters: NONE |
---|
46 | * |
---|
47 | * INTERRUPT LATENCY: |
---|
48 | * ready chain |
---|
49 | * select heir |
---|
50 | */ |
---|
51 | |
---|
52 | void _Scheduler_priority_Yield( |
---|
53 | Scheduler_Control *the_scheduler __attribute__((unused)) |
---|
54 | ) |
---|
55 | { |
---|
56 | ISR_Level level; |
---|
57 | Thread_Control *executing; |
---|
58 | Chain_Control *ready; |
---|
59 | |
---|
60 | executing = _Thread_Executing; |
---|
61 | ready = executing->scheduler.priority->ready_chain; |
---|
62 | _ISR_Disable( level ); |
---|
63 | if ( !_Chain_Has_only_one_node( ready ) ) { |
---|
64 | _Chain_Extract_unprotected( &executing->Object.Node ); |
---|
65 | _Chain_Append_unprotected( ready, &executing->Object.Node ); |
---|
66 | |
---|
67 | _ISR_Flash( level ); |
---|
68 | |
---|
69 | if ( _Thread_Is_heir( executing ) ) |
---|
70 | _Thread_Heir = (Thread_Control *) _Chain_First( ready ); |
---|
71 | _Thread_Dispatch_necessary = true; |
---|
72 | } |
---|
73 | else if ( !_Thread_Is_heir( executing ) ) |
---|
74 | _Thread_Dispatch_necessary = true; |
---|
75 | |
---|
76 | _ISR_Enable( level ); |
---|
77 | } |
---|