From b2c338970f6332f916ef132f838f6d1f1d52d118 Mon Sep 17 00:00:00 2001 From: armink Date: Sat, 9 Mar 2019 15:46:56 +0800 Subject: [kservice] Update the rt_strnlen function. --- include/rtthread.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/rtthread.h') diff --git a/include/rtthread.h b/include/rtthread.h index d2356b8eda..e66e30fddb 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -516,6 +516,7 @@ void *rt_memcpy(void *dest, const void *src, rt_ubase_t n); rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count); rt_int32_t rt_strcmp(const char *cs, const char *ct); rt_size_t rt_strlen(const char *src); +rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen); char *rt_strdup(const char *s); #if defined(__CC_ARM) || defined(__CLANG_ARM) /* leak strdup interface */ -- cgit v1.3.1 From 1e16a1ef23135d54b8e8972909b9c64fa815ed9d Mon Sep 17 00:00:00 2001 From: HubretXie Date: Wed, 20 Mar 2019 14:55:59 +0800 Subject: 修改函数返回类型 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rt_tick_from_millisecond返回类型修改为rt_tick_t --- include/rtthread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/rtthread.h') diff --git a/include/rtthread.h b/include/rtthread.h index e66e30fddb..955ea51c50 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -75,7 +75,7 @@ void rt_system_tick_init(void); rt_tick_t rt_tick_get(void); void rt_tick_set(rt_tick_t tick); void rt_tick_increase(void); -int rt_tick_from_millisecond(rt_int32_t ms); +rt_tick_t rt_tick_from_millisecond(rt_int32_t ms); void rt_system_timer_init(void); void rt_system_timer_thread_init(void); -- cgit v1.3.1 From c8e27adf1f357bf50d41744fde82738b50e1c214 Mon Sep 17 00:00:00 2001 From: tyx <462747508@qq.com> Date: Tue, 9 Jul 2019 21:34:56 +0800 Subject: [src][ipc]完善 message queue 相关定义 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtthread.h | 4 ++-- src/ipc.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'include/rtthread.h') diff --git a/include/rtthread.h b/include/rtthread.h index 955ea51c50..04db77da46 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -378,8 +378,8 @@ rt_mq_t rt_mq_create(const char *name, rt_uint8_t flag); rt_err_t rt_mq_delete(rt_mq_t mq); -rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size); -rt_err_t rt_mq_urgent(rt_mq_t mq, void *buffer, rt_size_t size); +rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size); +rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size); rt_err_t rt_mq_recv(rt_mq_t mq, void *buffer, rt_size_t size, diff --git a/src/ipc.c b/src/ipc.c index e293eee8cd..39cf217baa 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1960,7 +1960,7 @@ RTM_EXPORT(rt_mq_delete); * * @return the error code */ -rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size) +rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size) { register rt_ubase_t temp; struct rt_mq_message *msg; @@ -2050,7 +2050,7 @@ RTM_EXPORT(rt_mq_send); * * @return the error code */ -rt_err_t rt_mq_urgent(rt_mq_t mq, void *buffer, rt_size_t size) +rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) { register rt_ubase_t temp; struct rt_mq_message *msg; -- cgit v1.3.1 From e4671d291689e71967afa5dec4ff25d310faa3fb Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Mon, 16 Sep 2019 15:12:42 +0800 Subject: [kernel][ipc] add send wait support for message queue --- include/rtdef.h | 2 + include/rtthread.h | 4 ++ src/ipc.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 131 insertions(+), 5 deletions(-) (limited to 'include/rtthread.h') diff --git a/include/rtdef.h b/include/rtdef.h index 7c05178e3c..b25a6a87d5 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -742,6 +742,8 @@ struct rt_messagequeue void *msg_queue_head; /**< list head */ void *msg_queue_tail; /**< list tail */ void *msg_queue_free; /**< pointer indicated the free node of queue */ + + rt_list_t suspend_sender_thread; /**< sender thread suspended on this message queue */ }; typedef struct rt_messagequeue *rt_mq_t; #endif diff --git a/include/rtthread.h b/include/rtthread.h index 04db77da46..d703f36268 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -379,6 +379,10 @@ rt_mq_t rt_mq_create(const char *name, rt_err_t rt_mq_delete(rt_mq_t mq); rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size); +rt_err_t rt_mq_send_wait(rt_mq_t mq, + const void *buffer, + rt_size_t size, + rt_int32_t timeout); rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size); rt_err_t rt_mq_recv(rt_mq_t mq, void *buffer, diff --git a/src/ipc.c b/src/ipc.c index c6a05e96a4..16d714b3f4 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -33,6 +33,7 @@ * 2011-12-18 Bernard add more parameter checking in message queue * 2013-09-14 Grissiom add an option check in rt_event_recv * 2018-10-02 Bernard add 64bit support for mailbox + * 2019-09-16 tyx add send wait support for message queue */ #include @@ -1823,6 +1824,9 @@ 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 */ + rt_list_init(&(mq->suspend_sender_thread)); + return RT_EOK; } RTM_EXPORT(rt_mq_init); @@ -1843,6 +1847,8 @@ rt_err_t rt_mq_detach(rt_mq_t mq) /* resume all suspended thread */ rt_ipc_list_resume_all(&mq->parent.suspend_thread); + /* also resume all message queue private suspended thread */ + rt_ipc_list_resume_all(&(mq->suspend_sender_thread)); /* detach message queue object */ rt_object_detach(&(mq->parent.parent)); @@ -1916,6 +1922,9 @@ 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 */ + rt_list_init(&(mq->suspend_sender_thread)); + return mq; } RTM_EXPORT(rt_mq_create); @@ -1938,6 +1947,8 @@ rt_err_t rt_mq_delete(rt_mq_t mq) /* resume all suspended thread */ rt_ipc_list_resume_all(&(mq->parent.suspend_thread)); + /* also resume all message queue private suspended thread */ + rt_ipc_list_resume_all(&(mq->suspend_sender_thread)); /* free message queue pool */ RT_KERNEL_FREE(mq->msg_pool); @@ -1951,19 +1962,25 @@ RTM_EXPORT(rt_mq_delete); #endif /** - * This function will send a message to message queue object, if there are - * threads suspended on message queue object, it will be waked up. + * This function will send a message to message queue object. If the message queue is full, + * current thread will be suspended until timeout. * * @param mq the message queue object * @param buffer the message * @param size the size of buffer + * @param timeout the waiting time * * @return the error code */ -rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size) +rt_err_t rt_mq_send_wait(rt_mq_t mq, + const void *buffer, + rt_size_t size, + rt_int32_t timeout) { register rt_ubase_t temp; struct rt_mq_message *msg; + rt_uint32_t tick_delta; + struct rt_thread *thread; /* parameter check */ RT_ASSERT(mq != RT_NULL); @@ -1975,6 +1992,11 @@ rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size) if (size > mq->msg_size) return -RT_ERROR; + /* initialize delta tick */ + tick_delta = 0; + /* get current thread */ + thread = rt_thread_self(); + RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mq->parent.parent))); /* disable interrupt */ @@ -1982,14 +2004,78 @@ rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size) /* get a free list, there must be an empty item */ msg = (struct rt_mq_message *)mq->msg_queue_free; - /* message queue is full */ - if (msg == RT_NULL) + /* for non-blocking call */ + if (msg == RT_NULL && timeout == 0) { /* enable interrupt */ rt_hw_interrupt_enable(temp); return -RT_EFULL; } + + /* message queue is full */ + while ((msg = mq->msg_queue_free) == RT_NULL) + { + /* reset error number in thread */ + thread->error = RT_EOK; + + /* no waiting, return timeout */ + if (timeout == 0) + { + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + + return -RT_EFULL; + } + + RT_DEBUG_IN_THREAD_CONTEXT; + /* suspend current thread */ + rt_ipc_list_suspend(&(mq->suspend_sender_thread), + thread, + mq->parent.parent.flag); + + /* has waiting time, start thread timer */ + if (timeout > 0) + { + /* get the start tick of timer */ + tick_delta = rt_tick_get(); + + RT_DEBUG_LOG(RT_DEBUG_IPC, ("mq_send_wait: start timer of thread:%s\n", + thread->name)); + + /* reset the timeout of thread timer and start it */ + rt_timer_control(&(thread->thread_timer), + RT_TIMER_CTRL_SET_TIME, + &timeout); + rt_timer_start(&(thread->thread_timer)); + } + + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + + /* re-schedule */ + rt_schedule(); + + /* resume from suspend state */ + if (thread->error != RT_EOK) + { + /* return error */ + return thread->error; + } + + /* disable interrupt */ + temp = rt_hw_interrupt_disable(); + + /* if it's not waiting forever and then re-calculate timeout tick */ + if (timeout > 0) + { + tick_delta = rt_tick_get() - tick_delta; + timeout -= tick_delta; + if (timeout < 0) + timeout = 0; + } + } + /* move free list pointer */ mq->msg_queue_free = msg->next; @@ -2037,6 +2123,22 @@ rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size) return RT_EOK; } +RTM_EXPORT(rt_mq_send_wait) + +/** + * This function will send a message to message queue object, if there are + * threads suspended on message queue object, it will be waked up. + * + * @param mq the message queue object + * @param buffer the message + * @param size the size of buffer + * + * @return the error code + */ +rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size) +{ + return rt_mq_send_wait(mq, buffer, size, 0); +} RTM_EXPORT(rt_mq_send); /** @@ -2257,6 +2359,22 @@ rt_err_t rt_mq_recv(rt_mq_t mq, /* put message to free list */ msg->next = (struct rt_mq_message *)mq->msg_queue_free; mq->msg_queue_free = msg; + + /* resume suspended thread */ + if (!rt_list_isempty(&(mq->suspend_sender_thread))) + { + rt_ipc_list_resume(&(mq->suspend_sender_thread)); + + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + + RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(mq->parent.parent))); + + rt_schedule(); + + return RT_EOK; + } + /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -2292,6 +2410,8 @@ rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg) /* resume all waiting thread */ rt_ipc_list_resume_all(&mq->parent.suspend_thread); + /* also resume all message queue private suspended thread */ + rt_ipc_list_resume_all(&(mq->suspend_sender_thread)); /* release all message in the queue */ while (mq->msg_queue_head != RT_NULL) -- cgit v1.3.1 From 5cd65092967a1dbaa35bb7fdd80cf3a0e2f9cc9f Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sat, 28 Sep 2019 11:56:03 +0800 Subject: [Kernel] cleanup code of spinlock in SMP Kernel --- include/rthw.h | 12 ++---------- include/rtthread.h | 21 +++++++++++++++++++++ src/SConscript | 3 +++ src/cpu.c | 53 ++++++++++++++++------------------------------------- 4 files changed, 42 insertions(+), 47 deletions(-) (limited to 'include/rtthread.h') diff --git a/include/rthw.h b/include/rthw.h index a77f2c1e46..2a602dcfe7 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -143,10 +143,10 @@ typedef union { } tickets; } rt_hw_spinlock_t; -typedef struct +struct rt_spinlock { 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); @@ -187,16 +187,8 @@ 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/include/rtthread.h b/include/rtthread.h index d703f36268..13a1a4424b 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -391,6 +391,27 @@ rt_err_t rt_mq_recv(rt_mq_t mq, rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg); #endif +/* + * spinlock + */ +#ifdef RT_USING_SMP +struct rt_spinlock; + +void rt_spin_lock_init(struct rt_spinlock *lock); +void rt_spin_lock(struct rt_spinlock *lock); +void rt_spin_unlock(struct rt_spinlock *lock); +rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock); +void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level); + +#else +#define rt_spin_lock_init(lock) /* nothing */ +#define rt_spin_lock(lock) rt_enter_critical() +#define rt_spin_unlock(lock) rt_exit_critical() +#define rt_spin_lock_irqsave(lock) rt_hw_interrupt_disable() +#define rt_spin_unlock_irqrestore(lock, level) rt_hw_interrupt_enable(level) + +#endif + /**@}*/ #ifdef RT_USING_DEVICE diff --git a/src/SConscript b/src/SConscript index ea6e19318f..82c3b8aaf1 100644 --- a/src/SConscript +++ b/src/SConscript @@ -26,6 +26,9 @@ if GetDepend('RT_USING_MEMHEAP') == False: if GetDepend('RT_USING_DEVICE') == False: SrcRemove(src, ['device.c']) +if GetDepend('RT_USING_SMP') == False: + SrcRemove(src, ['cpu.c']) + group = DefineGroup('Kernel', src, depend = [''], CPPPATH = CPPPATH) Return('group') diff --git a/src/cpu.c b/src/cpu.c index a4075108e1..f6f210eda8 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -12,9 +12,12 @@ #include #ifdef RT_USING_SMP -/*********************************** +static struct rt_cpu rt_cpus[RT_CPUS_NR]; +rt_hw_spinlock_t _cpus_lock; + +/* * disable scheduler - ***********************************/ + */ static void rt_preempt_disable(void) { register rt_base_t level; @@ -23,7 +26,7 @@ static void rt_preempt_disable(void) /* disable interrupt */ level = rt_hw_local_irq_disable(); - current_thread = rt_cpu_self()->current_thread; + current_thread = rt_thread_self(); if (!current_thread) { rt_hw_local_irq_enable(level); @@ -37,9 +40,9 @@ static void rt_preempt_disable(void) rt_hw_local_irq_enable(level); } -/*********************************** - * restore scheduler - ***********************************/ +/* + * enable scheduler + */ static void rt_preempt_enable(void) { register rt_base_t level; @@ -48,7 +51,7 @@ static void rt_preempt_enable(void) /* disable interrupt */ level = rt_hw_local_irq_disable(); - current_thread = rt_cpu_self()->current_thread; + current_thread = rt_thread_self(); if (!current_thread) { rt_hw_local_irq_enable(level); @@ -62,73 +65,49 @@ static void rt_preempt_enable(void) /* enable interrupt */ rt_hw_local_irq_enable(level); } -#endif -void rt_spin_lock_init(rt_spinlock_t *lock) +void rt_spin_lock_init(struct rt_spinlock *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) +void rt_spin_lock(struct rt_spinlock *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) +void rt_spin_unlock(struct rt_spinlock *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) +rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *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) +void rt_spin_unlock_irqrestore(struct rt_spinlock *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]; -rt_hw_spinlock_t _cpus_lock; - /** * This fucntion will return current cpu. */ @@ -155,7 +134,7 @@ rt_base_t rt_cpus_lock(void) pcpu = rt_cpu_self(); if (pcpu->current_thread != RT_NULL) { - register rt_uint16_t lock_nest = pcpu->current_thread->cpus_lock_nest; + register rt_ubase_t lock_nest = pcpu->current_thread->cpus_lock_nest; pcpu->current_thread->cpus_lock_nest++; if (lock_nest == 0) -- 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 'include/rtthread.h') 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 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 'include/rtthread.h') 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 d0ebdc54d42f9985e2316f8db58b3e6c65582f66 Mon Sep 17 00:00:00 2001 From: lihui Date: Tue, 24 Mar 2020 18:59:31 +0800 Subject: fix return type error of rt_strcasecmp: rt_uint32_t to rt_int32_t Signed-off-by: lihui --- include/rtthread.h | 2 +- src/kservice.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include/rtthread.h') diff --git a/include/rtthread.h b/include/rtthread.h index 92cdf012b2..70d4f38896 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -554,7 +554,7 @@ rt_int32_t rt_sscanf(const char *buf, const char *fmt, ...); char *rt_strncpy(char *dest, const char *src, rt_ubase_t n); void *rt_memmove(void *dest, const void *src, rt_ubase_t n); rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count); -rt_uint32_t rt_strcasecmp(const char *a, const char *b); +rt_int32_t rt_strcasecmp(const char *a, const char *b); void rt_show_version(void); diff --git a/src/kservice.c b/src/kservice.c index 0a8786e17a..1705ce5283 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -370,7 +370,7 @@ RTM_EXPORT(rt_strstr); * * @return the result */ -rt_uint32_t rt_strcasecmp(const char *a, const char *b) +rt_int32_t rt_strcasecmp(const char *a, const char *b) { int ca, cb; -- cgit v1.3.1 From b1eb3943a3ab1e4b39574d01eb98480afabb29d1 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 10 Apr 2020 00:01:58 +0800 Subject: [Kernel] Add rt_object_get_length/rt_object_get_pointers APIs. --- include/rtthread.h | 3 ++ src/object.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 79 insertions(+), 11 deletions(-) (limited to 'include/rtthread.h') diff --git a/include/rtthread.h b/include/rtthread.h index 70d4f38896..a76601a3bf 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -41,6 +41,9 @@ extern "C" { void rt_system_object_init(void); struct rt_object_information * rt_object_get_information(enum rt_object_class_type type); +int rt_object_get_length(enum rt_object_class_type type); +int rt_object_get_pointers(enum rt_object_class_type type, rt_object_t *pointers, int maxlen); + void rt_object_init(struct rt_object *object, enum rt_object_class_type type, const char *name); diff --git a/src/object.c b/src/object.c index 4ee2f6a1a1..62d70816dc 100644 --- a/src/object.c +++ b/src/object.c @@ -212,7 +212,9 @@ void rt_system_object_init(void) /** * This function will return the specified type of object information. * - * @param type the type of object + * @param type the type of object, which can be + * RT_Object_Class_Thread/Semaphore/Mutex... etc + * * @return the object type information or RT_NULL */ struct rt_object_information * @@ -227,6 +229,75 @@ rt_object_get_information(enum rt_object_class_type type) } RTM_EXPORT(rt_object_get_information); +/** + * This function will return the length of object list in object container. + * + * @param type the type of object, which can be + * RT_Object_Class_Thread/Semaphore/Mutex... etc + * @return the length of object list + */ +int rt_object_get_length(enum rt_object_class_type type) +{ + int count = 0; + rt_ubase_t level; + struct rt_list_node *node = RT_NULL; + struct rt_object_information *information = RT_NULL; + + information = rt_object_get_information((enum rt_object_class_type)type); + if (information == RT_NULL) return 0; + + level = rt_hw_interrupt_disable(); + /* get the count of objects */ + rt_list_for_each(node, &(information->object_list)) + { + count ++; + } + rt_hw_interrupt_enable(level); + + return count; +} +RTM_EXPORT(rt_object_get_length); + +/** + * This function will copy the object pointer of the specified type, + * with the maximum size specified by maxlen. + * + * @param type the type of object, which can be + * RT_Object_Class_Thread/Semaphore/Mutex... etc + * @param pointers the pointers will be saved to + * @param maxlen the maximum number of pointers can be saved + * + * @return the copied number of object pointers + */ +int rt_object_get_pointers(enum rt_object_class_type type, rt_object_t *pointers, int maxlen) +{ + int index = 0; + rt_ubase_t level; + + struct rt_object *object; + struct rt_list_node *node = RT_NULL; + struct rt_object_information *information = RT_NULL; + + if (maxlen <= 0) return 0; + + information = rt_object_get_information((enum rt_object_class_type)type); + if (information == RT_NULL) return 0; + + level = rt_hw_interrupt_disable(); + /* retrieve pointer of object */ + rt_list_for_each(node, &(information->object_list)) + { + object = rt_list_entry(node, struct rt_object, list); + + pointers[index] = object; + index ++; + } + rt_hw_interrupt_enable(level); + + return index; +} +RTM_EXPORT(rt_object_get_pointers); + /** * This function will initialize an object and add it to object system * management. @@ -482,9 +553,10 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type) struct rt_list_node *node = RT_NULL; struct rt_object_information *information = RT_NULL; + information = rt_object_get_information((enum rt_object_class_type)type); + /* parameter check */ - if ((name == RT_NULL) || (type > RT_Object_Class_Unknown)) - return RT_NULL; + if ((name == RT_NULL) || (information == RT_NULL)) return RT_NULL; /* which is invoke in interrupt status */ RT_DEBUG_NOT_IN_INTERRUPT; @@ -493,14 +565,7 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type) rt_enter_critical(); /* try to find object */ - if (information == RT_NULL) - { - information = rt_object_get_information((enum rt_object_class_type)type); - RT_ASSERT(information != RT_NULL); - } - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) + rt_list_for_each(node, &(information->object_list)) { object = rt_list_entry(node, struct rt_object, list); if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0) -- cgit v1.3.1