summaryrefslogtreecommitdiff
path: root/components/libc/compilers/common
diff options
context:
space:
mode:
authorzms123456 <[email protected]>2024-04-22 11:55:20 +0800
committerGitHub <[email protected]>2024-04-22 11:55:20 +0800
commit5ca1e450204f2b11de5c5e2f1b09a90a6b2d4d96 (patch)
tree332484679f5764dd95402c8a13663340868ec43d /components/libc/compilers/common
parentf13220d91111bbb48abaae26507917c2fc9c6d12 (diff)
[components][drivers]improve ktimer sleep (#8838)
improve ktimer sleep
Diffstat (limited to 'components/libc/compilers/common')
-rw-r--r--components/libc/compilers/common/ctime.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/components/libc/compilers/common/ctime.c b/components/libc/compilers/common/ctime.c
index c6602698ff..79d7010034 100644
--- a/components/libc/compilers/common/ctime.c
+++ b/components/libc/compilers/common/ctime.c
@@ -530,6 +530,9 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
struct timespec old_ts = {0};
struct timespec new_ts = {0};
+ struct rt_ktime_hrtimer timer;
+
+ rt_ktime_hrtimer_delay_init(&timer);
if (rqtp == RT_NULL)
{
@@ -544,7 +547,7 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
}
unsigned long ns = rqtp->tv_sec * NANOSECOND_PER_SECOND + rqtp->tv_nsec;
rt_ktime_boottime_get_ns(&old_ts);
- rt_ktime_hrtimer_ndelay(ns);
+ rt_ktime_hrtimer_ndelay(&timer, ns);
if (rt_get_errno() == RT_EINTR)
{
if (rmtp)
@@ -565,9 +568,13 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
rmtp->tv_nsec = rnsec;
}
}
+
+ rt_ktime_hrtimer_delay_detach(&timer);
rt_set_errno(EINTR);
return -1;
}
+
+ rt_ktime_hrtimer_delay_detach(&timer);
return 0;
}
RTM_EXPORT(nanosleep);