From c79fbd373fc8b300cb2f4564aa934a4e93b81547 Mon Sep 17 00:00:00 2001 From: heyuanjie Date: Mon, 30 Jul 2018 11:12:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[lwp]=E7=BB=99thread=E6=B7=BB=E5=8A=A0lwp?= =?UTF-8?q?=E6=88=90=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/src/dfs.c | 2 +- components/lwp/lwp.c | 13 +++++-------- include/rtdef.h | 6 +++++- src/thread.c | 4 ++++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 46e3e51229..954c7f0731 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -510,7 +510,7 @@ struct dfs_fdtable* dfs_fdtable_get(void) #ifdef RT_USING_LWP struct rt_lwp *lwp; - lwp = (struct rt_lwp *)rt_thread_self()->user_data; + lwp = (struct rt_lwp *)rt_thread_self()->lwp; if (lwp) fdt = &lwp->fdt; else diff --git a/components/lwp/lwp.c b/components/lwp/lwp.c index 17d5ec0b10..0bfeb4b103 100644 --- a/components/lwp/lwp.c +++ b/components/lwp/lwp.c @@ -46,14 +46,14 @@ extern void lwp_user_entry(void *args, const void *text, void *data); void lwp_set_kernel_sp(uint32_t *sp) { struct rt_lwp *user_data; - user_data = (struct rt_lwp *)rt_current_thread->user_data; + user_data = (struct rt_lwp *)rt_current_thread->lwp; user_data->kernel_sp = sp; } uint32_t *lwp_get_kernel_sp(void) { struct rt_lwp *user_data; - user_data = (struct rt_lwp *)rt_current_thread->user_data; + user_data = (struct rt_lwp *)rt_current_thread->lwp; return user_data->kernel_sp; } @@ -286,7 +286,7 @@ static void lwp_cleanup(struct rt_thread *tid) dbg_log(DBG_INFO, "thread: %s, stack_addr: %08X\n", tid->name, tid->stack_addr); - lwp = (struct rt_lwp *)tid->user_data; + lwp = (struct rt_lwp *)tid->lwp; if (lwp->lwp_type == LWP_TYPE_DYN_ADDR) { @@ -327,16 +327,13 @@ static void lwp_cleanup(struct rt_thread *tid) static void lwp_thread(void *parameter) { - volatile uint32_t tmp; rt_thread_t tid; struct rt_lwp *lwp; - rt_kprintf("%08x %08x\n", &tmp, tmp); - lwp = (struct rt_lwp *)parameter; rt_lwp_mem_init(lwp); tid = rt_thread_self(); - tid->user_data = (rt_uint32_t)lwp; + tid->lwp = lwp; tid->cleanup = lwp_cleanup; lwp_user_entry(lwp->args, lwp->text_entry, lwp->data); @@ -344,7 +341,7 @@ static void lwp_thread(void *parameter) struct rt_lwp *rt_lwp_self(void) { - return (struct rt_lwp *)rt_thread_self()->user_data; + return (struct rt_lwp *)rt_thread_self()->lwp; } int exec(char *filename, int argc, char **argv) diff --git a/include/rtdef.h b/include/rtdef.h index 642ea0e729..7e7e63594f 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -556,7 +556,11 @@ struct rt_thread void (*cleanup)(struct rt_thread *tid); /**< cleanup function when thread exit */ - rt_uint32_t user_data; /**< private user data beyond this thread */ + rt_uint32_t user_data; /**< private user data beyond this thread */ + +#ifdef RT_USING_LWP + struct rt_lwp *lwp; /**< if NULL it's a kernel thread */ +#endif }; typedef struct rt_thread *rt_thread_t; diff --git a/src/thread.c b/src/thread.c index 9e5c97983b..b3d91b30d0 100644 --- a/src/thread.c +++ b/src/thread.c @@ -199,6 +199,10 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, thread->si_list = RT_NULL; #endif +#ifdef RT_USING_LWP + thread->lwp = RT_NULL; +#endif + RT_OBJECT_HOOK_CALL(rt_thread_inited_hook, (thread)); return RT_EOK; From 2373a9c7beaf52cb65630e32b080ef293504f6b5 Mon Sep 17 00:00:00 2001 From: heyuanjie Date: Tue, 31 Jul 2018 10:38:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0lwp=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtdef.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/rtdef.h b/include/rtdef.h index 7e7e63594f..f8d90ceadb 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -496,6 +496,10 @@ typedef siginfo_t rt_siginfo_t; #define RT_THREAD_CTRL_CHANGE_PRIORITY 0x02 /**< Change thread priority. */ #define RT_THREAD_CTRL_INFO 0x03 /**< Get thread information. */ +#ifdef RT_USING_LWP +struct rt_lwp; +#endif + /** * Thread structure */