RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
rtsched.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2023-2024, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2024-01-19 Shell Separate scheduling statements from rt_thread_t
9 * to rt_sched_thread_ctx. Add definitions of scheduler.
10 */
11#ifndef __RT_SCHED_H__
12#define __RT_SCHED_H__
13
14#include "rttypes.h"
15#include "rtcompiler.h"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21struct rt_thread;
22
24
30{
33
34 /* priority */
37#if RT_THREAD_PRIORITY_MAX > 32
38 rt_uint8_t number;
39 rt_uint8_t high_mask;
40#endif /* RT_THREAD_PRIORITY_MAX > 32 */
42
43};
44
50{
52
56
57#ifdef ARCH_USING_HW_THREAD_SELF
58 rt_uint8_t critical_switch_flag:1;
59#endif /* ARCH_USING_HW_THREAD_SELF */
60
61#ifdef RT_USING_SMP
62 rt_uint8_t bind_cpu;
63 rt_uint8_t oncpu;
64
65 rt_base_t critical_lock_nest;
66#endif
67
69};
70
71#define RT_SCHED_THREAD_CTX struct rt_sched_thread_ctx sched_thread_ctx;
72
73#define RT_SCHED_PRIV(thread) ((thread)->sched_thread_ctx.sched_thread_priv)
74#define RT_SCHED_CTX(thread) ((thread)->sched_thread_ctx)
75
80#define RT_THREAD_LIST_NODE_ENTRY(node) \
81 rt_container_of( \
82 rt_list_entry((node), struct rt_sched_thread_ctx, thread_list_node), \
83 struct rt_thread, sched_thread_ctx)
84#define RT_THREAD_LIST_NODE(thread) (RT_SCHED_CTX(thread).thread_list_node)
85
89
91
95
97
98#ifdef RT_USING_SMP
99#define RT_SCHED_DEBUG_IS_LOCKED do { RT_ASSERT(rt_sched_is_locked()); } while (0)
100#define RT_SCHED_DEBUG_IS_UNLOCKED do { RT_ASSERT(!rt_sched_is_locked()); } while (0)
101
102#else /* !RT_USING_SMP */
103
104#define RT_SCHED_DEBUG_IS_LOCKED
105#define RT_SCHED_DEBUG_IS_UNLOCKED
106#endif /* RT_USING_SMP */
107
112#if defined(__RT_KERNEL_SOURCE__) || defined(__RT_IPC_SOURCE__)
113
114/* thread initialization and startup routine */
115void rt_sched_thread_init_ctx(struct rt_thread *thread, rt_uint32_t tick, rt_uint8_t priority);
116void rt_sched_thread_init_priv(struct rt_thread *thread, rt_uint32_t tick, rt_uint8_t priority);
117void rt_sched_thread_startup(struct rt_thread *thread);
118
119/* scheduler related routine */
120void rt_sched_post_ctx_switch(struct rt_thread *thread);
122
123/* thread status operation */
130rt_err_t rt_sched_thread_suspend(struct rt_thread *thread, rt_sched_lock_level_t level);
132rt_err_t rt_sched_thread_bind_cpu(struct rt_thread *thread, int cpu);
136void rt_sched_insert_thread(struct rt_thread *thread);
137void rt_sched_remove_thread(struct rt_thread *thread);
138struct rt_thread *rt_sched_thread_self(void);
139
140#endif /* defined(__RT_KERNEL_SOURCE__) || defined(__RT_IPC_SOURCE__) */
141
142#ifdef __cplusplus
143}
144#endif
145
146#endif /* __RT_SCHED_H__ */
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_bool_t rt_sched_is_locked(void)
rt_err_t rt_sched_unlock_n_resched(rt_sched_lock_level_t level)
rt_uint8_t rt_sched_thread_status_t
rt_ubase_t rt_sched_lock_level_t
rt_int32_t rt_base_t
int rt_bool_t
rt_base_t rt_err_t
unsigned char rt_uint8_t
rt_uint32_t rt_tick_t
struct rt_list_node rt_list_t
unsigned int rt_uint32_t
rt_uint32_t rt_ubase_t
void rt_sched_thread_init_ctx(struct rt_thread *thread, rt_uint32_t tick, rt_uint8_t priority)
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_err_t rt_sched_thread_timer_stop(struct rt_thread *thread)
rt_uint8_t rt_sched_thread_get_init_prio(struct rt_thread *thread)
rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t priority)
Update priority of the target thread
rt_err_t rt_sched_thread_close(struct rt_thread *thread)
rt_err_t rt_sched_thread_ready(struct rt_thread *thread)
rt_uint8_t rt_sched_thread_is_suspended(struct rt_thread *thread)
rt_err_t rt_sched_tick_increase(rt_tick_t tick)
rt_err_t rt_sched_thread_yield(struct rt_thread *thread)
rt_err_t rt_sched_thread_timer_start(struct rt_thread *thread)
rt_list_t thread_list_node
struct rt_sched_thread_priv sched_thread_priv
rt_uint8_t sched_flag_ttmr_set
rt_uint8_t sched_flag_locked
rt_uint8_t current_priority
rt_uint32_t number_mask