summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2017-04-09 19:12:53 +0800
committerBernard Xiong <[email protected]>2017-04-09 19:12:53 +0800
commitb1f15366883aac930cb07767a7929d64a61d8a34 (patch)
treebeef82f24091a6ba0d609e2ffe90398e6b299b18
parent0a0f04069ab71f9084838ab570e2b6516c35f42a (diff)
[kernel] Add thread_inited_hook.
-rw-r--r--include/rtthread.h3
-rw-r--r--src/thread.c19
2 files changed, 20 insertions, 2 deletions
diff --git a/include/rtthread.h b/include/rtthread.h
index b8809474f6..d719e4bfb4 100644
--- a/include/rtthread.h
+++ b/include/rtthread.h
@@ -156,7 +156,8 @@ void rt_thread_timeout(void *parameter);
#ifdef RT_USING_HOOK
void rt_thread_suspend_sethook(void (*hook)(rt_thread_t thread));
-void rt_thread_resume_sethook(void (*hook)(rt_thread_t thread));
+void rt_thread_resume_sethook (void (*hook)(rt_thread_t thread));
+void rt_thread_inited_sethook (void (*hook)(rt_thread_t thread));
#endif
/*
diff --git a/src/thread.c b/src/thread.c
index ec7bfdefbd..0eef331d52 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -48,7 +48,9 @@ extern rt_list_t rt_thread_defunct;
#ifdef RT_USING_HOOK
static void (*rt_thread_suspend_hook)(rt_thread_t thread);
-static void (*rt_thread_resume_hook)(rt_thread_t thread);
+static void (*rt_thread_resume_hook) (rt_thread_t thread);
+static void (*rt_thread_inited_hook) (rt_thread_t thread);
+
/**
* @ingroup Hook
* This function sets a hook function when the system suspend a thread.
@@ -61,6 +63,7 @@ void rt_thread_suspend_sethook(void (*hook)(rt_thread_t thread))
{
rt_thread_suspend_hook = hook;
}
+
/**
* @ingroup Hook
* This function sets a hook function when the system resume a thread.
@@ -73,6 +76,18 @@ void rt_thread_resume_sethook(void (*hook)(rt_thread_t thread))
{
rt_thread_resume_hook = hook;
}
+
+/**
+ * @ingroup Hook
+ * This function sets a hook function when a thread is initialized.
+ *
+ * @param hook the specified hook function
+ */
+void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread))
+{
+ rt_thread_inited_hook = hook;
+}
+
#endif
void rt_thread_exit(void)
@@ -162,6 +177,8 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
0,
RT_TIMER_FLAG_ONE_SHOT);
+ RT_OBJECT_HOOK_CALL(rt_thread_inited_hook,(thread));
+
return RT_EOK;
}