Skip to content

add RT_DEBUG_SCHEDULER_AVAILABLE check. #4740

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion components/dfs/filesystems/devfs/devfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,34 @@ int dfs_device_fs_open(struct dfs_fd *file)
{
count ++;
}
rt_exit_critical();

root_dirent = (struct device_dirent *)rt_malloc(sizeof(struct device_dirent) +
count * sizeof(rt_device_t));
if (root_dirent != RT_NULL)
{
/* lock scheduler */
rt_enter_critical();

root_dirent->devices = (rt_device_t *)(root_dirent + 1);
root_dirent->read_index = 0;
root_dirent->device_count = count;
count = 0;
/* get all device node */
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
{
/* avoid memory write through */
if (count == root_dirent->device_count)
{
rt_kprintf("warning: There are newly added devices that are not displayed!");
break;
}
object = rt_list_entry(node, struct rt_object, list);
root_dirent->devices[count] = (rt_device_t)object;
count ++;
}
rt_exit_critical();
}
rt_exit_critical();

/* set data */
file->data = root_dirent;
Expand Down
6 changes: 3 additions & 3 deletions components/drivers/ipc/completion.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
rt_thread_t thread;
RT_ASSERT(completion != RT_NULL);

/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);

result = RT_EOK;
thread = rt_thread_self();

Expand All @@ -82,9 +85,6 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
rt_list_insert_before(&(completion->suspended_list),
&(thread->tlist));

/* current context checking */
RT_DEBUG_NOT_IN_INTERRUPT;

/* start timer */
if (timeout > 0)
{
Expand Down
12 changes: 6 additions & 6 deletions components/drivers/ipc/dataqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
RT_ASSERT(queue != RT_NULL);
RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);

/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);

result = RT_EOK;
thread = rt_thread_self();

Expand All @@ -112,9 +115,6 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
goto __exit;
}

/* current context checking */
RT_DEBUG_NOT_IN_INTERRUPT;

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

Expand Down Expand Up @@ -217,6 +217,9 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
RT_ASSERT(data_ptr != RT_NULL);
RT_ASSERT(size != RT_NULL);

/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);

result = RT_EOK;
thread = rt_thread_self();

Expand All @@ -230,9 +233,6 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
goto __exit;
}

/* current context checking */
RT_DEBUG_NOT_IN_INTERRUPT;

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

Expand Down
2 changes: 1 addition & 1 deletion components/drivers/ipc/waitqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
rt_base_t level;

/* current context checking */
RT_DEBUG_NOT_IN_INTERRUPT;
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);

tick = rt_tick_from_millisecond(msec);

Expand Down
26 changes: 26 additions & 0 deletions include/rtdebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,34 @@ do \
rt_hw_interrupt_enable(level); \
} \
while (0)

/* "scheduler available" means:
* 1) the scheduler has been started.
* 2) not in interrupt context.
* 3) scheduler is not locked.
*/
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) \
do \
{ \
if (need_check) \
{ \
rt_base_t level; \
level = rt_hw_interrupt_disable(); \
if (rt_critical_level() != 0) \
{ \
rt_kprintf("Function[%s]: scheduler is not available\n", \
__FUNCTION__); \
RT_ASSERT(0) \
} \
RT_DEBUG_IN_THREAD_CONTEXT; \
rt_hw_interrupt_enable(level); \
} \
} \
while (0)
#else
#define RT_DEBUG_NOT_IN_INTERRUPT
#define RT_DEBUG_IN_THREAD_CONTEXT
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check)
#endif

#else /* RT_DEBUG */
Expand All @@ -121,6 +146,7 @@ while (0)
#define RT_DEBUG_LOG(type, message)
#define RT_DEBUG_NOT_IN_INTERRUPT
#define RT_DEBUG_IN_THREAD_CONTEXT
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check)

#endif /* RT_DEBUG */

Expand Down
31 changes: 20 additions & 11 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
RT_ASSERT(sem != RT_NULL);
RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore);

/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(time != 0);

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

/* disable interrupt */
Expand Down Expand Up @@ -514,9 +517,6 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
}
else
{
/* current context checking */
RT_DEBUG_IN_THREAD_CONTEXT;

/* semaphore is unavailable, push to suspend list */
/* get current thread */
thread = rt_thread_self();
Expand Down Expand Up @@ -912,7 +912,8 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
struct rt_thread *thread;

/* this function must not be used in interrupt even if time = 0 */
RT_DEBUG_IN_THREAD_CONTEXT;
/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);

/* parameter check */
RT_ASSERT(mutex != RT_NULL);
Expand Down Expand Up @@ -1566,12 +1567,13 @@ rt_err_t rt_event_recv(rt_event_t event,
register rt_ubase_t level;
register rt_base_t status;

RT_DEBUG_IN_THREAD_CONTEXT;

/* parameter check */
RT_ASSERT(event != RT_NULL);
RT_ASSERT(rt_object_get_type(&event->parent.parent) == RT_Object_Class_Event);

/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

郭老师,这个位置是RT_TRUE还是timeout != 0


if (set == 0)
return -RT_ERROR;

Expand Down Expand Up @@ -1993,6 +1995,9 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
RT_ASSERT(mb != RT_NULL);
RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox);

/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);

/* initialize delta tick */
tick_delta = 0;
/* get current thread */
Expand Down Expand Up @@ -2025,7 +2030,6 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
return -RT_EFULL;
}

RT_DEBUG_IN_THREAD_CONTEXT;
/* suspend current thread */
_ipc_list_suspend(&(mb->suspend_sender_thread),
thread,
Expand Down Expand Up @@ -2236,6 +2240,9 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout)
RT_ASSERT(mb != RT_NULL);
RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox);

/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);

/* initialize delta tick */
tick_delta = 0;
/* get current thread */
Expand Down Expand Up @@ -2271,7 +2278,6 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout)
return -RT_ETIMEOUT;
}

RT_DEBUG_IN_THREAD_CONTEXT;
/* suspend current thread */
_ipc_list_suspend(&(mb->parent.suspend_thread),
thread,
Expand Down Expand Up @@ -2744,6 +2750,9 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq,
RT_ASSERT(buffer != RT_NULL);
RT_ASSERT(size != 0);

/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);

/* greater than one message size */
if (size > mq->msg_size)
return -RT_ERROR;
Expand Down Expand Up @@ -2784,7 +2793,6 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq,
return -RT_EFULL;
}

RT_DEBUG_IN_THREAD_CONTEXT;
/* suspend current thread */
_ipc_list_suspend(&(mq->suspend_sender_thread),
thread,
Expand Down Expand Up @@ -3054,6 +3062,9 @@ rt_err_t rt_mq_recv(rt_mq_t mq,
RT_ASSERT(buffer != RT_NULL);
RT_ASSERT(size != 0);

/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);

/* initialize delta tick */
tick_delta = 0;
/* get current thread */
Expand All @@ -3074,8 +3085,6 @@ rt_err_t rt_mq_recv(rt_mq_t mq,
/* message queue is empty */
while (mq->entry == 0)
{
RT_DEBUG_IN_THREAD_CONTEXT;

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

Expand Down