From de624c52c140f9b6e6d782025398b0c0a250d666 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 13 Jan 2019 11:23:08 +0800 Subject: [Kernel] Enable RUNNING status in thread. --- src/thread.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index df9f151834..b23d2fb6b9 100644 --- a/src/thread.c +++ b/src/thread.c @@ -655,6 +655,7 @@ RTM_EXPORT(rt_thread_control); */ rt_err_t rt_thread_suspend(rt_thread_t thread) { + register rt_base_t stat; register rt_base_t temp; /* thread check */ @@ -663,22 +664,25 @@ rt_err_t rt_thread_suspend(rt_thread_t thread) RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: %s\n", thread->name)); - if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_READY) + stat = thread->stat & RT_THREAD_STAT_MASK; + if ((stat != RT_THREAD_READY) && (stat != RT_THREAD_RUNNING)) { RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: thread disorder, 0x%2x\n", thread->stat)); - return -RT_ERROR; } - RT_ASSERT(thread == rt_thread_self()); - /* disable interrupt */ temp = rt_hw_interrupt_disable(); + if (stat == RT_THREAD_RUNNING) + { + /* not suspend running status thread on other core */ + RT_ASSERT(thread == rt_thread_self()); + } /* change thread stat */ - thread->stat = RT_THREAD_SUSPEND | (thread->stat & ~RT_THREAD_STAT_MASK); rt_schedule_remove_thread(thread); + thread->stat = RT_THREAD_SUSPEND | (thread->stat & ~RT_THREAD_STAT_MASK); /* stop thread timer anyway */ rt_timer_stop(&(thread->thread_timer)); -- cgit v1.3.1 From f9f7e6c5206c4b6573c33c4a233c1fbde2363389 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 14 Feb 2019 13:45:25 +0800 Subject: [ptherad] Fix pthread_exit issue When pthread invokes pthread_exit, it just detach self. --- components/libc/pthreads/pthread.c | 6 ------ src/thread.c | 13 ++++++------- 2 files changed, 6 insertions(+), 13 deletions(-) (limited to 'src/thread.c') diff --git a/components/libc/pthreads/pthread.c b/components/libc/pthreads/pthread.c index 8e79aceb2a..55f46c0caa 100644 --- a/components/libc/pthreads/pthread.c +++ b/components/libc/pthreads/pthread.c @@ -346,12 +346,6 @@ void pthread_exit(void *value) ptd->tls = RT_NULL; } - if (ptd->attr.detachstate == PTHREAD_CREATE_JOINABLE) - { - /* release the joinable pthread */ - rt_sem_release(ptd->joinable_sem); - } - /* detach thread */ rt_thread_detach(ptd->tid); /* reschedule thread */ diff --git a/src/thread.c b/src/thread.c index b23d2fb6b9..0f2e1dc3d0 100644 --- a/src/thread.c +++ b/src/thread.c @@ -347,17 +347,17 @@ rt_err_t rt_thread_detach(rt_thread_t thread) /* change stat */ thread->stat = RT_THREAD_CLOSE; - /* detach object */ - rt_object_detach((rt_object_t)thread); - - if (thread->cleanup != RT_NULL) + if ((rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) && + thread->cleanup == RT_NULL) + { + rt_object_detach((rt_object_t)thread); + } + else { /* disable interrupt */ lock = rt_hw_interrupt_disable(); - /* insert to defunct thread list */ rt_list_insert_after(&rt_thread_defunct, &(thread->tlist)); - /* enable interrupt */ rt_hw_interrupt_enable(lock); } @@ -366,7 +366,6 @@ rt_err_t rt_thread_detach(rt_thread_t thread) } RTM_EXPORT(rt_thread_detach); - #ifdef RT_USING_HEAP /** * This function will create a thread object and allocate thread object memory -- cgit v1.3.1 From 6cdfb2ac92d8422136f926024b2c2f969fce6b9e Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Thu, 9 May 2019 19:28:52 +0800 Subject: fix signal code --- include/rtdef.h | 3 + libcpu/arm/cortex-a/context_gcc.S | 81 ++++++------------ libcpu/arm/cortex-a/start_gcc.S | 39 +++++++-- src/scheduler.c | 84 +++++++++++++----- src/signal.c | 176 ++++++++++++++++++++++++++++++-------- src/thread.c | 2 + 6 files changed, 267 insertions(+), 118 deletions(-) (limited to 'src/thread.c') diff --git a/include/rtdef.h b/include/rtdef.h index 743b91d959..253333253a 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -495,6 +495,7 @@ typedef siginfo_t rt_siginfo_t; #define RT_THREAD_STAT_SIGNAL 0x10 #define RT_THREAD_STAT_SIGNAL_READY (RT_THREAD_STAT_SIGNAL | RT_THREAD_READY) #define RT_THREAD_STAT_SIGNAL_WAIT 0x20 +#define RT_THREAD_STAT_SIGNAL_PENDING 0x40 #define RT_THREAD_STAT_SIGNAL_MASK 0xf0 /** @@ -596,7 +597,9 @@ struct rt_thread rt_sigset_t sig_pending; /**< the pending signals */ rt_sigset_t sig_mask; /**< the mask bits of signal */ +#ifndef RT_USING_SMP void *sig_ret; /**< the return stack pointer from signal */ +#endif rt_sighandler_t *sig_vectors; /**< vectors of signal handler */ void *si_list; /**< the signal infor list */ #endif diff --git a/libcpu/arm/cortex-a/context_gcc.S b/libcpu/arm/cortex-a/context_gcc.S index af5c516e4d..dff7a1de68 100644 --- a/libcpu/arm/cortex-a/context_gcc.S +++ b/libcpu/arm/cortex-a/context_gcc.S @@ -46,16 +46,7 @@ rt_hw_context_switch_to: mov r0, r1 bl rt_cpus_lock_status_restore #endif /*RT_USING_SMP*/ - -#ifdef RT_USING_LWP - ldmfd sp, {r13, r14}^ @ pop usr_sp usr_lr - add sp, #8 -#endif - - ldmfd sp!, {r4} @ pop new task spsr - msr spsr_cxsf, r4 - - ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc + b rt_hw_context_switch_exit .section .bss.share.isr _guest_switch_lvl: @@ -93,15 +84,7 @@ rt_hw_context_switch: mov r0, r2 bl rt_cpus_lock_status_restore #endif /*RT_USING_SMP*/ - -#ifdef RT_USING_LWP - ldmfd sp, {r13, r14}^ @ pop usr_sp usr_lr - add sp, #8 -#endif - - ldmfd sp!, {r4} @ pop new task cpsr to spsr - msr spsr_cxsf, r4 - ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr + b rt_hw_context_switch_exit /* * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to); @@ -123,51 +106,19 @@ rt_hw_context_switch: .globl rt_hw_context_switch_interrupt rt_hw_context_switch_interrupt: #ifdef RT_USING_SMP - /* r0 :irq_mod context + /* r0 :svc_mod context * r1 :addr of from_thread's sp * r2 :addr of to_thread's sp * r3 :to_thread's tcb */ - @ r0 point to {r0-r3} in stack - push {r1 - r3} - mov r1, r0 - add r0, r0, #4*4 - ldmfd r0!, {r4-r12,lr}@ reload saved registers - mrs r3, spsr @ get cpsr of interrupt thread - sub r2, lr, #4 @ save old task's pc to r2 - msr cpsr_c, #I_Bit|F_Bit|Mode_SVC - - stmfd sp!, {r2} @ push old task's pc - stmfd sp!, {r4-r12,lr}@ push old task's lr,r12-r4 - ldmfd r1, {r4-r7} @ restore r0-r3 of the interrupt thread - stmfd sp!, {r4-r7} @ push old task's r0-r3 - stmfd sp!, {r3} @ push old task's cpsr - -#ifdef RT_USING_LWP - stmfd sp, {r13,r14}^ @push usr_sp usr_lr - sub sp, #8 -#endif - - msr cpsr_c, #I_Bit|F_Bit|Mode_IRQ - pop {r1 - r3} - mov sp, r0 - msr cpsr_c, #I_Bit|F_Bit|Mode_SVC - str sp, [r1] + str r0, [r1] ldr sp, [r2] mov r0, r3 bl rt_cpus_lock_status_restore -#ifdef RT_USING_LWP - ldmfd sp, {r13,r14}^ @pop usr_sp usr_lr - add sp, #8 -#endif - - ldmfd sp!, {r4} @ pop new task's cpsr to spsr - msr spsr_cxsf, r4 - - ldmfd sp!, {r0-r12,lr,pc}^ @ pop new task's r0-r12,lr & pc, copy spsr to cpsr + b rt_hw_context_switch_exit #else /*RT_USING_SMP*/ ldr r2, =rt_thread_switch_interrupt_flag @@ -183,3 +134,25 @@ _reswitch: str r1, [r2] bx lr #endif /*RT_USING_SMP*/ + +.global rt_hw_context_switch_exit +rt_hw_context_switch_exit: + +#ifdef RT_USING_SMP +#ifdef RT_USING_SIGNALS + mov r0, sp + cps #Mode_IRQ + bl rt_signal_check + cps #Mode_SVC + mov sp, r0 +#endif +#endif + +#ifdef RT_USING_LWP + ldmfd sp, {r13, r14}^ /* usr_sp, usr_lr */ + add sp, #8 +#endif + ldmfd sp!, {r1} + msr spsr_cxsf, r1 /* original mode */ + ldmfd sp!, {r0-r12,lr,pc}^ /* irq return */ + diff --git a/libcpu/arm/cortex-a/start_gcc.S b/libcpu/arm/cortex-a/start_gcc.S index 51026b7ed5..014846f3aa 100644 --- a/libcpu/arm/cortex-a/start_gcc.S +++ b/libcpu/arm/cortex-a/start_gcc.S @@ -11,7 +11,6 @@ */ #include "rtconfig.h" - .equ Mode_USR, 0x10 .equ Mode_FIQ, 0x11 .equ Mode_IRQ, 0x12 @@ -158,20 +157,48 @@ vector_fiq: vector_irq: #ifdef RT_USING_SMP clrex + + stmfd sp!, {r0, r1} + cps #Mode_SVC + mov r0, sp /* svc_sp */ + mov r1, lr /* svc_lr */ + + cps #Mode_IRQ + sub lr, #4 + stmfd r0!, {r1, lr} /* svc_lr, svc_pc */ + stmfd r0!, {r2 - r12} + ldmfd sp!, {r1, r2} /* original r0, r1 */ + stmfd r0!, {r1 - r2} + mrs r1, spsr /* original mode */ + stmfd r0!, {r1} + +#ifdef RT_USING_LWP + stmfd r0, {r13, r14}^ /* usr_sp, usr_lr */ + sub r0, #8 #endif - stmfd sp!, {r0-r12,lr} + /* now irq stack is clean */ + /* r0 is task svc_sp */ + /* backup r0 -> r8 */ + mov r8, r0 bl rt_interrupt_enter bl rt_hw_trap_irq bl rt_interrupt_leave -#ifdef RT_USING_SMP - mov r0, sp + cps #Mode_SVC + mov sp, r8 + mov r0, r8 bl rt_scheduler_do_irq_switch - ldmfd sp!, {r0-r12,lr} - subs pc, lr, #4 + b rt_hw_context_switch_exit + #else + stmfd sp!, {r0-r12,lr} + + bl rt_interrupt_enter + bl rt_hw_trap_irq + bl rt_interrupt_leave + @ if rt_thread_switch_interrupt_flag set, jump to @ rt_hw_context_switch_interrupt_do and don't return ldr r0, =rt_thread_switch_interrupt_flag diff --git a/src/scheduler.c b/src/scheduler.c index be29d9a7e0..3da723687c 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -322,8 +322,23 @@ void rt_schedule(void) if (pcpu->irq_nest) { pcpu->irq_switch_flag = 1; + rt_hw_interrupt_enable(level); + goto __exit; } - else if (current_thread->scheduler_lock_nest == 1) /* whether lock scheduler */ + +#ifdef RT_USING_SIGNALS + if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND) + { + /* if current_thread signal is in pending */ + + if ((current_thread->stat & RT_THREAD_STAT_SIGNAL_MASK) & RT_THREAD_STAT_SIGNAL_PENDING) + { + rt_thread_resume(current_thread); + } + } +#endif + + if (current_thread->scheduler_lock_nest == 1) /* whether lock scheduler */ { rt_ubase_t highest_ready_priority; @@ -366,27 +381,32 @@ void rt_schedule(void) _rt_scheduler_stack_check(to_thread); #endif - { - extern void rt_thread_handle_sig(rt_bool_t clean_state); - - rt_hw_context_switch((rt_ubase_t)¤t_thread->sp, - (rt_ubase_t)&to_thread->sp, to_thread); - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - -#ifdef RT_USING_SIGNALS - /* check signal status */ - rt_thread_handle_sig(RT_TRUE); -#endif - goto __exit; - } + rt_hw_context_switch((rt_ubase_t)¤t_thread->sp, + (rt_ubase_t)&to_thread->sp, to_thread); } } } +#ifdef RT_USING_SIGNALS + if (current_thread->stat & RT_THREAD_STAT_SIGNAL_PENDING) + { + extern void rt_thread_handle_sig(rt_bool_t clean_state); + + current_thread->stat &= ~RT_THREAD_STAT_SIGNAL_PENDING; + + rt_hw_interrupt_enable(level); + + /* check signal status */ + rt_thread_handle_sig(RT_TRUE); + } + else + { + rt_hw_interrupt_enable(level); + } +#else /* enable interrupt */ rt_hw_interrupt_enable(level); +#endif __exit: return ; @@ -465,13 +485,25 @@ void rt_schedule(void) rt_hw_context_switch((rt_ubase_t)&from_thread->sp, (rt_ubase_t)&to_thread->sp); +#ifdef RT_USING_SIGNALS + if (rt_current_thread->stat & RT_THREAD_STAT_SIGNAL_PENDING) + { + extern void rt_thread_handle_sig(rt_bool_t clean_state); + + rt_current_thread->stat &= ~RT_THREAD_STAT_SIGNAL_PENDING; + rt_hw_interrupt_enable(level); + + /* check signal status */ + rt_thread_handle_sig(RT_TRUE); + } + else + { + rt_hw_interrupt_enable(level); + } +#else /* enable interrupt */ rt_hw_interrupt_enable(level); - -#ifdef RT_USING_SIGNALS - /* check signal status */ - rt_thread_handle_sig(RT_TRUE); #endif goto __exit; } @@ -519,6 +551,18 @@ void rt_scheduler_do_irq_switch(void *context) pcpu = rt_cpu_index(cpu_id); current_thread = pcpu->current_thread; +#ifdef RT_USING_SIGNALS + if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND) + { + /* if current_thread signal is in pending */ + + if ((current_thread->stat & RT_THREAD_STAT_SIGNAL_MASK) & RT_THREAD_STAT_SIGNAL_PENDING) + { + rt_thread_resume(current_thread); + } + } +#endif + if (pcpu->irq_switch_flag == 0) { rt_hw_interrupt_enable(level); diff --git a/src/signal.c b/src/signal.c index 06c2055d26..0cab6215af 100644 --- a/src/signal.c +++ b/src/signal.c @@ -52,17 +52,27 @@ static void _signal_entry(void *parameter) /* handle signal */ rt_thread_handle_sig(RT_FALSE); - /* never come back... */ - rt_hw_interrupt_disable(); +#ifdef RT_USING_SMP + { + struct rt_cpu* pcpu = rt_cpu_self(); + + if (--pcpu->current_thread->cpus_lock_nest == 0) + { + pcpu->current_thread->scheduler_lock_nest--; + } + + } +#else /* return to thread */ tid->sp = tid->sig_ret; tid->sig_ret = RT_NULL; +#endif LOG_D("switch back to: 0x%08x\n", tid->sp); tid->stat &= ~RT_THREAD_STAT_SIGNAL; #ifdef RT_USING_SMP - rt_hw_context_switch_to((rt_ubase_t)&(tid->sp), tid); + rt_hw_context_switch_to((rt_base_t)¶meter, tid); #else rt_hw_context_switch_to((rt_ubase_t)&(tid->sp)); #endif /*RT_USING_SMP*/ @@ -82,16 +92,21 @@ static void _signal_deliver(rt_thread_t tid) { rt_ubase_t level; + level = rt_hw_interrupt_disable(); + /* thread is not interested in pended signals */ - if (!(tid->sig_pending & tid->sig_mask)) return; + if (!(tid->sig_pending & tid->sig_mask)) + { + rt_hw_interrupt_enable(level); + return; + } - level = rt_hw_interrupt_disable(); if ((tid->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND) { /* resume thread to handle signal */ rt_thread_resume(tid); /* add signal state */ - tid->stat |= RT_THREAD_STAT_SIGNAL; + tid->stat |= (RT_THREAD_STAT_SIGNAL | RT_THREAD_STAT_SIGNAL_PENDING); rt_hw_interrupt_enable(level); @@ -108,17 +123,36 @@ static void _signal_deliver(rt_thread_t tid) rt_hw_interrupt_enable(level); /* do signal action in self thread context */ - rt_thread_handle_sig(RT_TRUE); + if (rt_interrupt_get_nest() == 0) + { + rt_thread_handle_sig(RT_TRUE); + } } else if (!((tid->stat & RT_THREAD_STAT_SIGNAL_MASK) & RT_THREAD_STAT_SIGNAL)) { /* add signal state */ - tid->stat |= RT_THREAD_STAT_SIGNAL; + tid->stat |= (RT_THREAD_STAT_SIGNAL | RT_THREAD_STAT_SIGNAL_PENDING); +#ifdef RT_USING_SMP + { + int cpu_id; + + cpu_id = tid->oncpu; + if ((cpu_id != RT_CPU_DETACHED) && (cpu_id != rt_hw_cpu_id())) + { + rt_uint32_t cpu_mask; + + cpu_mask = RT_CPU_MASK ^ (1 << cpu_id); + rt_hw_ipi_send(RT_SCHEDULE_IPI, cpu_mask); + } + } +#else /* point to the signal handle entry */ + tid->stat &= ~RT_THREAD_STAT_SIGNAL_PENDING; tid->sig_ret = tid->sp; tid->sp = rt_hw_stack_init((void *)_signal_entry, RT_NULL, (void *)((char *)tid->sig_ret - 32), RT_NULL); +#endif rt_hw_interrupt_enable(level); LOG_D("signal stack pointer @ 0x%08x", tid->sp); @@ -133,14 +167,53 @@ static void _signal_deliver(rt_thread_t tid) } } +#ifdef RT_USING_SMP +void *rt_signal_check(void* context) +{ + rt_base_t level; + int cpu_id; + struct rt_cpu* pcpu; + struct rt_thread *current_thread; + + level = rt_hw_interrupt_disable(); + cpu_id = rt_hw_cpu_id(); + pcpu = rt_cpu_index(cpu_id); + current_thread = pcpu->current_thread; + + if (pcpu->irq_nest) + { + rt_hw_interrupt_enable(level); + return context; + } + + if (current_thread->cpus_lock_nest == 1) + { + if (current_thread->stat & RT_THREAD_STAT_SIGNAL_PENDING) + { + void *sig_context; + + current_thread->stat &= ~RT_THREAD_STAT_SIGNAL_PENDING; + + rt_hw_interrupt_enable(level); + sig_context = rt_hw_stack_init((void *)_signal_entry, context, + (void *)(context - 32), RT_NULL); + return sig_context; + } + } + rt_hw_interrupt_enable(level); + return context; +} +#endif + rt_sighandler_t rt_signal_install(int signo, rt_sighandler_t handler) { + rt_base_t level; rt_sighandler_t old = RT_NULL; rt_thread_t tid = rt_thread_self(); if (!sig_valid(signo)) return SIG_ERR; - rt_enter_critical(); + level = rt_hw_interrupt_disable(); if (tid->sig_vectors == RT_NULL) { rt_thread_alloc_sig(tid); @@ -154,7 +227,7 @@ rt_sighandler_t rt_signal_install(int signo, rt_sighandler_t handler) else if (handler == SIG_DFL) tid->sig_vectors[signo] = _signal_default_handler; else tid->sig_vectors[signo] = handler; } - rt_exit_critical(); + rt_hw_interrupt_enable(level); return old; } @@ -272,7 +345,20 @@ __done: LOG_D("sigwait: %d sig raised!", signo); if (si_prev) si_prev->list.next = si_node->list.next; - else tid->si_list = si_node->list.next; + else + { + struct siginfo_node *node_next; + + if (si_node->list.next) + { + node_next = (void *)rt_slist_entry(si_node->list.next, struct siginfo_node, list); + tid->si_list = node_next; + } + else + { + tid->si_list = RT_NULL; + } + } /* clear pending */ tid->sig_pending &= ~sig_mask(signo); @@ -281,7 +367,14 @@ __done: } si_prev = si_node; - si_node = (void *)rt_slist_entry(si_node->list.next, struct siginfo_node, list); + if (si_node->list.next) + { + si_node = (void *)rt_slist_entry(si_node->list.next, struct siginfo_node, list); + } + else + { + si_node = RT_NULL; + } } __done_int: @@ -320,13 +413,13 @@ void rt_thread_handle_sig(rt_bool_t clean_state) signo = si_node->si.si_signo; handler = tid->sig_vectors[signo]; + tid->sig_pending &= ~sig_mask(signo); rt_hw_interrupt_enable(level); LOG_D("handle signal: %d, handler 0x%08x", signo, handler); if (handler) handler(signo); level = rt_hw_interrupt_disable(); - tid->sig_pending &= ~sig_mask(signo); error = -RT_EINTR; rt_mp_free(si_node); /* release this siginfo node */ @@ -335,10 +428,16 @@ void rt_thread_handle_sig(rt_bool_t clean_state) } /* whether clean signal status */ - if (clean_state == RT_TRUE) tid->stat &= ~RT_THREAD_STAT_SIGNAL; + if (clean_state == RT_TRUE) + { + tid->stat &= ~RT_THREAD_STAT_SIGNAL; + } + else + { + return; + } } } - rt_hw_interrupt_enable(level); } @@ -364,30 +463,30 @@ void rt_thread_alloc_sig(rt_thread_t tid) void rt_thread_free_sig(rt_thread_t tid) { rt_base_t level; - struct siginfo_node *si_list; + struct siginfo_node *si_node; rt_sighandler_t *sig_vectors; level = rt_hw_interrupt_disable(); - si_list = (struct siginfo_node *)tid->si_list; + si_node = (struct siginfo_node *)tid->si_list; tid->si_list = RT_NULL; sig_vectors = tid->sig_vectors; tid->sig_vectors = RT_NULL; rt_hw_interrupt_enable(level); - if (si_list) + if (si_node) { struct rt_slist_node *node; - struct siginfo_node *si_node; + struct rt_slist_node *node_to_free; LOG_D("free signal info list"); - node = &(si_list->list); + node = &(si_node->list); do { - si_node = rt_slist_entry(node, struct siginfo_node, list); - rt_mp_free(si_node); - + node_to_free = node; node = node->next; + si_node = rt_slist_entry(node_to_free, struct siginfo_node, list); + rt_mp_free(si_node); } while (node); } @@ -418,30 +517,23 @@ int rt_thread_kill(rt_thread_t tid, int sig) struct rt_slist_node *node; struct siginfo_node *entry; - node = (struct rt_slist_node *)tid->si_list; - rt_hw_interrupt_enable(level); + si_node = (struct siginfo_node *)tid->si_list; + if (si_node) + node = (struct rt_slist_node *)&si_node->list; + else + node = RT_NULL; /* update sig info */ - rt_enter_critical(); for (; (node) != RT_NULL; node = node->next) { entry = rt_slist_entry(node, struct siginfo_node, list); if (entry->si.si_signo == sig) { memcpy(&(entry->si), &si, sizeof(siginfo_t)); - rt_exit_critical(); + rt_hw_interrupt_enable(level); return 0; } } - rt_exit_critical(); - - /* disable interrupt to protect tcb */ - level = rt_hw_interrupt_disable(); - } - else - { - /* a new signal */ - tid->sig_pending |= sig_mask(sig); } rt_hw_interrupt_enable(level); @@ -452,14 +544,22 @@ int rt_thread_kill(rt_thread_t tid, int sig) memcpy(&(si_node->si), &si, sizeof(siginfo_t)); level = rt_hw_interrupt_disable(); - if (!tid->si_list) tid->si_list = si_node; - else + + if (tid->si_list) { struct siginfo_node *si_list; si_list = (struct siginfo_node *)tid->si_list; rt_slist_append(&(si_list->list), &(si_node->list)); } + else + { + tid->si_list = si_node; + } + + /* a new signal */ + tid->sig_pending |= sig_mask(sig); + rt_hw_interrupt_enable(level); } else diff --git a/src/thread.c b/src/thread.c index 0f2e1dc3d0..276bba9938 100644 --- a/src/thread.c +++ b/src/thread.c @@ -191,7 +191,9 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, thread->sig_mask = 0x00; thread->sig_pending = 0x00; +#ifndef RT_USING_SMP thread->sig_ret = RT_NULL; +#endif thread->sig_vectors = RT_NULL; thread->si_list = RT_NULL; #endif -- cgit v1.3.1 From d8eb0cfc1e119b81290a460883f427a38d572617 Mon Sep 17 00:00:00 2001 From: tyustli <1225613647@qq.com> Date: Tue, 18 Jun 2019 20:09:19 +0800 Subject: fix kernel and framework no cast type error --- components/dfs/filesystems/elmfat/dfs_elm.c | 12 ++++---- components/dfs/filesystems/elmfat/ff.c | 2 +- components/dfs/src/dfs.c | 6 ++-- components/dfs/src/dfs_file.c | 4 +-- components/dfs/src/dfs_posix.c | 4 +-- components/dfs/src/poll.c | 2 +- components/drivers/audio/audio.c | 6 ++-- components/drivers/audio/audio_pipe.c | 12 ++++---- components/drivers/i2c/i2c-bit-ops.c | 12 ++++---- components/drivers/i2c/i2c_dev.c | 4 +-- components/drivers/sensors/sensor.c | 4 +-- components/drivers/sensors/sensor_cmd.c | 10 +++--- components/drivers/serial/serial.c | 12 ++++---- components/drivers/src/pipe.c | 2 +- components/drivers/src/ringblk_buf.c | 46 ++++++++++++++-------------- components/drivers/src/ringbuffer.c | 4 +-- components/drivers/usb/usbdevice/core/core.c | 8 ++--- components/finsh/shell.c | 2 +- src/ipc.c | 10 +++--- src/kservice.c | 18 ++++++----- src/thread.c | 2 +- 21 files changed, 92 insertions(+), 90 deletions(-) (limited to 'src/thread.c') diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index a45c15aa03..3825fd9108 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -202,7 +202,7 @@ int dfs_elm_mkfs(rt_device_t dev_id) int index; char logic_nbr[2] = {'0', ':'}; - work = rt_malloc(_MAX_SS); + work = (BYTE *)rt_malloc(_MAX_SS); if (RT_NULL == work) { return -ENOMEM; @@ -233,7 +233,7 @@ int dfs_elm_mkfs(rt_device_t dev_id) } else { - fat = rt_malloc(sizeof(FATFS)); + fat = (FATFS *)rt_malloc(sizeof(FATFS)); if (fat == RT_NULL) { rt_free(work); /* release memory */ @@ -340,7 +340,7 @@ int dfs_elm_open(struct dfs_fd *file) vol = elm_get_vol((FATFS *)fs->data); if (vol < 0) return -ENOENT; - drivers_fn = rt_malloc(256); + drivers_fn = (char *)rt_malloc(256); if (drivers_fn == RT_NULL) return -ENOMEM; @@ -648,7 +648,7 @@ int dfs_elm_unlink(struct dfs_filesystem *fs, const char *path) vol = elm_get_vol((FATFS *)fs->data); if (vol < 0) return -ENOENT; - drivers_fn = rt_malloc(256); + drivers_fn = (char *)rt_malloc(256); if (drivers_fn == RT_NULL) return -ENOMEM; @@ -680,7 +680,7 @@ int dfs_elm_rename(struct dfs_filesystem *fs, const char *oldpath, const char *n if (vol < 0) return -ENOENT; - drivers_oldfn = rt_malloc(256); + drivers_oldfn = (char *)rt_malloc(256); if (drivers_oldfn == RT_NULL) return -ENOMEM; drivers_newfn = newpath; @@ -714,7 +714,7 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) vol = elm_get_vol((FATFS *)fs->data); if (vol < 0) return -ENOENT; - drivers_fn = rt_malloc(256); + drivers_fn = (char *)rt_malloc(256); if (drivers_fn == RT_NULL) return -ENOMEM; diff --git a/components/dfs/filesystems/elmfat/ff.c b/components/dfs/filesystems/elmfat/ff.c index 4a2f0258b6..19df7450e2 100644 --- a/components/dfs/filesystems/elmfat/ff.c +++ b/components/dfs/filesystems/elmfat/ff.c @@ -569,7 +569,7 @@ static WCHAR LfnBuf[_MAX_LFN+1]; /* LFN enabled with static working buffer */ #define FREE_NAMBUF() ff_memfree(lfn) #else #define DEF_NAMBUF WCHAR *lfn; -#define INIT_NAMBUF(fs) { lfn = ff_memalloc((_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; } +#define INIT_NAMBUF(fs) { lfn = (WCHAR *)ff_memalloc((_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; } #define FREE_NAMBUF() ff_memfree(lfn) #endif diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 5bddb96930..32cbbf643b 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -141,7 +141,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd) cnt = fdt->maxfd + 4; cnt = cnt > DFS_FD_MAX ? DFS_FD_MAX : cnt; - fds = rt_realloc(fdt->fds, cnt * sizeof(struct dfs_fd *)); + fds = (struct dfs_fd **)rt_realloc(fdt->fds, cnt * sizeof(struct dfs_fd *)); if (fds == NULL) goto __exit; /* return fdt->maxfd */ /* clean the new allocated fds */ @@ -157,7 +157,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd) /* allocate 'struct dfs_fd' */ if (idx < (int)fdt->maxfd && fdt->fds[idx] == RT_NULL) { - fdt->fds[idx] = rt_calloc(1, sizeof(struct dfs_fd)); + fdt->fds[idx] = (struct dfs_fd *)rt_calloc(1, sizeof(struct dfs_fd)); if (fdt->fds[idx] == RT_NULL) idx = fdt->maxfd; } @@ -393,7 +393,7 @@ char *dfs_normalize_path(const char *directory, const char *filename) if (filename[0] != '/') /* it's a absolute path, use it directly */ { - fullpath = rt_malloc(strlen(directory) + strlen(filename) + 2); + fullpath = (char *)rt_malloc(strlen(directory) + strlen(filename) + 2); if (fullpath == NULL) return NULL; diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 65fd0c45e8..5f090a7f6b 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -600,7 +600,7 @@ static void copyfile(const char *src, const char *dst) rt_uint8_t *block_ptr; rt_int32_t read_bytes; - block_ptr = rt_malloc(BUF_SZ); + block_ptr = (rt_uint8_t *)rt_malloc(BUF_SZ); if (block_ptr == NULL) { rt_kprintf("out of memory\n"); @@ -715,7 +715,7 @@ static void copydir(const char *src, const char *dst) static const char *_get_path_lastname(const char *path) { char *ptr; - if ((ptr = strrchr(path, '/')) == NULL) + if ((ptr = (char *)strrchr(path, '/')) == NULL) return path; /* skip the '/' then return */ diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 6d643e2d4a..69fe56a84e 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -265,11 +265,11 @@ RTM_EXPORT(lseek); * * note: the old and new file name must be belong to a same file system. */ -int rename(const char *old, const char *new) +int rename(const char *old_file, const char *new_file) { int result; - result = dfs_file_rename(old, new); + result = dfs_file_rename(old_file, new_file); if (result < 0) { rt_set_errno(result); diff --git a/components/dfs/src/poll.c b/components/dfs/src/poll.c index aee157eed5..473b1579d2 100644 --- a/components/dfs/src/poll.c +++ b/components/dfs/src/poll.c @@ -54,7 +54,7 @@ static void _poll_add(rt_wqueue_t *wq, rt_pollreq_t *req) struct rt_poll_table *pt; struct rt_poll_node *node; - node = rt_malloc(sizeof(struct rt_poll_node)); + node = (struct rt_poll_node *)rt_malloc(sizeof(struct rt_poll_node)); if (node == RT_NULL) return; diff --git a/components/drivers/audio/audio.c b/components/drivers/audio/audio.c index 6a5ebc8741..6da0a3da91 100644 --- a/components/drivers/audio/audio.c +++ b/components/drivers/audio/audio.c @@ -157,7 +157,7 @@ static rt_err_t _audio_dev_open(struct rt_device *dev, rt_uint16_t oflag) //init pipe for record { - rt_uint8_t *buf = rt_malloc(CFG_AUDIO_RECORD_PIPE_SIZE); + rt_uint8_t *buf = (rt_uint8_t *)rt_malloc(CFG_AUDIO_RECORD_PIPE_SIZE); if (buf == RT_NULL) { @@ -382,7 +382,7 @@ static rt_err_t _audio_dev_control(struct rt_device *dev, int cmd, void *args) if (desc) { desc->data_size = AUDIO_DEVICE_DECODE_MP_BLOCK_SZ * 2; - desc->data_ptr = rt_mp_alloc(&audio->mp, RT_WAITING_FOREVER); + desc->data_ptr = (rt_uint8_t *)rt_mp_alloc(&audio->mp, RT_WAITING_FOREVER); result = RT_EOK; } @@ -440,7 +440,7 @@ rt_err_t rt_audio_register(struct rt_audio_device *audio, const char *name, rt_u //init memory pool for replay { - rt_uint8_t *mempool = rt_malloc(AUDIO_DEVICE_DECODE_MP_SZ); + rt_uint8_t *mempool = (rt_uint8_t *)rt_malloc(AUDIO_DEVICE_DECODE_MP_SZ); rt_mp_init(&audio->mp, "adu_mp", mempool, AUDIO_DEVICE_DECODE_MP_SZ, AUDIO_DEVICE_DECODE_MP_BLOCK_SZ * 2); } diff --git a/components/drivers/audio/audio_pipe.c b/components/drivers/audio/audio_pipe.c index 4df9fd8a49..d6975e962c 100644 --- a/components/drivers/audio/audio_pipe.c +++ b/components/drivers/audio/audio_pipe.c @@ -50,7 +50,7 @@ static rt_size_t rt_pipe_read(rt_device_t dev, if (!(pipe->flag & RT_PIPE_FLAG_BLOCK_RD)) { level = rt_hw_interrupt_disable(); - read_nbytes = rt_ringbuffer_get(&(pipe->ringbuffer), buffer, size); + read_nbytes = rt_ringbuffer_get(&(pipe->ringbuffer), (rt_uint8_t *)buffer, size); /* if the ringbuffer is empty, there won't be any writer waiting */ if (read_nbytes) @@ -68,7 +68,7 @@ static rt_size_t rt_pipe_read(rt_device_t dev, do { level = rt_hw_interrupt_disable(); - read_nbytes = rt_ringbuffer_get(&(pipe->ringbuffer), buffer, size); + read_nbytes = rt_ringbuffer_get(&(pipe->ringbuffer), (rt_uint8_t *)buffer, size); if (read_nbytes == 0) { rt_thread_suspend(thread); @@ -134,10 +134,10 @@ static rt_size_t rt_pipe_write(rt_device_t dev, if (pipe->flag & RT_PIPE_FLAG_FORCE_WR) write_nbytes = rt_ringbuffer_put_force(&(pipe->ringbuffer), - buffer, size); + (const rt_uint8_t *)buffer, size); else write_nbytes = rt_ringbuffer_put(&(pipe->ringbuffer), - buffer, size); + (const rt_uint8_t *)buffer, size); _rt_pipe_resume_reader(pipe); @@ -153,7 +153,7 @@ static rt_size_t rt_pipe_write(rt_device_t dev, do { level = rt_hw_interrupt_disable(); - write_nbytes = rt_ringbuffer_put(&(pipe->ringbuffer), buffer, size); + write_nbytes = rt_ringbuffer_put(&(pipe->ringbuffer), (const rt_uint8_t *)buffer, size); if (write_nbytes == 0) { /* pipe full, waiting on suspended write list */ @@ -270,7 +270,7 @@ rt_err_t rt_audio_pipe_create(const char *name, rt_int32_t flag, rt_size_t size) return -RT_ENOMEM; /* create ring buffer of pipe */ - rb_memptr = rt_malloc(size); + rb_memptr = (rt_uint8_t *)rt_malloc(size); if (rb_memptr == RT_NULL) { rt_free(pipe); diff --git a/components/drivers/i2c/i2c-bit-ops.c b/components/drivers/i2c/i2c-bit-ops.c index 26479a1d68..478cf99fd6 100644 --- a/components/drivers/i2c/i2c-bit-ops.c +++ b/components/drivers/i2c/i2c-bit-ops.c @@ -132,7 +132,7 @@ static rt_int32_t i2c_writeb(struct rt_i2c_bus_device *bus, rt_uint8_t data) rt_int32_t i; rt_uint8_t bit; - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; for (i = 7; i >= 0; i--) { @@ -159,7 +159,7 @@ static rt_int32_t i2c_readb(struct rt_i2c_bus_device *bus) { rt_uint8_t i; rt_uint8_t data = 0; - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; SDA_H(ops); i2c_delay(ops); @@ -222,7 +222,7 @@ static rt_size_t i2c_send_bytes(struct rt_i2c_bus_device *bus, static rt_err_t i2c_send_ack_or_nack(struct rt_i2c_bus_device *bus, int ack) { - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; if (ack) SET_SDA(ops, 0); @@ -282,7 +282,7 @@ static rt_int32_t i2c_send_address(struct rt_i2c_bus_device *bus, rt_uint8_t addr, rt_int32_t retries) { - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; rt_int32_t i; rt_err_t ret = 0; @@ -306,7 +306,7 @@ static rt_err_t i2c_bit_send_address(struct rt_i2c_bus_device *bus, { rt_uint16_t flags = msg->flags; rt_uint16_t ignore_nack = msg->flags & RT_I2C_IGNORE_NACK; - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; rt_uint8_t addr1, addr2; rt_int32_t retries; @@ -369,7 +369,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus, rt_uint32_t num) { struct rt_i2c_msg *msg; - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; rt_int32_t i, ret; rt_uint16_t ignore_nack; diff --git a/components/drivers/i2c/i2c_dev.c b/components/drivers/i2c/i2c_dev.c index 6c7df8e427..c784a4e4ee 100644 --- a/components/drivers/i2c/i2c_dev.c +++ b/components/drivers/i2c/i2c_dev.c @@ -28,7 +28,7 @@ static rt_size_t i2c_bus_device_read(rt_device_t dev, addr = pos & 0xffff; flags = (pos >> 16) & 0xffff; - return rt_i2c_master_recv(bus, addr, flags, buffer, count); + return rt_i2c_master_recv(bus, addr, flags, (rt_uint8_t *)buffer, count); } static rt_size_t i2c_bus_device_write(rt_device_t dev, @@ -48,7 +48,7 @@ static rt_size_t i2c_bus_device_write(rt_device_t dev, addr = pos & 0xffff; flags = (pos >> 16) & 0xffff; - return rt_i2c_master_send(bus, addr, flags, buffer, count); + return rt_i2c_master_send(bus, addr, flags, (const rt_uint8_t *)buffer, count); } static rt_err_t i2c_bus_device_control(rt_device_t dev, diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c index d689988fdd..451d2745f1 100644 --- a/components/drivers/sensors/sensor.c +++ b/components/drivers/sensors/sensor.c @@ -69,7 +69,7 @@ void rt_sensor_cb(rt_sensor_t sen) /* ISR for sensor interrupt */ static void irq_callback(void *args) { - rt_sensor_t sensor = args; + rt_sensor_t sensor = (rt_sensor_t)args; rt_uint8_t i; if (sensor->module) @@ -389,7 +389,7 @@ int rt_hw_sensor_register(rt_sensor_t sensor, /* Add a type name for the sensor device */ sensor_name = sensor_name_str[sensor->info.type]; - device_name = rt_calloc(1, rt_strlen(sensor_name) + 1 + rt_strlen(name)); + device_name = (char *)rt_calloc(1, rt_strlen(sensor_name) + 1 + rt_strlen(name)); if (device_name == RT_NULL) { LOG_E("device_name calloc failed!"); diff --git a/components/drivers/sensors/sensor_cmd.c b/components/drivers/sensors/sensor_cmd.c index 245279020e..ea9e56a3d3 100755 --- a/components/drivers/sensors/sensor_cmd.c +++ b/components/drivers/sensors/sensor_cmd.c @@ -63,15 +63,15 @@ static rt_err_t rx_callback(rt_device_t dev, rt_size_t size) static void sensor_fifo_rx_entry(void *parameter) { - rt_device_t dev = parameter; - rt_sensor_t sensor = parameter; + rt_device_t dev = (rt_device_t)parameter; + rt_sensor_t sensor = (rt_sensor_t)parameter; struct rt_sensor_data *data = RT_NULL; struct rt_sensor_info info; rt_size_t res, i; rt_device_control(dev, RT_SENSOR_CTRL_GET_INFO, &info); - data = rt_malloc(sizeof(struct rt_sensor_data) * info.fifo_max); + data = (struct rt_sensor_data *)rt_malloc(sizeof(struct rt_sensor_data) * info.fifo_max); if (data == RT_NULL) { LOG_E("Memory allocation failed!"); @@ -137,8 +137,8 @@ MSH_CMD_EXPORT(sensor_fifo, Sensor fifo mode test function); static void sensor_irq_rx_entry(void *parameter) { - rt_device_t dev = parameter; - rt_sensor_t sensor = parameter; + rt_device_t dev = (rt_device_t)parameter; + rt_sensor_t sensor = (rt_sensor_t)parameter; struct rt_sensor_data data; rt_size_t res, i = 0; diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index c3e96fc77b..04034e8c44 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -791,16 +791,16 @@ static rt_size_t rt_serial_read(struct rt_device *dev, if (dev->open_flag & RT_DEVICE_FLAG_INT_RX) { - return _serial_int_rx(serial, buffer, size); + return _serial_int_rx(serial, (rt_uint8_t *)buffer, size); } #ifdef RT_SERIAL_USING_DMA else if (dev->open_flag & RT_DEVICE_FLAG_DMA_RX) { - return _serial_dma_rx(serial, buffer, size); + return _serial_dma_rx(serial, (rt_uint8_t *)buffer, size); } #endif /* RT_SERIAL_USING_DMA */ - return _serial_poll_rx(serial, buffer, size); + return _serial_poll_rx(serial, (rt_uint8_t *)buffer, size); } static rt_size_t rt_serial_write(struct rt_device *dev, @@ -817,17 +817,17 @@ static rt_size_t rt_serial_write(struct rt_device *dev, if (dev->open_flag & RT_DEVICE_FLAG_INT_TX) { - return _serial_int_tx(serial, buffer, size); + return _serial_int_tx(serial, (const rt_uint8_t *)buffer, size); } #ifdef RT_SERIAL_USING_DMA else if (dev->open_flag & RT_DEVICE_FLAG_DMA_TX) { - return _serial_dma_tx(serial, buffer, size); + return _serial_dma_tx(serial, (const rt_uint8_t *)buffer, size); } #endif /* RT_SERIAL_USING_DMA */ else { - return _serial_poll_tx(serial, buffer, size); + return _serial_poll_tx(serial, (const rt_uint8_t *)buffer, size); } } diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c index 16fb82dbfb..b682c351ad 100644 --- a/components/drivers/src/pipe.c +++ b/components/drivers/src/pipe.c @@ -425,7 +425,7 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz) rt_pipe_t *pipe; rt_device_t dev; - pipe = rt_malloc(sizeof(rt_pipe_t)); + pipe = (rt_pipe_t *)rt_malloc(sizeof(rt_pipe_t)); if (pipe == RT_NULL) return RT_NULL; rt_memset(pipe, 0, sizeof(rt_pipe_t)); diff --git a/components/drivers/src/ringblk_buf.c b/components/drivers/src/ringblk_buf.c index 74ced674fe..86e812cd4c 100644 --- a/components/drivers/src/ringblk_buf.c +++ b/components/drivers/src/ringblk_buf.c @@ -134,16 +134,16 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size) { rt_base_t level; rt_size_t empty1 = 0, empty2 = 0; - rt_rbb_blk_t head, tail, new = NULL; + rt_rbb_blk_t head, tail, new_rbb = NULL; RT_ASSERT(rbb); RT_ASSERT(blk_size < (1L << 24)); level = rt_hw_interrupt_disable(); - new = find_empty_blk_in_set(rbb); + new_rbb = find_empty_blk_in_set(rbb); - if (rt_slist_len(&rbb->blk_list) < rbb->blk_max_num && new) + if (rt_slist_len(&rbb->blk_list) < rbb->blk_max_num && new_rbb) { if (rt_slist_len(&rbb->blk_list) > 0) { @@ -163,22 +163,22 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size) if (empty1 >= blk_size) { - rt_slist_append(&rbb->blk_list, &new->list); - new->status = RT_RBB_BLK_INITED; - new->buf = tail->buf + tail->size; - new->size = blk_size; + rt_slist_append(&rbb->blk_list, &new_rbb->list); + new_rbb->status = RT_RBB_BLK_INITED; + new_rbb->buf = tail->buf + tail->size; + new_rbb->size = blk_size; } else if (empty2 >= blk_size) { - rt_slist_append(&rbb->blk_list, &new->list); - new->status = RT_RBB_BLK_INITED; - new->buf = rbb->buf; - new->size = blk_size; + rt_slist_append(&rbb->blk_list, &new_rbb->list); + new_rbb->status = RT_RBB_BLK_INITED; + new_rbb->buf = rbb->buf; + new_rbb->size = blk_size; } else { /* no space */ - new = NULL; + new_rbb = NULL; } } else @@ -194,35 +194,35 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size) if (empty1 >= blk_size) { - rt_slist_append(&rbb->blk_list, &new->list); - new->status = RT_RBB_BLK_INITED; - new->buf = tail->buf + tail->size; - new->size = blk_size; + rt_slist_append(&rbb->blk_list, &new_rbb->list); + new_rbb->status = RT_RBB_BLK_INITED; + new_rbb->buf = tail->buf + tail->size; + new_rbb->size = blk_size; } else { /* no space */ - new = NULL; + new_rbb = NULL; } } } else { /* the list is empty */ - rt_slist_append(&rbb->blk_list, &new->list); - new->status = RT_RBB_BLK_INITED; - new->buf = rbb->buf; - new->size = blk_size; + rt_slist_append(&rbb->blk_list, &new_rbb->list); + new_rbb->status = RT_RBB_BLK_INITED; + new_rbb->buf = rbb->buf; + new_rbb->size = blk_size; } } else { - new = NULL; + new_rbb = NULL; } rt_hw_interrupt_enable(level); - return new; + return new_rbb; } RTM_EXPORT(rt_rbb_blk_alloc); diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index 0acdbbd38c..c6a491a7cc 100644 --- a/components/drivers/src/ringbuffer.c +++ b/components/drivers/src/ringbuffer.c @@ -332,11 +332,11 @@ struct rt_ringbuffer* rt_ringbuffer_create(rt_uint16_t size) size = RT_ALIGN_DOWN(size, RT_ALIGN_SIZE); - rb = rt_malloc(sizeof(struct rt_ringbuffer)); + rb = (struct rt_ringbuffer *)rt_malloc(sizeof(struct rt_ringbuffer)); if (rb == RT_NULL) goto exit; - pool = rt_malloc(size); + pool = (rt_uint8_t *)rt_malloc(size); if (pool == RT_NULL) { rt_free(rb); diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/core.c index 4e3a3e9280..ae0704585f 100644 --- a/components/drivers/usb/usbdevice/core/core.c +++ b/components/drivers/usb/usbdevice/core/core.c @@ -995,7 +995,7 @@ udevice_t rt_usbd_device_new(void) RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbd_device_new\n")); /* allocate memory for the object */ - udevice = rt_malloc(sizeof(struct udevice)); + udevice = (udevice_t)rt_malloc(sizeof(struct udevice)); if(udevice == RT_NULL) { rt_kprintf("alloc memery failed\n"); @@ -1109,7 +1109,7 @@ uconfig_t rt_usbd_config_new(void) RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbd_config_new\n")); /* allocate memory for the object */ - cfg = rt_malloc(sizeof(struct uconfig)); + cfg = (uconfig_t)rt_malloc(sizeof(struct uconfig)); if(cfg == RT_NULL) { rt_kprintf("alloc memery failed\n"); @@ -2053,7 +2053,7 @@ rt_size_t rt_usbd_ep0_write(udevice_t device, void *buffer, rt_size_t size) ep0 = &device->dcd->ep0; ep0->request.size = size; - ep0->request.buffer = buffer; + ep0->request.buffer = (rt_uint8_t *)buffer; ep0->request.remain_size = size; if(size >= ep0->id->maxpacket) { @@ -2079,7 +2079,7 @@ rt_size_t rt_usbd_ep0_read(udevice_t device, void *buffer, rt_size_t size, RT_ASSERT(buffer != RT_NULL); ep0 = &device->dcd->ep0; - ep0->request.buffer = buffer; + ep0->request.buffer = (rt_uint8_t *)buffer; ep0->request.remain_size = size; ep0->rx_indicate = rx_ind; if(size >= ep0->id->maxpacket) diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 3a02e24c2e..1505e071c5 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -56,7 +56,7 @@ int finsh_set_prompt(const char * prompt) /* strdup */ if(prompt) { - finsh_prompt_custom = rt_malloc(strlen(prompt)+1); + finsh_prompt_custom = (char *)rt_malloc(strlen(prompt)+1); if(finsh_prompt_custom) { strcpy(finsh_prompt_custom, prompt); diff --git a/src/ipc.c b/src/ipc.c index 0df4f05f23..e293eee8cd 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1308,7 +1308,7 @@ rt_err_t rt_mb_init(rt_mailbox_t mb, rt_ipc_object_init(&(mb->parent)); /* init mailbox */ - mb->msg_pool = msgpool; + mb->msg_pool = (rt_ubase_t *)msgpool; mb->size = size; mb->entry = 0; mb->in_offset = 0; @@ -1376,7 +1376,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag) /* init mailbox */ mb->size = size; - mb->msg_pool = RT_KERNEL_MALLOC(mb->size * sizeof(rt_ubase_t)); + mb->msg_pool = (rt_ubase_t *)RT_KERNEL_MALLOC(mb->size * sizeof(rt_ubase_t)); if (mb->msg_pool == RT_NULL) { /* delete mailbox object */ @@ -1816,7 +1816,7 @@ rt_err_t rt_mq_init(rt_mq_t mq, { head = (struct rt_mq_message *)((rt_uint8_t *)mq->msg_pool + temp * (mq->msg_size + sizeof(struct rt_mq_message))); - head->next = mq->msg_queue_free; + head->next = (struct rt_mq_message *)mq->msg_queue_free; mq->msg_queue_free = head; } @@ -1909,7 +1909,7 @@ rt_mq_t rt_mq_create(const char *name, { head = (struct rt_mq_message *)((rt_uint8_t *)mq->msg_pool + temp * (mq->msg_size + sizeof(struct rt_mq_message))); - head->next = mq->msg_queue_free; + head->next = (struct rt_mq_message *)mq->msg_queue_free; mq->msg_queue_free = head; } @@ -2093,7 +2093,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, void *buffer, rt_size_t size) temp = rt_hw_interrupt_disable(); /* link msg to the beginning of message queue */ - msg->next = mq->msg_queue_head; + msg->next = (struct rt_mq_message *)mq->msg_queue_head; mq->msg_queue_head = msg; /* if there is no tail */ diff --git a/src/kservice.c b/src/kservice.c index 322fb61e28..202bd97f83 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -326,7 +326,7 @@ rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count) const unsigned char *su1, *su2; int res = 0; - for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) + for (su1 = (const unsigned char *)cs, su2 = (const unsigned char *)ct; 0 < count; ++su1, ++su2, count--) if ((res = *su1 - *su2) != 0) break; @@ -1117,14 +1117,14 @@ RTM_EXPORT(rt_console_get_device); */ rt_device_t rt_console_set_device(const char *name) { - rt_device_t new, old; + rt_device_t new_device, old_device; /* save old device */ - old = _console_device; + old_device = _console_device; /* find new console device */ - new = rt_device_find(name); - if (new != RT_NULL) + new_device = rt_device_find(name); + if (new_device != RT_NULL) { if (_console_device != RT_NULL) { @@ -1133,11 +1133,11 @@ rt_device_t rt_console_set_device(const char *name) } /* set new console device */ - rt_device_open(new, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM); - _console_device = new; + rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM); + _console_device = new_device; } - return old; + return old_device; } RTM_EXPORT(rt_console_set_device); #endif @@ -1332,7 +1332,9 @@ int __rt_ffs(int value) #ifdef RT_DEBUG /* RT_ASSERT(EX)'s hook */ + void (*rt_assert_hook)(const char *ex, const char *func, rt_size_t line); + /** * This function will set a hook function to RT_ASSERT(EX). It will run when the expression is false. * diff --git a/src/thread.c b/src/thread.c index 276bba9938..ab203b1d49 100644 --- a/src/thread.c +++ b/src/thread.c @@ -141,7 +141,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, (void *)rt_thread_exit); #else thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, - (void *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)), + (rt_uint8_t *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)), (void *)rt_thread_exit); #endif -- cgit v1.3.1 From cb07e5fb24afebdf233847da551d3ede80727345 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Thu, 26 Sep 2019 18:13:07 +0800 Subject: 开放spinlock相关函数 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtdef.h | 1 + include/rthw.h | 14 +++++ libcpu/arm/cortex-a/cpu.c | 6 +++ libcpu/risc-v/k210/cpuport_smp.c | 5 ++ src/cpu.c | 113 +++++++++++++++++++++++++++++++++++++++ src/scheduler.c | 11 ++-- src/thread.c | 1 + 7 files changed, 148 insertions(+), 3 deletions(-) (limited to 'src/thread.c') diff --git a/include/rtdef.h b/include/rtdef.h index b25a6a87d5..3dc8a2a2a9 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -577,6 +577,7 @@ struct rt_thread rt_uint16_t scheduler_lock_nest; /**< scheduler lock count */ rt_uint16_t cpus_lock_nest; /**< cpus lock count */ + rt_uint16_t critical_lock_nest; /**< critical lock count */ #endif /*RT_USING_SMP*/ /* priority */ diff --git a/include/rthw.h b/include/rthw.h index ef3dc087ad..a77f2c1e46 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -143,6 +143,12 @@ typedef union { } tickets; } rt_hw_spinlock_t; +typedef struct +{ + rt_hw_spinlock_t lock; +} rt_spinlock_t; + +void rt_hw_spin_lock_init(rt_hw_spinlock_t *lock); void rt_hw_spin_lock(rt_hw_spinlock_t *lock); void rt_hw_spin_unlock(rt_hw_spinlock_t *lock); @@ -181,8 +187,16 @@ void rt_hw_secondary_cpu_idle_exec(void); #define rt_hw_spin_lock(lock) *(lock) = rt_hw_interrupt_disable() #define rt_hw_spin_unlock(lock) rt_hw_interrupt_enable(*(lock)) +typedef int rt_spinlock_t; + #endif +void rt_spin_lock_init(rt_spinlock_t *lock); +void rt_spin_lock(rt_spinlock_t *lock); +void rt_spin_unlock(rt_spinlock_t *lock); +rt_base_t rt_spin_lock_irqsave(rt_spinlock_t *lock); +void rt_spin_unlock_irqrestore(rt_spinlock_t *lock, rt_base_t level); + #ifdef __cplusplus } #endif diff --git a/libcpu/arm/cortex-a/cpu.c b/libcpu/arm/cortex-a/cpu.c index 6b129f89ee..7c6bf58a4b 100644 --- a/libcpu/arm/cortex-a/cpu.c +++ b/libcpu/arm/cortex-a/cpu.c @@ -14,6 +14,7 @@ #include #ifdef RT_USING_SMP + int rt_hw_cpu_id(void) { int cpu_id; @@ -25,6 +26,11 @@ int rt_hw_cpu_id(void) return cpu_id; }; +void rt_hw_spin_lock_init(rt_hw_spinlock_t *lock) +{ + lock->slock = 0; +} + void rt_hw_spin_lock(rt_hw_spinlock_t *lock) { unsigned long tmp; diff --git a/libcpu/risc-v/k210/cpuport_smp.c b/libcpu/risc-v/k210/cpuport_smp.c index a31314a13f..8c57dfeafc 100644 --- a/libcpu/risc-v/k210/cpuport_smp.c +++ b/libcpu/risc-v/k210/cpuport_smp.c @@ -25,6 +25,11 @@ int rt_hw_cpu_id(void) return read_csr(mhartid); } +void rt_hw_spin_lock_init(rt_hw_spinlock_t *lock) +{ + ((spinlock_t *)lock)->lock = 0; +} + void rt_hw_spin_lock(rt_hw_spinlock_t *lock) { spinlock_lock((spinlock_t *)lock); diff --git a/src/cpu.c b/src/cpu.c index fe3ba21bb0..a4075108e1 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -11,6 +11,119 @@ #include #include +#ifdef RT_USING_SMP +/*********************************** + * disable scheduler + ***********************************/ +static void rt_preempt_disable(void) +{ + register rt_base_t level; + struct rt_thread *current_thread; + + /* disable interrupt */ + level = rt_hw_local_irq_disable(); + + current_thread = rt_cpu_self()->current_thread; + if (!current_thread) + { + rt_hw_local_irq_enable(level); + return; + } + + /* lock scheduler for local cpu */ + current_thread->scheduler_lock_nest ++; + + /* enable interrupt */ + rt_hw_local_irq_enable(level); +} + +/*********************************** + * restore scheduler + ***********************************/ +static void rt_preempt_enable(void) +{ + register rt_base_t level; + struct rt_thread *current_thread; + + /* disable interrupt */ + level = rt_hw_local_irq_disable(); + + current_thread = rt_cpu_self()->current_thread; + if (!current_thread) + { + rt_hw_local_irq_enable(level); + return; + } + + /* unlock scheduler for local cpu */ + current_thread->scheduler_lock_nest --; + + rt_schedule(); + /* enable interrupt */ + rt_hw_local_irq_enable(level); +} +#endif + +void rt_spin_lock_init(rt_spinlock_t *lock) +{ +#ifdef RT_USING_SMP + rt_hw_spin_lock_init(&lock->lock); +#endif +} +RTM_EXPORT(rt_spin_lock_init) + +void rt_spin_lock(rt_spinlock_t *lock) +{ +#ifdef RT_USING_SMP + rt_preempt_disable(); + rt_hw_spin_lock(&lock->lock); +#else + rt_enter_critical(); +#endif +} +RTM_EXPORT(rt_spin_lock) + +void rt_spin_unlock(rt_spinlock_t *lock) +{ +#ifdef RT_USING_SMP + rt_hw_spin_unlock(&lock->lock); + rt_preempt_enable(); +#else + rt_exit_critical(); +#endif +} +RTM_EXPORT(rt_spin_unlock) + +rt_base_t rt_spin_lock_irqsave(rt_spinlock_t *lock) +{ + unsigned long level; + +#ifdef RT_USING_SMP + rt_preempt_disable(); + + level = rt_hw_local_irq_disable(); + rt_hw_spin_lock(&lock->lock); + + return level; +#else + return rt_hw_interrupt_disable(); +#endif +} +RTM_EXPORT(rt_spin_lock_irqsave) + +void rt_spin_unlock_irqrestore(rt_spinlock_t *lock, rt_base_t level) +{ +#ifdef RT_USING_SMP + rt_hw_spin_unlock(&lock->lock); + rt_hw_local_irq_enable(level); + + rt_preempt_enable(); +#else + rt_hw_interrupt_enable(level); +#endif +} +RTM_EXPORT(rt_spin_unlock_irqrestore) + #ifdef RT_USING_SMP static struct rt_cpu rt_cpus[RT_CPUS_NR]; diff --git a/src/scheduler.c b/src/scheduler.c index b487bd4b60..0faafaa2fc 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -840,11 +840,14 @@ void rt_enter_critical(void) */ /* lock scheduler for all cpus */ - if (current_thread->scheduler_lock_nest == !!current_thread->cpus_lock_nest) + if (current_thread->critical_lock_nest == 0) { rt_hw_spin_lock(&_rt_critical_lock); } + /* critical for local cpu */ + current_thread->critical_lock_nest ++; + /* lock scheduler for local cpu */ current_thread->scheduler_lock_nest ++; @@ -892,7 +895,9 @@ void rt_exit_critical(void) current_thread->scheduler_lock_nest --; - if (current_thread->scheduler_lock_nest == !!current_thread->cpus_lock_nest) + current_thread->critical_lock_nest --; + + if (current_thread->critical_lock_nest == 0) { rt_hw_spin_unlock(&_rt_critical_lock); } @@ -951,7 +956,7 @@ rt_uint16_t rt_critical_level(void) #ifdef RT_USING_SMP struct rt_thread *current_thread = rt_cpu_self()->current_thread; - return current_thread->scheduler_lock_nest; + return current_thread->critical_lock_nest; #else return rt_scheduler_lock_nest; #endif /*RT_USING_SMP*/ diff --git a/src/thread.c b/src/thread.c index ab203b1d49..a88729e52c 100644 --- a/src/thread.c +++ b/src/thread.c @@ -172,6 +172,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, /* lock init */ thread->scheduler_lock_nest = 0; thread->cpus_lock_nest = 0; + thread->critical_lock_nest = 0; #endif /*RT_USING_SMP*/ /* initialize cleanup function and user data */ -- cgit v1.3.1 From cdaf8c65cabd0120e6d19453cfffe905e9b6a769 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Tue, 12 Nov 2019 16:02:24 +0800 Subject: 修正rt_thread_delete在特定点被切走后不能回来继续执行的问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thread.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index a88729e52c..bee5f0c2c0 100644 --- a/src/thread.c +++ b/src/thread.c @@ -446,12 +446,12 @@ rt_err_t rt_thread_delete(rt_thread_t thread) /* release thread timer */ rt_timer_detach(&(thread->thread_timer)); - /* change stat */ - thread->stat = RT_THREAD_CLOSE; - /* disable interrupt */ lock = rt_hw_interrupt_disable(); + /* change stat */ + thread->stat = RT_THREAD_CLOSE; + /* insert to defunct thread list */ rt_list_insert_after(&rt_thread_defunct, &(thread->tlist)); -- cgit v1.3.1 From 88b552276b1b64750f3db460b36f8e329f1c18c4 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Fri, 15 Nov 2019 10:45:12 +0800 Subject: 修正在多核时,运行在另外核上的idle任务有可能会插在rt_thread_exit调用rt_schedule之前释放其资源的问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thread.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index bee5f0c2c0..c5f75a1176 100644 --- a/src/thread.c +++ b/src/thread.c @@ -107,11 +107,11 @@ void rt_thread_exit(void) rt_list_insert_after(&rt_thread_defunct, &(thread->tlist)); } - /* enable interrupt */ - rt_hw_interrupt_enable(level); - /* switch to next task */ rt_schedule(); + + /* enable interrupt */ + rt_hw_interrupt_enable(level); } static rt_err_t _rt_thread_init(struct rt_thread *thread, -- cgit v1.3.1 From 992d3af3aee1e8567080e33e27011170f60dfab9 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Mon, 16 Dec 2019 13:59:46 +0800 Subject: [kernel] code and comments cleanup --- include/libc/libc_signal.h | 6 +-- include/rtdef.h | 2 +- include/rthw.h | 2 +- src/clock.c | 2 +- src/device.c | 16 ++++---- src/ipc.c | 94 +++++++++++++++++++++++----------------------- src/kservice.c | 2 +- src/signal.c | 4 +- src/thread.c | 6 +-- 9 files changed, 67 insertions(+), 67 deletions(-) (limited to 'src/thread.c') diff --git a/include/libc/libc_signal.h b/include/libc/libc_signal.h index 71f8de125d..c77f36798c 100644 --- a/include/libc/libc_signal.h +++ b/include/libc/libc_signal.h @@ -24,7 +24,7 @@ extern "C" { NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and sigev_notify_attributes to the sigevent structure. */ -union sigval +union sigval { int sival_int; /* Integer signal value */ void *sival_ptr; /* Pointer signal value */ @@ -107,7 +107,7 @@ typedef unsigned long sigset_t; typedef void (*_sig_func_ptr)(int); -struct sigaction +struct sigaction { _sig_func_ptr sa_handler; sigset_t sa_mask; @@ -163,7 +163,7 @@ typedef unsigned long sigset_t; typedef void (*_sig_func_ptr)(int); -struct sigaction +struct sigaction { _sig_func_ptr sa_handler; sigset_t sa_mask; diff --git a/include/rtdef.h b/include/rtdef.h index 3f0b116785..b3aa38d3af 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -522,7 +522,7 @@ typedef siginfo_t rt_siginfo_t; /** * CPUs definitions - * + * */ struct rt_cpu { diff --git a/include/rthw.h b/include/rthw.h index 2a602dcfe7..89877faf90 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -37,7 +37,7 @@ extern "C" { #endif #ifndef RT_CPU_CACHE_LINE_SZ -#define RT_CPU_CACHE_LINE_SZ 32 +#define RT_CPU_CACHE_LINE_SZ 32 #endif enum RT_HW_CACHE_OPS diff --git a/src/clock.c b/src/clock.c index 9b54101363..97a09ddeaf 100644 --- a/src/clock.c +++ b/src/clock.c @@ -25,7 +25,7 @@ static rt_tick_t rt_tick = 0; #endif /** - * This function will init system tick and set it to zero. + * This function will initialize system tick and set it to zero. * @ingroup SystemInit * * @deprecated since 1.1.0, this function does not need to be invoked diff --git a/src/device.c b/src/device.c index 51fc6176a6..32c06b380c 100644 --- a/src/device.c +++ b/src/device.c @@ -95,7 +95,7 @@ RTM_EXPORT(rt_device_unregister); * @return the error code, RT_EOK on successfully. * * @deprecated since 1.2.x, this function is not needed because the initialization - * of a device is performed when applicaiton opens it. + * of a device is performed when application opens it. */ rt_err_t rt_device_init_all(void) { @@ -162,7 +162,7 @@ rt_device_t rt_device_create(int type, int attach_size) size = RT_ALIGN(sizeof(struct rt_device), RT_ALIGN_SIZE); attach_size = RT_ALIGN(attach_size, RT_ALIGN_SIZE); - /* use the totoal size */ + /* use the total size */ size += attach_size; device = (rt_device_t)rt_malloc(size); @@ -208,7 +208,7 @@ rt_err_t rt_device_init(rt_device_t dev) RT_ASSERT(dev != RT_NULL); - /* get device init handler */ + /* get device_init handler */ if (device_init != RT_NULL) { if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED)) @@ -269,7 +269,7 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag) return -RT_EBUSY; } - /* call device open interface */ + /* call device_open interface */ if (device_open != RT_NULL) { result = device_open(dev, oflag); @@ -317,7 +317,7 @@ rt_err_t rt_device_close(rt_device_t dev) if (dev->ref_count != 0) return RT_EOK; - /* call device close interface */ + /* call device_close interface */ if (device_close != RT_NULL) { result = device_close(dev); @@ -357,7 +357,7 @@ rt_size_t rt_device_read(rt_device_t dev, return 0; } - /* call device read interface */ + /* call device_read interface */ if (device_read != RT_NULL) { return device_read(dev, pos, buffer, size); @@ -396,7 +396,7 @@ rt_size_t rt_device_write(rt_device_t dev, return 0; } - /* call device write interface */ + /* call device_write interface */ if (device_write != RT_NULL) { return device_write(dev, pos, buffer, size); @@ -423,7 +423,7 @@ rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg) RT_ASSERT(dev != RT_NULL); RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); - /* call device write interface */ + /* call device_write interface */ if (device_control != RT_NULL) { return device_control(dev, cmd, arg); diff --git a/src/ipc.c b/src/ipc.c index 6a8234a747..e6955bae37 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -60,7 +60,7 @@ extern void (*rt_object_put_hook)(struct rt_object *object); */ rt_inline rt_err_t rt_ipc_object_init(struct rt_ipc_object *ipc) { - /* init ipc object */ + /* initialize ipc object */ rt_list_init(&(ipc->suspend_thread)); return RT_EOK; @@ -159,13 +159,13 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list) struct rt_thread *thread; register rt_ubase_t temp; - /* wakeup all suspend threads */ + /* wakeup all suspended threads */ while (!rt_list_isempty(list)) { /* disable interrupt */ temp = rt_hw_interrupt_disable(); - /* get next suspend thread */ + /* get next suspended thread */ thread = rt_list_entry(list->next, struct rt_thread, tlist); /* set error code to RT_ERROR */ thread->error = -RT_ERROR; @@ -173,7 +173,7 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list) /* * resume thread * In rt_thread_resume function, it will remove current thread from - * suspend list + * suspended list */ rt_thread_resume(thread); @@ -191,7 +191,7 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list) * * @param sem the semaphore object * @param name the name of semaphore - * @param value the init value of semaphore + * @param value the initial value of semaphore * @param flag the flag of semaphore * * @return the operation status, RT_EOK on successful @@ -204,13 +204,13 @@ rt_err_t rt_sem_init(rt_sem_t sem, RT_ASSERT(sem != RT_NULL); RT_ASSERT(value < 0x10000U); - /* init object */ + /* initialize object */ rt_object_init(&(sem->parent.parent), RT_Object_Class_Semaphore, name); - /* init ipc object */ + /* initialize ipc object */ rt_ipc_object_init(&(sem->parent)); - /* set init value */ + /* set initial value */ sem->value = (rt_uint16_t)value; /* set parent */ @@ -236,7 +236,7 @@ rt_err_t rt_sem_detach(rt_sem_t sem) RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore); RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent)); - /* wakeup all suspend threads */ + /* wakeup all suspended threads */ rt_ipc_list_resume_all(&(sem->parent.suspend_thread)); /* detach semaphore object */ @@ -251,7 +251,7 @@ RTM_EXPORT(rt_sem_detach); * This function will create a semaphore from system resource * * @param name the name of semaphore - * @param value the init value of semaphore + * @param value the initial value of semaphore * @param flag the flag of semaphore * * @return the created semaphore, RT_NULL on error happen @@ -270,10 +270,10 @@ rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag) if (sem == RT_NULL) return sem; - /* init ipc object */ + /* initialize ipc object */ rt_ipc_object_init(&(sem->parent)); - /* set init value */ + /* set initial value */ sem->value = value; /* set parent */ @@ -301,7 +301,7 @@ rt_err_t rt_sem_delete(rt_sem_t sem) RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore); RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent) == RT_FALSE); - /* wakeup all suspend threads */ + /* wakeup all suspended threads */ rt_ipc_list_resume_all(&(sem->parent.suspend_thread)); /* delete semaphore object */ @@ -532,10 +532,10 @@ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag) /* parameter check */ RT_ASSERT(mutex != RT_NULL); - /* init object */ + /* initialize object */ rt_object_init(&(mutex->parent.parent), RT_Object_Class_Mutex, name); - /* init ipc object */ + /* initialize ipc object */ rt_ipc_object_init(&(mutex->parent)); mutex->value = 1; @@ -566,10 +566,10 @@ rt_err_t rt_mutex_detach(rt_mutex_t mutex) RT_ASSERT(rt_object_get_type(&mutex->parent.parent) == RT_Object_Class_Mutex); RT_ASSERT(rt_object_is_systemobject(&mutex->parent.parent)); - /* wakeup all suspend threads */ + /* wakeup all suspended threads */ rt_ipc_list_resume_all(&(mutex->parent.suspend_thread)); - /* detach mutex object */ + /* detach semaphore object */ rt_object_detach(&(mutex->parent.parent)); return RT_EOK; @@ -598,7 +598,7 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) if (mutex == RT_NULL) return mutex; - /* init ipc object */ + /* initialize ipc object */ rt_ipc_object_init(&(mutex->parent)); mutex->value = 1; @@ -631,7 +631,7 @@ rt_err_t rt_mutex_delete(rt_mutex_t mutex) RT_ASSERT(rt_object_get_type(&mutex->parent.parent) == RT_Object_Class_Mutex); RT_ASSERT(rt_object_is_systemobject(&mutex->parent.parent) == RT_FALSE); - /* wakeup all suspend threads */ + /* wakeup all suspended threads */ rt_ipc_list_resume_all(&(mutex->parent.suspend_thread)); /* delete mutex object */ @@ -917,16 +917,16 @@ rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag) /* parameter check */ RT_ASSERT(event != RT_NULL); - /* init object */ + /* initialize object */ rt_object_init(&(event->parent.parent), RT_Object_Class_Event, name); /* set parent flag */ event->parent.parent.flag = flag; - /* init ipc object */ + /* initialize ipc object */ rt_ipc_object_init(&(event->parent)); - /* init event */ + /* initialize event */ event->set = 0; return RT_EOK; @@ -980,10 +980,10 @@ rt_event_t rt_event_create(const char *name, rt_uint8_t flag) /* set parent */ event->parent.parent.flag = flag; - /* init ipc object */ + /* initialize ipc object */ rt_ipc_object_init(&(event->parent)); - /* init event */ + /* initialize event */ event->set = 0; return event; @@ -1050,7 +1050,7 @@ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set) event->set |= set; RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(event->parent.parent))); - + if (!rt_list_isempty(&event->parent.suspend_thread)) { /* search thread list to resume thread */ @@ -1073,7 +1073,7 @@ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set) { if (thread->event_set & event->set) { - /* save recieved event set */ + /* save the received event set */ thread->event_set = thread->event_set & event->set; /* received an OR event */ @@ -1143,7 +1143,7 @@ rt_err_t rt_event_recv(rt_event_t event, if (set == 0) return -RT_ERROR; - /* init status */ + /* initialize status */ status = -RT_ERROR; /* get current thread */ thread = rt_thread_self(); @@ -1253,7 +1253,7 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg) /* parameter check */ RT_ASSERT(event != RT_NULL); RT_ASSERT(rt_object_get_type(&event->parent.parent) == RT_Object_Class_Event); - + if (cmd == RT_IPC_CMD_RESET) { /* disable interrupt */ @@ -1262,7 +1262,7 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg) /* resume all waiting thread */ rt_ipc_list_resume_all(&event->parent.suspend_thread); - /* init event set */ + /* initialize event set */ event->set = 0; /* enable interrupt */ @@ -1299,23 +1299,23 @@ rt_err_t rt_mb_init(rt_mailbox_t mb, { RT_ASSERT(mb != RT_NULL); - /* init object */ + /* initialize object */ rt_object_init(&(mb->parent.parent), RT_Object_Class_MailBox, name); /* set parent flag */ mb->parent.parent.flag = flag; - /* init ipc object */ + /* initialize ipc object */ rt_ipc_object_init(&(mb->parent)); - /* init mailbox */ + /* initialize mailbox */ mb->msg_pool = (rt_ubase_t *)msgpool; mb->size = size; mb->entry = 0; mb->in_offset = 0; mb->out_offset = 0; - /* init an additional list of sender suspend thread */ + /* initialize an additional list of sender suspend thread */ rt_list_init(&(mb->suspend_sender_thread)); return RT_EOK; @@ -1372,10 +1372,10 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag) /* set parent */ mb->parent.parent.flag = flag; - /* init ipc object */ + /* initialize ipc object */ rt_ipc_object_init(&(mb->parent)); - /* init mailbox */ + /* initialize mailbox */ mb->size = size; mb->msg_pool = (rt_ubase_t *)RT_KERNEL_MALLOC(mb->size * sizeof(rt_ubase_t)); if (mb->msg_pool == RT_NULL) @@ -1389,7 +1389,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag) mb->in_offset = 0; mb->out_offset = 0; - /* init an additional list of sender suspend thread */ + /* initialize an additional list of sender suspend thread */ rt_list_init(&(mb->suspend_sender_thread)); return mb; @@ -1791,27 +1791,27 @@ rt_err_t rt_mq_init(rt_mq_t mq, /* parameter check */ RT_ASSERT(mq != RT_NULL); - /* init object */ + /* initialize object */ rt_object_init(&(mq->parent.parent), RT_Object_Class_MessageQueue, name); /* set parent flag */ mq->parent.parent.flag = flag; - /* init ipc object */ + /* initialize ipc object */ rt_ipc_object_init(&(mq->parent)); - /* set messasge pool */ + /* set message pool */ mq->msg_pool = msgpool; /* get correct message size */ mq->msg_size = RT_ALIGN(msg_size, RT_ALIGN_SIZE); mq->max_msgs = pool_size / (mq->msg_size + sizeof(struct rt_mq_message)); - /* init message list */ + /* initialize message list */ mq->msg_queue_head = RT_NULL; mq->msg_queue_tail = RT_NULL; - /* init message empty list */ + /* initialize message empty list */ mq->msg_queue_free = RT_NULL; for (temp = 0; temp < mq->max_msgs; temp ++) { @@ -1824,7 +1824,7 @@ rt_err_t rt_mq_init(rt_mq_t mq, /* the initial entry is zero */ mq->entry = 0; - /* init an additional list of sender suspend thread */ + /* initialize an additional list of sender suspend thread */ rt_list_init(&(mq->suspend_sender_thread)); return RT_EOK; @@ -1887,10 +1887,10 @@ rt_mq_t rt_mq_create(const char *name, /* set parent */ mq->parent.parent.flag = flag; - /* init ipc object */ + /* initialize ipc object */ rt_ipc_object_init(&(mq->parent)); - /* init message queue */ + /* initialize message queue */ /* get correct message size */ mq->msg_size = RT_ALIGN(msg_size, RT_ALIGN_SIZE); @@ -1905,11 +1905,11 @@ rt_mq_t rt_mq_create(const char *name, return RT_NULL; } - /* init message list */ + /* initialize message list */ mq->msg_queue_head = RT_NULL; mq->msg_queue_tail = RT_NULL; - /* init message empty list */ + /* initialize message empty list */ mq->msg_queue_free = RT_NULL; for (temp = 0; temp < mq->max_msgs; temp ++) { @@ -1922,7 +1922,7 @@ rt_mq_t rt_mq_create(const char *name, /* the initial entry is zero */ mq->entry = 0; - /* init an additional list of sender suspend thread */ + /* initialize an additional list of sender suspend thread */ rt_list_init(&(mq->suspend_sender_thread)); return mq; diff --git a/src/kservice.c b/src/kservice.c index 202bd97f83..58f04330f1 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -316,7 +316,7 @@ RTM_EXPORT(rt_memmove); * This function will compare two areas of memory * * @param cs one area of memory - * @param ct znother area of memory + * @param ct another area of memory * @param count the size of the area * * @return the result diff --git a/src/signal.c b/src/signal.c index bea3615d34..bb9339ab6c 100644 --- a/src/signal.c +++ b/src/signal.c @@ -22,8 +22,8 @@ #define RT_SIG_INFO_MAX 32 #endif -#define DBG_TAG "SIGN" -#define DBG_LVL DBG_WARNING +#define DBG_TAG "SIGN" +#define DBG_LVL DBG_WARNING #include #define sig_mask(sig_no) (1u << sig_no) diff --git a/src/thread.c b/src/thread.c index c5f75a1176..7596906fae 100644 --- a/src/thread.c +++ b/src/thread.c @@ -179,7 +179,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, thread->cleanup = 0; thread->user_data = 0; - /* init thread timer */ + /* initialize thread timer */ rt_timer_init(&(thread->thread_timer), thread->name, rt_thread_timeout, @@ -242,7 +242,7 @@ rt_err_t rt_thread_init(struct rt_thread *thread, RT_ASSERT(thread != RT_NULL); RT_ASSERT(stack_start != RT_NULL); - /* init thread object */ + /* initialize thread object */ rt_object_init((rt_object_t)thread, RT_Object_Class_Thread, name); return _rt_thread_init(thread, @@ -293,7 +293,7 @@ rt_err_t rt_thread_startup(rt_thread_t thread) RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_INIT); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); - /* set current priority to init priority */ + /* set current priority to initialize priority */ thread->current_priority = thread->init_priority; /* calculate priority attribute */ -- cgit v1.3.1 From 4a14b8f59a5e03a9d1e9a3185abcd4daf68f5505 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 18 Dec 2019 21:38:26 +0800 Subject: [Kernel] Add delay_util implementation. --- include/rtthread.h | 1 + src/thread.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'src/thread.c') diff --git a/include/rtthread.h b/include/rtthread.h index 13a1a4424b..d7be380764 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -138,6 +138,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread); rt_err_t rt_thread_yield(void); rt_err_t rt_thread_delay(rt_tick_t tick); +rt_err_t rt_thread_delay_util(rt_tick_t *tick, rt_tick_t inc_tick); rt_err_t rt_thread_mdelay(rt_int32_t ms); rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg); rt_err_t rt_thread_suspend(rt_thread_t thread); diff --git a/src/thread.c b/src/thread.c index 7596906fae..95f9f76f84 100644 --- a/src/thread.c +++ b/src/thread.c @@ -530,6 +530,61 @@ rt_err_t rt_thread_delay(rt_tick_t tick) } RTM_EXPORT(rt_thread_delay); +/** + * This function will let current thread delay util (*tick + inc_tick). + * + * @param tick the tick of last wakeup. + * @param inc_tick the increment tick + * + * @return RT_EOK + */ +rt_err_t rt_thread_delay_util(rt_tick_t *tick, rt_tick_t inc_tick) +{ + register rt_base_t level; + struct rt_thread *thread; + + /* set to current thread */ + thread = rt_thread_self(); + RT_ASSERT(thread != RT_NULL); + RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); + + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + + if (rt_tick_get() - *tick < inc_tick) + { + *tick = rt_tick_get() - *tick + inc_tick; + + /* suspend thread */ + rt_thread_suspend(thread); + + /* reset the timeout of thread timer and start it */ + rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, tick); + rt_timer_start(&(thread->thread_timer)); + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + + rt_schedule(); + + /* get the wakeup tick */ + *tick = rt_tick_get(); + + /* clear error number of this thread to RT_EOK */ + if (thread->error == -RT_ETIMEOUT) + { + thread->error = RT_EOK; + } + } + else + { + rt_hw_interrupt_enable(level); + } + + return RT_EOK; +} +RTM_EXPORT(rt_thread_delay_util); + /** * This function will let current thread delay for some milliseconds. * -- cgit v1.3.1 From df57b9014c07fbb3afdc33c1dc94c55c2dba0359 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 19 Dec 2019 08:06:53 +0800 Subject: Update thread.c --- src/thread.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index 95f9f76f84..041dfab879 100644 --- a/src/thread.c +++ b/src/thread.c @@ -543,6 +543,8 @@ rt_err_t rt_thread_delay_util(rt_tick_t *tick, rt_tick_t inc_tick) register rt_base_t level; struct rt_thread *thread; + RT_ASSERT(tick != RT_NULL); + /* set to current thread */ thread = rt_thread_self(); RT_ASSERT(thread != RT_NULL); @@ -567,9 +569,6 @@ rt_err_t rt_thread_delay_util(rt_tick_t *tick, rt_tick_t inc_tick) rt_schedule(); - /* get the wakeup tick */ - *tick = rt_tick_get(); - /* clear error number of this thread to RT_EOK */ if (thread->error == -RT_ETIMEOUT) { @@ -581,6 +580,9 @@ rt_err_t rt_thread_delay_util(rt_tick_t *tick, rt_tick_t inc_tick) rt_hw_interrupt_enable(level); } + /* get the wakeup tick */ + *tick = rt_tick_get(); + return RT_EOK; } RTM_EXPORT(rt_thread_delay_util); -- cgit v1.3.1 From 2c1f7b73a73f6e5aae7c9bbb1c38a609e39a1a08 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 19 Dec 2019 09:45:58 +0800 Subject: [Kernel] fix typo in rthread_delay --- include/rtthread.h | 2 +- src/thread.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/thread.c') diff --git a/include/rtthread.h b/include/rtthread.h index d7be380764..92cdf012b2 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -138,7 +138,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread); rt_err_t rt_thread_yield(void); rt_err_t rt_thread_delay(rt_tick_t tick); -rt_err_t rt_thread_delay_util(rt_tick_t *tick, rt_tick_t inc_tick); +rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick); rt_err_t rt_thread_mdelay(rt_int32_t ms); rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg); rt_err_t rt_thread_suspend(rt_thread_t thread); diff --git a/src/thread.c b/src/thread.c index 041dfab879..3a3c97d0b6 100644 --- a/src/thread.c +++ b/src/thread.c @@ -531,14 +531,14 @@ rt_err_t rt_thread_delay(rt_tick_t tick) RTM_EXPORT(rt_thread_delay); /** - * This function will let current thread delay util (*tick + inc_tick). + * This function will let current thread delay until (*tick + inc_tick). * * @param tick the tick of last wakeup. * @param inc_tick the increment tick * * @return RT_EOK */ -rt_err_t rt_thread_delay_util(rt_tick_t *tick, rt_tick_t inc_tick) +rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) { register rt_base_t level; struct rt_thread *thread; -- cgit v1.3.1 From ff445708874117471d569e0eec368dded0747741 Mon Sep 17 00:00:00 2001 From: zhaoshaowei Date: Fri, 27 Dec 2019 16:41:47 +0800 Subject: [Kernel] fix typo in rt_thread_delay_util --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index 3a3c97d0b6..74a573b78f 100644 --- a/src/thread.c +++ b/src/thread.c @@ -585,7 +585,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) return RT_EOK; } -RTM_EXPORT(rt_thread_delay_util); +RTM_EXPORT(rt_thread_delay_until); /** * This function will let current thread delay for some milliseconds. -- cgit v1.3.1 From d6d690da1a4987df13268aaf91d1c05337afb5c4 Mon Sep 17 00:00:00 2001 From: suhui <3164683437@qq.com> Date: Fri, 21 Feb 2020 19:46:59 +0800 Subject: fix the comment Signed-off-by: suhui <3164683437@qq.com> --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index 74a573b78f..19ab5549c8 100644 --- a/src/thread.c +++ b/src/thread.c @@ -590,7 +590,7 @@ RTM_EXPORT(rt_thread_delay_until); /** * This function will let current thread delay for some milliseconds. * - * @param tick the delay time + * @param ms the delay ms time * * @return RT_EOK */ -- cgit v1.3.1 From 240961e8e88a3b3fb6624dcd89599511149f7e5c Mon Sep 17 00:00:00 2001 From: Cliff Chen Date: Fri, 15 May 2020 18:15:43 +0800 Subject: [Kernel] Fix double release for thread Signed-off-by: Cliff Chen --- src/thread.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index 19ab5549c8..2b2fb1922c 100644 --- a/src/thread.c +++ b/src/thread.c @@ -338,6 +338,9 @@ rt_err_t rt_thread_detach(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread)); + if (thread->stat == RT_THREAD_CLOSE) + return RT_EOK; + if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) { /* remove from schedule */ @@ -437,6 +440,9 @@ rt_err_t rt_thread_delete(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread) == RT_FALSE); + if (thread->stat == RT_THREAD_CLOSE) + return RT_EOK; + if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) { /* remove from schedule */ -- cgit v1.3.1 From 7471a665db9f5a474a066cd0f59132dac656c7e7 Mon Sep 17 00:00:00 2001 From: cliff-cmc <62226047+cliff-cmc@users.noreply.github.com> Date: Mon, 25 May 2020 08:43:13 +0800 Subject: Update thread.c --- src/thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index 2b2fb1922c..715596b132 100644 --- a/src/thread.c +++ b/src/thread.c @@ -338,7 +338,7 @@ rt_err_t rt_thread_detach(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread)); - if (thread->stat == RT_THREAD_CLOSE) + if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_CLOSE) return RT_EOK; if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) @@ -440,7 +440,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread) == RT_FALSE); - if (thread->stat == RT_THREAD_CLOSE) + if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_CLOSE) return RT_EOK; if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) -- cgit v1.3.1 From 3ed84b8d03dc9778f1c262278e2b8653de834408 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Fri, 24 Jul 2020 21:13:56 +0800 Subject: 解决yield操作不能及时释放cpu的问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clock.c | 3 +-- src/scheduler.c | 6 +++--- src/thread.c | 8 ++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src/thread.c') diff --git a/src/clock.c b/src/clock.c index 97a09ddeaf..a91cd829b6 100644 --- a/src/clock.c +++ b/src/clock.c @@ -91,8 +91,7 @@ void rt_tick_increase(void) thread->stat |= RT_THREAD_STAT_YIELD; - /* yield */ - rt_thread_yield(); + rt_schedule(); } /* check timer */ diff --git a/src/scheduler.c b/src/scheduler.c index 6baaa9627a..d0859e745a 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -350,9 +350,9 @@ void rt_schedule(void) } else { - current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; rt_schedule_insert_thread(current_thread); } + current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } to_thread->oncpu = cpu_id; if (to_thread != current_thread) @@ -448,9 +448,9 @@ void rt_schedule(void) } else { - rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; need_insert_from_thread = 1; } + rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } if (to_thread != rt_current_thread) @@ -599,9 +599,9 @@ void rt_scheduler_do_irq_switch(void *context) } else { - current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; rt_schedule_insert_thread(current_thread); } + current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } to_thread->oncpu = cpu_id; if (to_thread != current_thread) diff --git a/src/thread.c b/src/thread.c index 715596b132..60aa17f381 100644 --- a/src/thread.c +++ b/src/thread.c @@ -478,7 +478,15 @@ RTM_EXPORT(rt_thread_delete); */ rt_err_t rt_thread_yield(void) { + struct rt_thread *thread; + rt_base_t lock; + + thread = rt_thread_self(); + lock = rt_hw_interrupt_disable(); + thread->remaining_tick = thread->init_tick; + thread->stat |= RT_THREAD_STAT_YIELD; rt_schedule(); + rt_hw_interrupt_enable(lock); return RT_EOK; } -- cgit v1.3.1 From c15a7858c9a7bc1f978faa5f0ea3f618fbd3bc03 Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Fri, 14 Aug 2020 15:52:35 +0800 Subject: [fix] thread control bug about RT_THREAD_CTRL_CLOSE command --- src/thread.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index 715596b132..9f80482b20 100644 --- a/src/thread.c +++ b/src/thread.c @@ -679,9 +679,17 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) case RT_THREAD_CTRL_STARTUP: return rt_thread_startup(thread); -#ifdef RT_USING_HEAP case RT_THREAD_CTRL_CLOSE: - return rt_thread_delete(thread); + + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + { + return rt_thread_detach(thread); + } +#ifdef RT_USING_HEAP + else + { + return rt_thread_delete(thread); + } #endif #ifdef RT_USING_SMP -- cgit v1.3.1 From 0776b36a4f17239740c0a4d0254330c0e5ff9824 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 22 Oct 2020 22:44:58 +0800 Subject: [Kernel] fix the delay_until issue --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index 7a90e57f25..49e2022bf7 100644 --- a/src/thread.c +++ b/src/thread.c @@ -569,7 +569,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) if (rt_tick_get() - *tick < inc_tick) { - *tick = rt_tick_get() - *tick + inc_tick; + *tick = *tick + inc_tick - rt_tick_get(); /* suspend thread */ rt_thread_suspend(thread); -- cgit v1.3.1