1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSScoreSchedulerPriority |
---|
7 | * |
---|
8 | * @brief This source file contains the implementation of |
---|
9 | * _Scheduler_priority_Unblock(). |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * Scheduler Handler |
---|
14 | * |
---|
15 | * Copyright (C) 2010 Gedare Bloom. |
---|
16 | * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). |
---|
17 | * |
---|
18 | * Redistribution and use in source and binary forms, with or without |
---|
19 | * modification, are permitted provided that the following conditions |
---|
20 | * are met: |
---|
21 | * 1. Redistributions of source code must retain the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer. |
---|
23 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
24 | * notice, this list of conditions and the following disclaimer in the |
---|
25 | * documentation and/or other materials provided with the distribution. |
---|
26 | * |
---|
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
31 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
37 | * POSSIBILITY OF SUCH DAMAGE. |
---|
38 | */ |
---|
39 | |
---|
40 | #ifdef HAVE_CONFIG_H |
---|
41 | #include "config.h" |
---|
42 | #endif |
---|
43 | |
---|
44 | #include <rtems/score/schedulerpriorityimpl.h> |
---|
45 | |
---|
46 | void _Scheduler_priority_Unblock ( |
---|
47 | const Scheduler_Control *scheduler, |
---|
48 | Thread_Control *the_thread, |
---|
49 | Scheduler_Node *node |
---|
50 | ) |
---|
51 | { |
---|
52 | Scheduler_priority_Context *context; |
---|
53 | Scheduler_priority_Node *the_node; |
---|
54 | unsigned int priority; |
---|
55 | unsigned int unmapped_priority; |
---|
56 | |
---|
57 | context = _Scheduler_priority_Get_context( scheduler ); |
---|
58 | the_node = _Scheduler_priority_Node_downcast( node ); |
---|
59 | priority = (unsigned int ) _Scheduler_Node_get_priority( &the_node->Base ); |
---|
60 | unmapped_priority = SCHEDULER_PRIORITY_UNMAP( priority ); |
---|
61 | |
---|
62 | if ( unmapped_priority != the_node->Ready_queue.current_priority ) { |
---|
63 | _Scheduler_priority_Ready_queue_update( |
---|
64 | &the_node->Ready_queue, |
---|
65 | unmapped_priority, |
---|
66 | &context->Bit_map, |
---|
67 | &context->Ready[ 0 ] |
---|
68 | ); |
---|
69 | } |
---|
70 | |
---|
71 | _Scheduler_priority_Ready_queue_enqueue( |
---|
72 | &the_thread->Object.Node, |
---|
73 | &the_node->Ready_queue, |
---|
74 | &context->Bit_map |
---|
75 | ); |
---|
76 | |
---|
77 | /* TODO: flash critical section? */ |
---|
78 | |
---|
79 | /* |
---|
80 | * If the thread that was unblocked is more important than the heir, |
---|
81 | * then we have a new heir. This may or may not result in a |
---|
82 | * context switch. |
---|
83 | * |
---|
84 | * Normal case: |
---|
85 | * If the current thread is preemptible, then we need to do |
---|
86 | * a context switch. |
---|
87 | * Pseudo-ISR case: |
---|
88 | * Even if the thread isn't preemptible, if the new heir is |
---|
89 | * a pseudo-ISR system task, we need to do a context switch. |
---|
90 | */ |
---|
91 | if ( priority < _Thread_Get_priority( _Thread_Heir ) ) { |
---|
92 | _Scheduler_Update_heir( the_thread, priority == PRIORITY_PSEUDO_ISR ); |
---|
93 | } |
---|
94 | } |
---|