Skip to content

[kernel] 将rt_thread结构体改为显式继承rt_object #7131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bsp/allwinner_tina/libcpu/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void rt_hw_trap_udef(struct rt_hw_register *regs)
rt_hw_show_register(regs);

rt_kprintf("undefined instruction\n");
rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
rt_kprintf("thread - %s stack:\n", rt_current_thread->parent.name);

#if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
list_thread();
Expand Down Expand Up @@ -139,7 +139,7 @@ void rt_hw_trap_pabt(struct rt_hw_register *regs)
rt_hw_show_register(regs);

rt_kprintf("prefetch abort\n");
rt_kprintf("thread - %s stack:\n", RT_NAME_MAX, rt_current_thread->name);
rt_kprintf("thread - %s stack:\n", RT_NAME_MAX, rt_current_thread->parent.name);

#if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
list_thread();
Expand Down Expand Up @@ -167,7 +167,7 @@ void rt_hw_trap_dabt(struct rt_hw_register *regs)
rt_hw_show_register(regs);

rt_kprintf("data abort\n");
rt_kprintf("thread - %s stack:\n", RT_NAME_MAX, rt_current_thread->name);
rt_kprintf("thread - %s stack:\n", RT_NAME_MAX, rt_current_thread->parent.name);

#if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
list_thread();
Expand Down
2 changes: 1 addition & 1 deletion bsp/bluetrum/ab32vg1-ab-prougen/board/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void exception_isr(void)

#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_console_set_device(RT_NULL);
rt_kprintf(stack_info, rt_thread_self()->sp, rt_thread_self()->name);
rt_kprintf(stack_info, rt_thread_self()->sp, rt_thread_self()->parent.name);
#endif

while (1);
Expand Down
6 changes: 3 additions & 3 deletions bsp/dm365/platform/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void rt_hw_trap_udef(struct rt_hw_register *regs)
rt_hw_show_register(regs);

rt_kprintf("undefined instruction\n");
rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
rt_kprintf("thread - %s stack:\n", rt_current_thread->parent.name);

#if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
list_thread();
Expand Down Expand Up @@ -92,7 +92,7 @@ void rt_hw_trap_pabt(struct rt_hw_register *regs)
rt_hw_show_register(regs);

rt_kprintf("prefetch abort\n");
rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
rt_kprintf("thread - %s stack:\n", rt_current_thread->parent.name);

#if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
list_thread();
Expand Down Expand Up @@ -128,7 +128,7 @@ void rt_hw_trap_dabt(struct rt_hw_register *regs)
rt_hw_show_register(regs);

rt_kprintf("data abort\n");
rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
rt_kprintf("thread - %s stack:\n", rt_current_thread->parent.name);

#if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
list_thread();
Expand Down
4 changes: 2 additions & 2 deletions bsp/raspberry-pico/libcpu/cpuport.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ void rt_hw_hard_fault_exception(struct exception_stack_frame *contex)

#ifdef RT_USING_SMP
rt_thread_t rt_current_thread = rt_thread_self();
rt_kprintf("hard fault on cpu : %d on thread: %s\n", rt_current_thread->oncpu, rt_current_thread->name);
rt_kprintf("hard fault on cpu : %d on thread: %s\n", rt_current_thread->oncpu, rt_current_thread->parent.name);
#else
rt_kprintf("hard fault on thread: %s\n", rt_current_thread->name);
rt_kprintf("hard fault on thread: %s\n", rt_current_thread->parent.name);
#endif
#if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
list_thread();
Expand Down
8 changes: 4 additions & 4 deletions bsp/simulator/drivers/module_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ rt_module_t rt_module_self(void)
return RT_NULL;

/* return current module */
return (rt_module_t)tid->module_id;
return (rt_module_t)tid->parent.module_id;
}
RTM_EXPORT(rt_module_self);

Expand Down Expand Up @@ -319,7 +319,7 @@ rt_module_t rt_module_open(const char *path)
module->module_entry));

/* set module id */
module->module_thread->module_id = (void *)module;
module->module_thread->parent.module_id = (void *)module;
module->parent.flag = RT_MODULE_FLAG_WITHENTRY;

/* startup module thread */
Expand Down Expand Up @@ -520,11 +520,11 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_
2048, RT_THREAD_PRIORITY_MAX - 2, 10);

/* set module id */
module->module_thread->module_id = (void *)module;
module->module_thread->parent.module_id = (void *)module;
module->parent.flag = RT_MODULE_FLAG_WITHENTRY;

