Skip to content

[sleep] 加入调度器尚未运行时的延时情况 #4800

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 1 commit into from
Jun 16, 2021
Merged
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
24 changes: 16 additions & 8 deletions components/libc/compilers/common/unistd.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,26 @@ RTM_EXPORT(isatty);

char *ttyname(int fd)
{
return "/dev/tty"; /*TODO: need to add more specific*/
return "/dev/tty"; /* TODO: need to add more specific */
}
RTM_EXPORT(ttyname);

unsigned int sleep(unsigned int seconds)
{
rt_tick_t delta_tick;

delta_tick = rt_tick_get();
rt_thread_delay(seconds * RT_TICK_PER_SECOND);
delta_tick = rt_tick_get() - delta_tick;
if (rt_thread_self() != RT_NULL)
{
rt_thread_delay(seconds * RT_TICK_PER_SECOND);
}
else /* scheduler has not run yet */
{
while(seconds > 0)
{
rt_hw_us_delay(1000000u);
seconds --;
}
}

return seconds - delta_tick/RT_TICK_PER_SECOND;
return 0;
}
RTM_EXPORT(sleep);

Expand All @@ -59,11 +66,12 @@ int usleep(useconds_t usec)
{
rt_thread_mdelay(usec / 1000u);
}
else
else /* scheduler has not run yet */
{
rt_hw_us_delay(usec / 1000u);
}
rt_hw_us_delay(usec % 1000u);

return 0;
}
RTM_EXPORT(usleep);
Expand Down