RT Thread 排程器鉤子函式的使用

2021-08-26 02:41:52 字數 1664 閱讀 1116

排程器鉤子函式如何使用?

可以使用函式 rt_scheduler_sethook(scheduler_hook);來設定乙個排程器鉤子,括號裡面的函式就是你自己的鉤子函式。

/*

* 在排程器鉤子中列印執行緒切換資訊

*/#include #define thread_stack_size 1024

#define thread_priority 20

#define thread_timeslice 10

/* 針對每個執行緒的計數器 */

volatile rt_uint32_t count[2];

/* 執行緒1、2共用乙個入口,但入口引數不同 */

static void thread_entry(void* parameter)

}static rt_thread_t tid1 = rt_null;

static rt_thread_t tid2 = rt_null;

static void scheduler_hook(struct rt_thread* from, struct rt_thread* to)

int sch_hook_sample()

/* 匯出到 msh 命令列表中 */

msh_cmd_export(sch_hook_sample, sch_hook sample);

**執行結果:

\ | /

- rt - thread operating system

/ | \ 3.1.0 build aug 27 2018

msh >sch_hook_sample

msh >from: tshell --> to: thread1

thread 1 is running

from: thread1 --> to: thread2

thread 2 is running

from: thread2 --> to: tidle

from: tidle --> to: thread1

thread 1 is running

from: thread1 --> to: tidle

from: tidle --> to: thread2

thread 2 is running

from: thread2 --> to: tidle

from: tidle --> to: thread1

thread 1 is running

from: thread1 --> to: tidle

from: tidle --> to: thread2

thread 2 is running

from: thread2 --> to: tidle

from: tidle --> to: thread1

thread 1 is running

from: thread1 --> to: tidle

from: tidle --> to: thread2

thread 2 is running

from: thread2 --> to: tidle

可以看到執行緒1 、2 、空閒執行緒之間的切換過程。

mounted鉤子函式 對vue中鉤子函式的理解

1 beforecreate 鉤子 該階段元件例項剛建立,元件屬性計算之前 可理解為元件屬性還未初始化,未繫結,未掛載元素el 比如 el,data,methods等,如果你試圖在beforecreated鉤子中獲取這些屬性值,會得到ubdefined 的結果,但是 可以獲取到this物件,因為此時...

mysql 鉤子函式 Flask鉤子函式是什麼

flask鉤子函式 在flask中鉤子函式是使用特定的裝飾器的函式。為什麼叫做鉤子函式呢,是因為鉤子函式可以在正常執行的 中,插入一段自己想要執行的 那麼這種函式就叫做鉤子函式。before first request flask專案第一次部署後會執行的鉤子函式。before request 請求已...

UCOS III 鉤子函式

鉤子函式一般主要是用來擴充套件其他函式 任務 功能的,鉤子函式有如下幾個 1 osidletaskhook 空閒任務呼叫這個函式,可以用來讓 cpu進入低功耗模式2 osinithook 系統初始化函式 osinit 呼叫此函式。3 osstattaskhook 統計任務每秒中都會呼叫這個函式,此函...