/* startup module thread */
rt_thread_startup(module->module_thread);
rt_thread_startup(module->parent.module_thread);
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions bsp/taihu/applications/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ static void thread1_entry(void* parameter)
while (1)
{
rt_sem_release(&sem2);
rt_kprintf("thread1..: %s\n", rt_thread_self()->name);
rt_kprintf("thread1..: %s\n", rt_thread_self()->parent.name);
rt_sem_take(&sem1, RT_WAITING_FOREVER);
rt_kprintf("get semaphore: %s!\n", rt_thread_self()->name);
rt_kprintf("thread1..: %s\n", rt_thread_self()->parent.name);
}
}

Expand All @@ -37,7 +37,7 @@ static void thread2_entry(void* parameter)
while (1)
{
rt_sem_take(&sem2, RT_WAITING_FOREVER);
rt_kprintf("thread2--->: %s\n", rt_thread_self()->name);
rt_kprintf("thread2--->: %s\n", rt_thread_self()->parent.name);
rt_sem_release(&sem1);
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ static void thread1_entry(void* parameter)
rt_uint32_t count = 0;
while (1)
{
rt_kprintf("%s: count = %d\n", rt_thread_self()->name, count ++);
rt_kprintf("%s: count = %d\n", rt_thread_self()->parent.name, count ++);

rt_thread_delay(10);
}
Expand Down
2 changes: 1 addition & 1 deletion bsp/w60x/drivers/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static void _thread_inited_hook(rt_thread_t thread)
if ((stk_start + stack_size) >= TASK_STACK_USING_MEM_UPPER_RANGE)
{
rt_kprintf("thread[%s] stack only between 0x%08x and 0x%08x, please use rt_create_thread()!!\n",
thread->name, TASK_STACK_USING_MEM_LOWER_RANGE, TASK_STACK_USING_MEM_UPPER_RANGE);
thread->parent.name, TASK_STACK_USING_MEM_LOWER_RANGE, TASK_STACK_USING_MEM_UPPER_RANGE);
}
RT_ASSERT((stk_start + stack_size) < TASK_STACK_USING_MEM_UPPER_RANGE);
}
Expand Down
12 changes: 6 additions & 6 deletions components/finsh/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ long list_thread(void)

#ifdef RT_USING_SMP
if (thread->oncpu != RT_CPU_DETACHED)
rt_kprintf("%-*.*s %3d %3d %4d ", maxlen, RT_NAME_MAX, thread->name, thread->oncpu, thread->bind_cpu, thread->current_priority);
rt_kprintf("%-*.*s %3d %3d %4d ", maxlen, RT_NAME_MAX, thread->parent.name, thread->oncpu, thread->bind_cpu, thread->current_priority);
else
rt_kprintf("%-*.*s N/A %3d %4d ", maxlen, RT_NAME_MAX, thread->name, thread->bind_cpu, thread->current_priority);
rt_kprintf("%-*.*s N/A %3d %4d ", maxlen, RT_NAME_MAX, thread->parent.name, thread->bind_cpu, thread->current_priority);

#else
rt_kprintf("%-*.*s %3d ", maxlen, RT_NAME_MAX, thread->name, thread->current_priority);
rt_kprintf("%-*.*s %3d ", maxlen, RT_NAME_MAX, thread->parent.name, thread->current_priority);
#endif /*RT_USING_SMP*/
stat = (thread->stat & RT_THREAD_STAT_MASK);
if (stat == RT_THREAD_READY) rt_kprintf(" ready ");
Expand Down Expand Up @@ -256,7 +256,7 @@ static void show_wait_queue(struct rt_list_node *list)
for (node = list->next; node != list; node = node->next)
{
thread = rt_list_entry(node, struct rt_thread, tlist);
rt_kprintf("%.*s", RT_NAME_MAX, thread->name);
rt_kprintf("%.*s", RT_NAME_MAX, thread->parent.name);

if (node->next != list)
rt_kprintf("/");
Expand Down Expand Up @@ -439,7 +439,7 @@ long list_mutex(void)
maxlen, RT_NAME_MAX,
m->parent.parent.name,
RT_NAME_MAX,
m->owner->name,
m->owner->parent.name,
m->hold,
m->priority,
rt_list_len(&m->parent.suspend_thread));
Expand All @@ -452,7 +452,7 @@ long list_mutex(void)
maxlen, RT_NAME_MAX,
m->parent.parent.name,
RT_NAME_MAX,
m->owner->name,
m->owner->parent.name,
m->hold,
m->priority,
rt_list_len(&m->parent.suspend_thread));
Expand Down
2 changes: 1 addition & 1 deletion components/libc/compilers/common/cstdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void __rt_libc_exit(int status)

