🆕 usleep()、nanosleep()

This commit is contained in:
fslongjin
2022-07-12 12:01:51 +08:00
parent 4208c56074
commit 676260c537
21 changed files with 277 additions and 15 deletions

32
user/libs/libc/time.c Normal file
View File

@ -0,0 +1,32 @@
#include "time.h"
#include "errno.h"
#include "unistd.h"
#include <libsystem/syscall.h>
/**
* @brief 休眠指定时间
*
* @param rqtp 指定休眠的时间
* @param rmtp 返回的剩余休眠时间
* @return int
*/
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
return syscall_invoke(SYS_NANOSLEEP, (uint64_t)rqtp, (uint64_t)rmtp, 0, 0, 0, 0, 0, 0);
}
/**
* @brief 睡眠指定时间
*
* @param usec 微秒
* @return int
*/
int usleep(useconds_t usec)
{
struct timespec ts = {
tv_sec : (long int)(usec / 1000000),
tv_nsec : (long int)(usec % 1000000) * 1000UL
};
return nanosleep(&ts, NULL);
}