Skip to content

Commit 5bf1ffb

Browse files
committed
重新格式化
1 parent 052ed70 commit 5bf1ffb

File tree

1 file changed

+34
-67
lines changed

1 file changed

+34
-67
lines changed

src/scheduler_up.c

Lines changed: 34 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ static void (*rt_scheduler_switch_hook)(struct rt_thread *tid);
7070
*
7171
* @param hook is the hook function.
7272
*/
73-
void rt_scheduler_sethook(void (*hook)(struct rt_thread *from,
74-
struct rt_thread *to))
73+
void rt_scheduler_sethook(void (*hook)(struct rt_thread *from, struct rt_thread *to))
7574
{
7675
rt_scheduler_hook = hook;
7776
}
@@ -95,11 +94,9 @@ rt_inline void _scheduler_update_highest_priority(void)
9594
#if RT_THREAD_PRIORITY_MAX > 32
9695
rt_ubase_t number;
9796
number = __rt_ffs(rt_thread_ready_priority_group) - 1;
98-
rt_thread_ready_highest_priority =
99-
(number << 3) + __rt_ffs(rt_thread_ready_table[number]) - 1;
97+
rt_thread_ready_highest_priority = (number << 3) + __rt_ffs(rt_thread_ready_table[number]) - 1;
10098
#else
101-
rt_thread_ready_highest_priority =
102-
__rt_ffs(rt_thread_ready_priority_group) - 1;
99+
rt_thread_ready_highest_priority = __rt_ffs(rt_thread_ready_priority_group) - 1;
103100
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
104101
}
105102

@@ -171,8 +168,7 @@ void rt_system_scheduler_start(void)
171168
struct rt_thread *to_thread;
172169

173170
_scheduler_update_highest_priority();
174-
to_thread =
175-
_scheduler_get_priority_thread(rt_thread_ready_highest_priority);
171+
to_thread = _scheduler_get_priority_thread(rt_thread_ready_highest_priority);
176172

177173
rt_cpu_self()->current_thread = to_thread;
178174