if (self != RT_NULL)
{
LOG_W("thread:%s exit:%d!", self->name, status);
LOG_W("thread:%s exit:%d!", self->parent.name, status);
#ifdef RT_USING_PTHREADS
if(self->pthread_data != RT_NULL)
{
Expand Down
10 changes: 5 additions & 5 deletions components/libc/posix/libdl/dlmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ struct rt_dlmodule *dlmodule_create(void)

void dlmodule_destroy_subthread(struct rt_dlmodule *module, rt_thread_t thread)
{
RT_ASSERT(thread->module_id == module);
RT_ASSERT(thread->parent.module_id== module);

/* lock scheduler to prevent scheduling in cleanup function. */
rt_enter_critical();
Expand Down Expand Up @@ -225,7 +225,7 @@ void dlmodule_destroy_subthread(struct rt_dlmodule *module, rt_thread_t thread)
rt_thread_free_sig(thread);
#endif

if (thread->type & RT_Object_Class_Static)
if (thread->parent.type & RT_Object_Class_Static)
{
/* detach object */
rt_object_detach((rt_object_t)thread);
Expand Down Expand Up @@ -409,7 +409,7 @@ struct rt_dlmodule *dlmodule_self(void)
tid = rt_thread_self();
if (tid)
{
ret = (struct rt_dlmodule*) tid->module_id;
ret = (struct rt_dlmodule*) tid->parent.module_id;
}

return ret;
Expand Down Expand Up @@ -555,7 +555,7 @@ struct rt_dlmodule* dlmodule_exec(const char* pgname, const char* cmd, int cmd_s
module->stack_size, module->priority, 10);
if (tid)
{
tid->module_id = module;
tid->parent.module_id= module;
module->main_thread = tid;

rt_thread_startup(tid);
Expand Down Expand Up @@ -732,7 +732,7 @@ struct rt_dlmodule* dlmodule_exec_custom(const char* pgname, const char* cmd, in
module->stack_size, module->priority, 10);
if (tid)
{
tid->module_id = module;
tid->parent.module_id= module;
module->main_thread = tid;

rt_thread_startup(tid);
Expand Down
4 changes: 2 additions & 2 deletions components/lwp/arch/x86/i386/lwp_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int arch_expand_user_stack(void *addr)
else /* map failed, send signal SIGSEGV */
{
#ifdef RT_USING_SIGNALS
dbg_log(DBG_ERROR, "[fault] thread %s mapped addr %p failed!\n", rt_thread_self()->name, addr);
dbg_log(DBG_ERROR, "[fault] thread %s mapped addr %p failed!\n", rt_thread_self()->parent.name, addr);
lwp_thread_kill(rt_thread_self(), SIGSEGV);
ret = 1; /* return 1, will return back to intr, then check exit */
#endif
Expand All @@ -57,7 +57,7 @@ int arch_expand_user_stack(void *addr)
else /* not stack, send signal SIGSEGV */
{
#ifdef RT_USING_SIGNALS
dbg_log(DBG_ERROR, "[fault] thread %s access unmapped addr %p!\n", rt_thread_self()->name, addr);
dbg_log(DBG_ERROR, "[fault] thread %s access unmapped addr %p!\n", rt_thread_self()->parent.name, addr);
lwp_thread_kill(rt_thread_self(), SIGSEGV);
ret = 1; /* return 1, will return back to intr, then check exit */
#endif
Expand Down
2 changes: 1 addition & 1 deletion components/lwp/lwp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ void lwp_cleanup(struct rt_thread *tid)
return;
}

LOG_I("cleanup thread: %s, stack_addr: %08X", tid->name, tid->stack_addr);
LOG_I("cleanup thread: %s, stack_addr: %08X", tid->parent.name, tid->stack_addr);

level = rt_hw_interrupt_disable();
lwp = (struct rt_lwp *)tid->lwp;
Expand Down
8 changes: 4 additions & 4 deletions components/lwp/lwp_pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,11 @@ static void print_thread_info(struct rt_thread* thread, int maxlen)

#ifdef RT_USING_SMP
if (thread->oncpu != RT_CPU_DETACHED)
rt_kprintf("%-*.*s %3d %3d ", maxlen, RT_NAME_MAX, thread->name, thread->oncpu, thread->current_priority);
rt_kprintf("%-*.*s %3d %3d ", maxlen, RT_NAME_MAX, thread->parent.name, thread->oncpu, thread->current_priority);
else
rt_kprintf("%-*.*s N/A %3d ", maxlen, RT_NAME_MAX, thread->name, thread->current_priority);
rt_kprintf("%-*.*s N/A %3d ", maxlen, RT_NAME_MAX, thread->parent.name, thread->current_priority);
#else
rt_kprintf("%-*.*s %3d ", maxlen, RT_NAME_MAX, thread->name, thread->current_priority);
rt_kprintf("%-*.*s %3d ", maxlen, RT_NAME_MAX, thread->parent.name, thread->current_priority);
#endif /*RT_USING_SMP*/

stat = (thread->stat & RT_THREAD_STAT_MASK);
Expand Down Expand Up @@ -787,7 +787,7 @@ long list_process(void)

thread = threads[index];
level = rt_hw_interrupt_disable();
if ((thread->type & ~RT_Object_Class_Static) != RT_Object_Class_Thread)
if ((thread->parent.type & ~RT_Object_Class_Static) != RT_Object_Class_Thread)
{
rt_hw_interrupt_enable(level);
continue;
Expand Down
8 changes: 4 additions & 4 deletions components/lwp/lwp_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ long _sys_clone(void *arg[])
goto fail;
}

thread = rt_thread_create(self->name,
thread = rt_thread_create(self->parent.name,
RT_NULL,
RT_NULL,
self->stack_size,
Expand Down Expand Up @@ -1710,7 +1710,7 @@ sysret_t _sys_fork(void)
/* create thread */
self_thread = rt_thread_self();

thread = rt_thread_create(self_thread->name,
thread = rt_thread_create(self_thread->parent.name,
RT_NULL,
RT_NULL,
self_thread->stack_size,
Expand Down Expand Up @@ -2358,7 +2358,7 @@ sysret_t sys_execve(const char *path, char *const argv[], char *const envp[])
/* load ok, now set thread name and swap the data of lwp and new_lwp */
level = rt_hw_interrupt_disable();

rt_strncpy(thread->name, run_name + last_backslash, RT_NAME_MAX);
rt_strncpy(thread->parent.name, run_name + last_backslash, RT_NAME_MAX);

rt_pages_free(page, 0);

Expand Down Expand Up @@ -2417,7 +2417,7 @@ rt_err_t sys_thread_delete(rt_thread_t thread)
#else
rt_err_t ret = 0;

if(thread->type != RT_Object_Class_Thread)
if(thread->parent.type != RT_Object_Class_Thread)
{
ret = -EINVAL;
goto __exit;
Expand Down
2 changes: 1 addition & 1 deletion components/net/lwip/port/sys_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ void sys_arch_unprotect(sys_prot_t pval)
void sys_arch_assert(const char *file, int line)
{
rt_kprintf("\nAssertion: %d in %s, thread %s\n",
line, file, rt_thread_self()->name);
line, file, rt_thread_self()->parent.name);
RT_ASSERT(0);
}

Expand Down
2 changes: 1 addition & 1 deletion components/utilities/ulog/syslog/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ rt_weak rt_size_t syslog_formater(char *log_buf, int level, const char *tag, rt_
/* is not in interrupt context */
if (rt_interrupt_get_nest() == 0)
{
log_len += ulog_strcpy(log_len, log_buf + log_len, rt_thread_self()->name);
log_len += ulog_strcpy(log_len, log_buf + log_len, rt_thread_self()->parent.name);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion components/utilities/ulog/ulog.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ rt_weak rt_size_t ulog_head_formater(char *log_buf, rt_uint32_t level, const cha
const char *thread_name = "N/A";
if (rt_thread_self())
{
thread_name = rt_thread_self()->name;
thread_name = rt_thread_self()->parent.name;
}
name_len = rt_strnlen(thread_name, RT_NAME_MAX);
rt_strncpy(log_buf + log_len, thread_name, name_len);
Expand Down
2 changes: 1 addition & 1 deletion components/vbus/watermark_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void rt_wm_que_dump(struct rt_watermark_queue *wg)
thread = rt_list_entry(wg->suspended_threads.next,
struct rt_thread,
tlist);
rt_kprintf(" %.*s", RT_NAME_MAX, thread->name);
rt_kprintf(" %.*s", RT_NAME_MAX, thread->parent.name);
}
rt_kprintf("\n");
}
19 changes: 1 addition & 18 deletions include/rtdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,24 +743,7 @@ struct rt_user_context
*/
struct rt_thread
{
/* rt object */
#if RT_NAME_MAX > 0
char name[RT_NAME_MAX]; /**< dynamic name of kernel object */
#else
const char *name; /**< static name of kernel object */
#endif /* RT_NAME_MAX > 0 */
rt_uint8_t type; /**< type of object */
rt_uint8_t flags; /**< thread's flags */

#ifdef RT_USING_MODULE
void *module_id; /**< id of application module */
#endif /* RT_USING_MODULE */

#ifdef RT_USING_SMART
int lwp_ref_count; /**< ref count for lwp */
#endif /* RT_USING_SMART */

rt_list_t list; /**< the object list */
struct rt_object parent;
rt_list_t tlist; /**< the thread list */

/* stack point and entry */
Expand Down
Loading