RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
scheduler_comm.c 文件参考
#include <rtdbg.h>
#include <rtthread.h>
+ scheduler_comm.c 的引用(Include)关系图:

浏览该文件的源代码.

宏定义

#define DBG_TAG   "kernel.sched"
 
#define DBG_LVL   DBG_INFO
 

函数

void rt_sched_thread_init_ctx (struct rt_thread *thread, rt_uint32_t tick, rt_uint8_t priority)
 
rt_err_t rt_sched_thread_timer_start (struct rt_thread *thread)
 
rt_err_t rt_sched_thread_timer_stop (struct rt_thread *thread)
 
rt_uint8_t rt_sched_thread_get_stat (struct rt_thread *thread)
 
rt_uint8_t rt_sched_thread_get_curr_prio (struct rt_thread *thread)
 
rt_uint8_t rt_sched_thread_get_init_prio (struct rt_thread *thread)
 
rt_uint8_t rt_sched_thread_is_suspended (struct rt_thread *thread)
 
rt_err_t rt_sched_thread_close (struct rt_thread *thread)
 
rt_err_t rt_sched_thread_yield (struct rt_thread *thread)
 
rt_err_t rt_sched_thread_ready (struct rt_thread *thread)
 
rt_err_t rt_sched_tick_increase (rt_tick_t tick)
 
rt_err_t rt_sched_thread_change_priority (struct rt_thread *thread, rt_uint8_t priority)
 

宏定义说明

◆ DBG_TAG

#define DBG_TAG   "kernel.sched"

在文件 scheduler_comm.c13 行定义.

◆ DBG_LVL

#define DBG_LVL   DBG_INFO

在文件 scheduler_comm.c14 行定义.

函数说明

◆ rt_sched_thread_init_ctx()

void rt_sched_thread_init_ctx ( struct rt_thread * thread,
rt_uint32_t tick,
rt_uint8_t priority )

在文件 scheduler_comm.c19 行定义.

20{
21 /* setup thread status */
22 RT_SCHED_CTX(thread).stat = RT_THREAD_INIT;
23
24#ifdef RT_USING_SMP
25 /* not bind on any cpu */
26 RT_SCHED_CTX(thread).bind_cpu = RT_CPUS_NR;
27 RT_SCHED_CTX(thread).oncpu = RT_CPU_DETACHED;
28#endif /* RT_USING_SMP */
29
30 rt_sched_thread_init_priv(thread, tick, priority);
31}
#define RT_THREAD_INIT
#define RT_SCHED_CTX(thread)

引用了 RT_SCHED_CTX , 以及 RT_THREAD_INIT.

◆ rt_sched_thread_timer_start()

rt_err_t rt_sched_thread_timer_start ( struct rt_thread * thread)

在文件 scheduler_comm.c33 行定义.

34{
36 RT_SCHED_CTX(thread).sched_flag_ttmr_set = 1;
37 return RT_EOK;
38}
#define RT_SCHED_DEBUG_IS_LOCKED

引用了 RT_SCHED_CTX , 以及 RT_SCHED_DEBUG_IS_LOCKED.

+ 这是这个函数的调用关系图:

◆ rt_sched_thread_timer_stop()

rt_err_t rt_sched_thread_timer_stop ( struct rt_thread * thread)

在文件 scheduler_comm.c40 行定义.

41{
42 rt_err_t error;
44
45 if (RT_SCHED_CTX(thread).sched_flag_ttmr_set)
46 {
47 error = rt_timer_stop(&thread->thread_timer);
48
49 /* mask out timer flag no matter stop success or not */
50 RT_SCHED_CTX(thread).sched_flag_ttmr_set = 0;
51 }
52 else
53 {
54 error = RT_EOK;
55 }
56 return error;
57}
rt_err_t rt_timer_stop(rt_timer_t timer)
This function will stop the timer
rt_base_t rt_err_t
RT_SCHED_THREAD_CTX struct rt_timer thread_timer

引用了 RT_SCHED_CTX, RT_SCHED_DEBUG_IS_LOCKED, rt_timer_stop() , 以及 rt_thread::thread_timer.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ rt_sched_thread_get_stat()

rt_uint8_t rt_sched_thread_get_stat ( struct rt_thread * thread)

在文件 scheduler_comm.c59 行定义.

60{
62 return RT_SCHED_CTX(thread).stat & RT_THREAD_STAT_MASK;
63}
#define RT_THREAD_STAT_MASK

