From c79fbd373fc8b300cb2f4564aa934a4e93b81547 Mon Sep 17 00:00:00 2001 From: heyuanjie Date: Mon, 30 Jul 2018 11:12:12 +0800 Subject: [PATCH] =?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;