Skip to content

[kernel]Isolate errors between the threading module and the scheduler. #7096

New issue

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

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

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/drivers/cputime/cputimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ rt_err_t rt_cputime_sleep(rt_uint64_t tick)
/* enable interrupt */
rt_hw_interrupt_enable(level);

thread->error = -RT_EINTR;
thread->error = RT_EOK;

rt_schedule();
if (thread->error == -RT_ETIMEOUT)
Expand Down
5 changes: 5 additions & 0 deletions components/drivers/ipc/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ static void _workqueue_thread_entry(void *parameter)

/* do work */
work->work_func(work, work->work_data);

RT_ASSERT(rt_thread_self()->error == RT_EOK);
/* clean current work */
queue->work_current = RT_NULL;

Expand Down Expand Up @@ -112,6 +114,7 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
{
/* resume work thread */
rt_thread_resume(queue->work_thread);
queue->work_thread->error = RT_EOK;
rt_hw_interrupt_enable(level);
rt_schedule();
}
Expand Down Expand Up @@ -194,6 +197,7 @@ static void _delayed_work_timeout_handler(void *parameter)
{
/* resume work thread */
rt_thread_resume(queue->work_thread);
queue->work_thread->error = RT_EOK;
rt_hw_interrupt_enable(level);
rt_schedule();
}
Expand Down Expand Up @@ -352,6 +356,7 @@ rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *wo
{
/* resume work thread */
rt_thread_resume(queue->work_thread);
queue->work_thread->error = RT_EOK;
rt_hw_interrupt_enable(level);
rt_schedule();
}
Expand Down
1 change: 1 addition & 0 deletions include/rtdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ typedef int (*init_fn_t)(void);
#define RT_ETRAP 11 /**< Trap event */
#define RT_ENOENT 12 /**< No entry */
#define RT_ENOSPC 13 /**< No space left */
#define RT_EINSCHE 14 /**< Scheduling in progress */

/**@}*/

Expand Down
12 changes: 6 additions & 6 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ static rt_err_t _rt_sem_take(rt_sem_t sem, rt_int32_t timeout, int suspend_flag)
thread = rt_thread_self();

/* reset thread error number */
thread->error = -RT_EINTR;
thread->error = RT_EOK;

RT_DEBUG_LOG(RT_DEBUG_IPC, ("sem take: suspend thread - %s\n",
thread->name));
Expand Down Expand Up @@ -1913,7 +1913,7 @@ static rt_err_t _rt_event_recv(rt_event_t event,
/* get current thread */
thread = rt_thread_self();
/* reset thread error */
thread->error = -RT_EINTR;
thread->error = RT_EOK;

RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(event->parent.parent)));

Expand Down Expand Up @@ -2388,7 +2388,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb,
while (mb->entry == mb->size)
{
/* reset error number in thread */
thread->error = -RT_EINTR;
thread->error = RT_EOK;

/* no waiting, return timeout */
if (timeout == 0)
Expand Down Expand Up @@ -2681,7 +2681,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo
while (mb->entry == 0)
{
/* reset error number in thread */
thread->error = -RT_EINTR;
thread->error = RT_EOK;

/* no waiting, return timeout */
if (timeout == 0)
Expand Down Expand Up @@ -3230,7 +3230,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
while ((msg = (struct rt_mq_message *)mq->msg_queue_free) == RT_NULL)
{
/* reset error number in thread */
thread->error = -RT_EINTR;
thread->error = RT_EOK;

/* no waiting, return timeout */
if (timeout == 0)
Expand Down Expand Up @@ -3583,7 +3583,7 @@ static rt_err_t _rt_mq_recv(rt_mq_t mq,
while (mq->entry == 0)
{
/* reset error number in thread */
thread->error = -RT_EINTR;
thread->error = RT_EOK;

/* no waiting, return timeout */
if (timeout == 0)
Expand Down
8 changes: 6 additions & 2 deletions src/kservice.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ static const char* rt_errno_strs[] =
"EIO",
"EINTRPT",
"EINVAL",
"ETRAP",
"ENOENT",
"ENOSPC",
"OK", /* EINSCHE is a temporary state, in fact no error. */
"EUNKNOW"
};

Expand All @@ -90,8 +94,8 @@ const char *rt_strerror(rt_err_t error)
if (error < 0)
error = -error;

return (error > RT_EINVAL + 1) ?
rt_errno_strs[RT_EINVAL + 1] :
return (error > RT_EINSCHE + 1) ?
rt_errno_strs[RT_EINSCHE + 1] :
rt_errno_strs[error];
}
RTM_EXPORT(rt_strerror);
Expand Down
10 changes: 10 additions & 0 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ void rt_schedule(void)
rt_base_t level;
struct rt_thread *to_thread;
struct rt_thread *from_thread;
struct rt_thread *from_thread_bak = rt_thread_self();

/* disable interrupt */
level = rt_hw_interrupt_disable();
Expand Down Expand Up @@ -522,6 +523,10 @@ void rt_schedule(void)

RT_OBJECT_HOOK_CALL(rt_scheduler_switch_hook, (from_thread));

// RT_ASSERT(from_thread_bak->error == RT_EOK);
/* Need schedule, set a temporary state, means scheduling in progress*/
from_thread_bak->error = -RT_EINSCHE;

rt_hw_context_switch((rt_ubase_t)&from_thread->sp,
(rt_ubase_t)&to_thread->sp);

Expand Down Expand Up @@ -569,6 +574,11 @@ void rt_schedule(void)
rt_hw_interrupt_enable(level);

__exit:

if (rt_thread_self()->error != RT_EOK && rt_thread_self()->error != -RT_ETIMEOUT)
{
rt_thread_self()->error = -RT_EINTR;
}
return;
}
#endif /* RT_USING_SMP */
Expand Down
2 changes: 1 addition & 1 deletion src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ rt_err_t rt_thread_sleep(rt_tick_t tick)
/* enable interrupt */
rt_hw_interrupt_enable(level);

thread->error = -RT_EINTR;
thread->error = RT_EOK;

rt_schedule();

Expand Down