引用了 RT_SCHED_CTX, RT_SCHED_DEBUG_IS_LOCKED , 以及 RT_THREAD_STAT_MASK.

+ 这是这个函数的调用关系图:

◆ rt_sched_thread_get_curr_prio()

rt_uint8_t rt_sched_thread_get_curr_prio ( struct rt_thread * thread)

在文件 scheduler_comm.c65 行定义.

66{
68 return RT_SCHED_PRIV(thread).current_priority;
69}
#define RT_SCHED_PRIV(thread)

引用了 RT_SCHED_DEBUG_IS_LOCKED , 以及 RT_SCHED_PRIV.

+ 这是这个函数的调用关系图:

◆ rt_sched_thread_get_init_prio()

rt_uint8_t rt_sched_thread_get_init_prio ( struct rt_thread * thread)

在文件 scheduler_comm.c71 行定义.

72{
73 /* read only fields, so lock is unecessary */
74 return RT_SCHED_PRIV(thread).init_priority;
75}

引用了 RT_SCHED_PRIV.

+ 这是这个函数的调用关系图:

◆ rt_sched_thread_is_suspended()

rt_uint8_t rt_sched_thread_is_suspended ( struct rt_thread * thread)
注解
Caller must hold the scheduler lock

在文件 scheduler_comm.c80 行定义.

81{
84}
int stat(const char *file, struct stat *buf)
#define RT_THREAD_SUSPEND_MASK

引用了 RT_SCHED_CTX, RT_SCHED_DEBUG_IS_LOCKED, RT_THREAD_SUSPEND_MASK , 以及 stat().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ rt_sched_thread_close()

rt_err_t rt_sched_thread_close ( struct rt_thread * thread)

在文件 scheduler_comm.c86 行定义.

87{
89 RT_SCHED_CTX(thread).stat = RT_THREAD_CLOSE;
90 return RT_EOK;
91}
#define RT_THREAD_CLOSE

引用了 RT_SCHED_CTX, RT_SCHED_DEBUG_IS_LOCKED , 以及 RT_THREAD_CLOSE.

+ 这是这个函数的调用关系图:

◆ rt_sched_thread_yield()

rt_err_t rt_sched_thread_yield ( struct rt_thread * thread)

在文件 scheduler_comm.c93 行定义.

94{
96
97 RT_SCHED_PRIV(thread).remaining_tick = RT_SCHED_PRIV(thread).init_tick;
98 RT_SCHED_CTX(thread).stat |= RT_THREAD_STAT_YIELD;
99
100 return RT_EOK;
101}
#define RT_THREAD_STAT_YIELD

引用了 RT_SCHED_CTX, RT_SCHED_DEBUG_IS_LOCKED, RT_SCHED_PRIV , 以及 RT_THREAD_STAT_YIELD.

+ 这是这个函数的调用关系图:

◆ rt_sched_thread_ready()

rt_err_t rt_sched_thread_ready ( struct rt_thread * thread)

Quiet timeout timer first if set. and don't continue if we failed, because it probably means that a timeout ISR racing to resume thread before us.

在文件 scheduler_comm.c103 行定义.

104{
105 rt_err_t error;
106
108
109 if (!rt_sched_thread_is_suspended(thread))
110 {
111 /* failed to proceed, and that's possibly due to a racing condition */
112 error = -RT_EINVAL;
113 }
114 else
115 {
116 if (RT_SCHED_CTX(thread).sched_flag_ttmr_set)
117 {
123 error = rt_sched_thread_timer_stop(thread);
124 }
125 else
126 {
127 error = RT_EOK;
128 }
129
130 if (!error)
131 {
132 /* remove from suspend list */
134
135 #ifdef RT_USING_SMART
136 thread->wakeup_handle.func = RT_NULL;
137 #endif
138
139 /* insert to schedule ready list and remove from susp list */
140 rt_sched_insert_thread(thread);
141 }
142 }
143
144 return error;
145}
rt_inline void rt_list_remove(rt_list_t *n)
remove node from list.
#define RT_THREAD_LIST_NODE(thread)
#define RT_NULL
rt_err_t rt_sched_thread_timer_stop(struct rt_thread *thread)
rt_uint8_t rt_sched_thread_is_suspended(struct rt_thread *thread)

