/* includes */
#include "vxWorks.h"
#include "taskLib.h"
#include "taskHookLib.h" /* taskHook所对应的库 */
/* task function */
void myFunc(void)
{
int i;
printf("Hello, I am task %d\n", taskIdSelf()); /* Print task Id */
}
/* taskCreatHook */
void myTaskHook(void)
{
printf("task hook function called\n");
}
/* user entry */
void user_start()
{
taskCreateHookAdd( (FUNCPTR) myTaskHook);
taskSpawn("myTask", 90, 0x100, 2000, (FUNCPTR) myFunc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
运行输出:
task hook function called
Hello, I am task 14868640
有过Windows钩子(Hook)编程经验的读者应该对其概念并不陌生,Hook作为回调函数,当被挂接后。操作系统发生特定的事情时,将触发这个Hook回调函数的执行。VxWorks也有钩子的概念,不过比Windows要简单许多,主要有taskCreateHook、taskDeleteHook、taskSwitchHookAdd,可以通过如下6个API来添加和删除这三种Hook:
STATUS taskCreateHookAdd (FUNCPTR createHook /* routine to be called when a task is created */ );
STATUS taskCreateHookDelete (FUNCPTR createHook /* routine to be deleted from list */);
STATUS taskSwitchHookAdd (FUNCPTR switchHook /* routine to be called at every task switch */);
STATUS taskSwitchHookDelete (FUNCPTR switchHook /* routine to be deleted from list */);
STATUS taskDeleteHookAdd (FUNCPTR deleteHook /* routine to be called when a task is deleted */);
STATUS taskDeleteHookDelete (FUNCPTR deleteHook /* routine to be deleted from list */);
阅读(4548) | 评论(0) | 转发(0) |