@@ -198,29 +194,24 @@ void rt_system_scheduler_start(void)
198194
rt_inline void _rt_sched_insert_thread(struct rt_thread *thread)
199195
{
200196
/* READY thread, insert to ready queue */
201-
RT_SCHED_CTX(thread).stat =
202-
RT_THREAD_READY | (RT_SCHED_CTX(thread).stat & ~RT_THREAD_STAT_MASK);
197+
RT_SCHED_CTX(thread).stat = RT_THREAD_READY | (RT_SCHED_CTX(thread).stat & ~RT_THREAD_STAT_MASK);
203198
/* there is no time slices left(YIELD), inserting thread before ready list*/
204199
if ((RT_SCHED_CTX(thread).stat & RT_THREAD_STAT_YIELD_MASK) != 0) {
205-
rt_list_insert_before(
206-
&(rt_thread_priority_table[RT_SCHED_PRIV(thread).current_priority]),
207-
&RT_THREAD_LIST_NODE(thread));
200+
rt_list_insert_before(&(rt_thread_priority_table[RT_SCHED_PRIV(thread).current_priority]),
201+
&RT_THREAD_LIST_NODE(thread));
208202
}
209203
/* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
210204
else {
211-
rt_list_insert_after(
212-
&(rt_thread_priority_table[RT_SCHED_PRIV(thread).current_priority]),
213-
&RT_THREAD_LIST_NODE(thread));
205+
rt_list_insert_after(&(rt_thread_priority_table[RT_SCHED_PRIV(thread).current_priority]),
206+
&RT_THREAD_LIST_NODE(thread));
214207
}
215208

216-
LOG_D("insert thread[%.*s], the priority: %d", RT_NAME_MAX,
217-
thread->parent.name,
209+
LOG_D("insert thread[%.*s], the priority: %d", RT_NAME_MAX, thread->parent.name,
218210
RT_SCHED_PRIV(rt_current_thread).current_priority);
219211

220212
/* set priority mask */
221213
#if RT_THREAD_PRIORITY_MAX > 32
222-
rt_thread_ready_table[RT_SCHED_PRIV(thread).number] |=
223-
RT_SCHED_PRIV(thread).high_mask;
214+
rt_thread_ready_table[RT_SCHED_PRIV(thread).number] |= RT_SCHED_PRIV(thread).high_mask;
224215
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
225216
rt_thread_ready_priority_group |= RT_SCHED_PRIV(thread).number_mask;
226217
}
@@ -234,20 +225,16 @@ rt_inline void _rt_sched_insert_thread(struct rt_thread *thread)
234225
*/
235226
rt_inline void _rt_sched_remove_thread(struct rt_thread *thread)
236227
{
237-
LOG_D("remove thread[%.*s], the priority: %d", RT_NAME_MAX,
238-
thread->parent.name,
228+
LOG_D("remove thread[%.*s], the priority: %d", RT_NAME_MAX, thread->parent.name,
239229
RT_SCHED_PRIV(rt_current_thread).current_priority);
240230

241231
/* remove thread from ready list */
242232
rt_list_remove(&RT_THREAD_LIST_NODE(thread));
243-
if (rt_list_isempty(&(
244-
rt_thread_priority_table[RT_SCHED_PRIV(thread).current_priority]))) {
233+
if (rt_list_isempty(&(rt_thread_priority_table[RT_SCHED_PRIV(thread).current_priority]))) {
245234
#if RT_THREAD_PRIORITY_MAX > 32
246-
rt_thread_ready_table[RT_SCHED_PRIV(thread).number] &=
247-
~RT_SCHED_PRIV(thread).high_mask;
235+
rt_thread_ready_table[RT_SCHED_PRIV(thread).number] &= ~RT_SCHED_PRIV(thread).high_mask;
248236
if (rt_thread_ready_table[RT_SCHED_PRIV(thread).number] == 0) {
249-
rt_thread_ready_priority_group &=
250-
~RT_SCHED_PRIV(thread).number_mask;
237+
rt_thread_ready_priority_group &= ~RT_SCHED_PRIV(thread).number_mask;
251238
}
252239
#else
253240
rt_thread_ready_priority_group &= ~RT_SCHED_PRIV(thread).number_mask;
@@ -283,24 +270,18 @@ void rt_schedule(void)
283270
need_insert_from_thread = RT_FALSE;
284271
curr_thread = rt_thread_self();
285272

286-
if ((RT_SCHED_CTX(curr_thread).stat & RT_THREAD_STAT_MASK) ==
287-
RT_THREAD_RUNNING) {
288-
if (RT_SCHED_PRIV(curr_thread).current_priority <
289-
rt_thread_ready_highest_priority) {
273+
if ((RT_SCHED_CTX(curr_thread).stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING) {
274+
if (RT_SCHED_PRIV(curr_thread).current_priority < rt_thread_ready_highest_priority) {
290275
to_thread = curr_thread;
291-
} else if (RT_SCHED_PRIV(curr_thread).current_priority ==
292-
rt_thread_ready_highest_priority &&
293-
(RT_SCHED_CTX(curr_thread).stat &
294-
RT_THREAD_STAT_YIELD_MASK) == 0) {
276+
} else if (RT_SCHED_PRIV(curr_thread).current_priority == rt_thread_ready_highest_priority &&
277+
(RT_SCHED_CTX(curr_thread).stat & RT_THREAD_STAT_YIELD_MASK) == 0) {
295278
to_thread = curr_thread;
296279
} else {
297-
to_thread = _scheduler_get_priority_thread(
298-
rt_thread_ready_highest_priority);
280+
to_thread = _scheduler_get_priority_thread(rt_thread_ready_highest_priority);
299281
need_insert_from_thread = RT_TRUE;
300282
}
301283
} else {
302-
to_thread = _scheduler_get_priority_thread(
303-
rt_thread_ready_highest_priority);
284+
to_thread = _scheduler_get_priority_thread(rt_thread_ready_highest_priority);
304285
}
305286

306287
if (to_thread != curr_thread) {
@@ -316,25 +297,21 @@ void rt_schedule(void)
316297
_rt_sched_insert_thread(from_thread);
317298
}
318299

319-
if ((RT_SCHED_CTX(from_thread).stat & RT_THREAD_STAT_YIELD_MASK) !=
320-
0) {
300+
if ((RT_SCHED_CTX(from_thread).stat & RT_THREAD_STAT_YIELD_MASK) != 0) {
321301
RT_SCHED_CTX(from_thread).stat &= ~RT_THREAD_STAT_YIELD_MASK;
322302
}
323303

324304
_rt_sched_remove_thread(to_thread);
325-
RT_SCHED_CTX(to_thread).stat =
326-
RT_THREAD_RUNNING |
327-
(RT_SCHED_CTX(to_thread).stat & ~RT_THREAD_STAT_MASK);
305+
RT_SCHED_CTX(to_thread).stat = RT_THREAD_RUNNING | (RT_SCHED_CTX(to_thread).stat & ~RT_THREAD_STAT_MASK);
328306

329307
_scheduler_update_highest_priority();
330308

331309
/* switch to new thread */
332310
LOG_D("[%d]switch to priority#%d "
333311
"thread:%.*s(sp:0x%08x), "
334312
"from thread:%.*s(sp: 0x%08x)",
335-
rt_interrupt_nest, highest_ready_priority, RT_NAME_MAX,
336-
to_thread->parent.name, to_thread->sp, RT_NAME_MAX,
337-
from_thread->parent.name, from_thread->sp);
313+
rt_interrupt_nest, highest_ready_priority, RT_NAME_MAX, to_thread->parent.name, to_thread->sp,
314+
RT_NAME_MAX, from_thread->parent.name, from_thread->sp);
338315

339316
RT_SCHEDULER_STACK_CHECK(to_thread);
340317

@@ -343,21 +320,18 @@ void rt_schedule(void)
343320

344321
RT_OBJECT_HOOK_CALL(rt_scheduler_switch_hook, (from_thread));
345322

346-
rt_hw_context_switch((rt_uintptr_t)&from_thread->sp,
347-
(rt_uintptr_t)&to_thread->sp);
323+
rt_hw_context_switch((rt_uintptr_t)&from_thread->sp, (rt_uintptr_t)&to_thread->sp);
348324

349325
/* enable interrupt */
350326
rt_hw_interrupt_enable(level);
351327

352328
#ifdef RT_USING_SIGNALS
353329
/* check stat of thread for signal */
354330
level = rt_hw_interrupt_disable();
355-
if (RT_SCHED_CTX(curr_thread).stat &
356-
RT_THREAD_STAT_SIGNAL_PENDING) {
331+
if (RT_SCHED_CTX(curr_thread).stat & RT_THREAD_STAT_SIGNAL_PENDING) {
357332
extern void rt_thread_handle_sig(rt_bool_t clean_state);
358333

359-
RT_SCHED_CTX(curr_thread).stat &=
360-
~RT_THREAD_STAT_SIGNAL_PENDING;
334+
RT_SCHED_CTX(curr_thread).stat &= ~RT_THREAD_STAT_SIGNAL_PENDING;
361335

362336
rt_hw_interrupt_enable(level);
363337

@@ -371,8 +345,7 @@ void rt_schedule(void)
371345
} else {
372346
LOG_D("switch in interrupt");
373347

374-
rt_hw_context_switch_interrupt((rt_uintptr_t)&from_thread->sp,
375-
(rt_uintptr_t)&to_thread->sp,
348+
rt_hw_context_switch_interrupt((rt_uintptr_t)&from_thread->sp, (rt_uintptr_t)&to_thread->sp,
376349
from_thread, to_thread);
377350
}
378351
}
@@ -387,14 +360,11 @@ void rt_schedule(void)
387360
void rt_sched_thread_startup(struct rt_thread *thread)
388361
{
389362
#if RT_THREAD_PRIORITY_MAX > 32
390-
RT_SCHED_PRIV(thread).number = RT_SCHED_PRIV(thread).current_priority >>
391-
3; /* 5bit */
363+
RT_SCHED_PRIV(thread).number = RT_SCHED_PRIV(thread).current_priority >> 3; /* 5bit */
392364
RT_SCHED_PRIV(thread).number_mask = 1L << RT_SCHED_PRIV(thread).number;
393-
RT_SCHED_PRIV(thread).high_mask =
394-
1L << (RT_SCHED_PRIV(thread).current_priority & 0x07); /* 3bit */
365+
RT_SCHED_PRIV(thread).high_mask = 1L << (RT_SCHED_PRIV(thread).current_priority & 0x07); /* 3bit */
395366
#else
396-
RT_SCHED_PRIV(thread).number_mask =
397-
1L << RT_SCHED_PRIV(thread).current_priority;
367+
RT_SCHED_PRIV(thread).number_mask = 1L << RT_SCHED_PRIV(thread).current_priority;
398368
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
399369

400370
/* change thread stat, so we can resume it */
@@ -414,8 +384,7 @@ void rt_sched_thread_startup(struct rt_thread *thread)
414384
* - Initializes priority masks (number_mask, number, high_mask for >32 priorities)
415385
* - Sets initial and remaining time slice ticks
416386
*/
417-
void rt_sched_thread_init_priv(struct rt_thread *thread, rt_uint32_t tick,
418-
rt_uint8_t priority)
387+
void rt_sched_thread_init_priv(struct rt_thread *thread, rt_uint32_t tick, rt_uint8_t priority)
419388
{
420389
rt_list_init(&RT_THREAD_LIST_NODE(thread));
421390

@@ -455,9 +424,7 @@ void rt_sched_insert_thread(struct rt_thread *thread)
455424

456425
/* it's current thread, it should be RUNNING thread */
457426
if (thread == rt_current_thread) {
458-
RT_SCHED_CTX(thread).stat =
459-
RT_THREAD_RUNNING |
460-
(RT_SCHED_CTX(thread).stat & ~RT_THREAD_STAT_MASK);
427+
RT_SCHED_CTX(thread).stat = RT_THREAD_RUNNING | (RT_SCHED_CTX(thread).stat & ~RT_THREAD_STAT_MASK);
461428
goto __exit;
462429
}
463430

0 commit comments

Comments
 (0)