引用了 rt_list_remove(), RT_NULL, RT_SCHED_CTX, RT_SCHED_DEBUG_IS_LOCKED, rt_sched_thread_is_suspended(), rt_sched_thread_timer_stop() , 以及 RT_THREAD_LIST_NODE.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ rt_sched_tick_increase()

rt_err_t rt_sched_tick_increase ( rt_tick_t tick)

在文件 scheduler_comm.c147 行定义.

148{
149 struct rt_thread *thread;
151
152 thread = rt_thread_self();
153
154 rt_sched_lock(&slvl);
155
156 if(RT_SCHED_PRIV(thread).remaining_tick > tick)
157 {
158 RT_SCHED_PRIV(thread).remaining_tick -= tick;
159 }
160 else
161 {
162 RT_SCHED_PRIV(thread).remaining_tick = 0;
163 }
164
165 if (RT_SCHED_PRIV(thread).remaining_tick)
166 {
167 rt_sched_unlock(slvl);
168 }
169 else
170 {
171 rt_sched_thread_yield(thread);
172
173 /* request a rescheduling even though we are probably in an ISR */
175 }
176
177 return RT_EOK;
178}
rt_thread_t rt_thread_self(void)
This function will return self thread object.
rt_ubase_t rt_sched_lock_level_t
rt_err_t rt_sched_thread_yield(struct rt_thread *thread)
rt_err_t rt_sched_lock(rt_sched_lock_level_t *plvl)
rt_err_t rt_sched_unlock(rt_sched_lock_level_t level)
rt_err_t rt_sched_unlock_n_resched(rt_sched_lock_level_t level)

引用了 rt_sched_lock(), RT_SCHED_PRIV, rt_sched_thread_yield(), rt_sched_unlock(), rt_sched_unlock_n_resched() , 以及 rt_thread_self().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ rt_sched_thread_change_priority()

rt_err_t rt_sched_thread_change_priority ( struct rt_thread * thread,
rt_uint8_t priority )

Update priority of the target thread

在文件 scheduler_comm.c183 行定义.

184{
185 RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX);
187
188 /* for ready thread, change queue; otherwise simply update the priority */
190 {
191 /* remove thread from schedule queue first */
192 rt_sched_remove_thread(thread);
193
194 /* change thread priority */
195 RT_SCHED_PRIV(thread).current_priority = priority;
196
197 /* recalculate priority attribute */
198#if RT_THREAD_PRIORITY_MAX > 32
199 RT_SCHED_PRIV(thread).number = RT_SCHED_PRIV(thread).current_priority >> 3; /* 5bit */
200 RT_SCHED_PRIV(thread).number_mask = 1 << RT_SCHED_PRIV(thread).number;
201 RT_SCHED_PRIV(thread).high_mask = 1 << (RT_SCHED_PRIV(thread).current_priority & 0x07); /* 3bit */
202#else
203 RT_SCHED_PRIV(thread).number_mask = 1 << RT_SCHED_PRIV(thread).current_priority;
204#endif /* RT_THREAD_PRIORITY_MAX > 32 */
205 RT_SCHED_CTX(thread).stat = RT_THREAD_INIT;
206
207 /* insert thread to schedule queue again */
208 rt_sched_insert_thread(thread);
209 }
210 else
211 {
212 RT_SCHED_PRIV(thread).current_priority = priority;
213
214 /* recalculate priority attribute */
215#if RT_THREAD_PRIORITY_MAX > 32
216 RT_SCHED_PRIV(thread).number = RT_SCHED_PRIV(thread).current_priority >> 3; /* 5bit */
217 RT_SCHED_PRIV(thread).number_mask = 1 << RT_SCHED_PRIV(thread).number;
218 RT_SCHED_PRIV(thread).high_mask = 1 << (RT_SCHED_PRIV(thread).current_priority & 0x07); /* 3bit */
219#else
220 RT_SCHED_PRIV(thread).number_mask = 1 << RT_SCHED_PRIV(thread).current_priority;
221#endif /* RT_THREAD_PRIORITY_MAX > 32 */
222 }
223
224 return RT_EOK;
225}
#define RT_ASSERT(EX)
#define RT_THREAD_READY

引用了 RT_ASSERT, RT_SCHED_CTX, RT_SCHED_DEBUG_IS_LOCKED, RT_SCHED_PRIV, RT_THREAD_INIT, RT_THREAD_READY, RT_THREAD_STAT_MASK , 以及 stat().

+ 函数调用图:
+ 这是这个函数的调用关系图: