Kernel: Add basic nanosleep, only millisecond percision
This commit is contained in:
parent
b2139c0b1e
commit
9901f95d78
|
@ -68,6 +68,7 @@ namespace Kernel
|
|||
|
||||
BAN::ErrorOr<long> sys_wait(pid_t pid, int* stat_loc, int options);
|
||||
BAN::ErrorOr<long> sys_sleep(int seconds);
|
||||
BAN::ErrorOr<long> sys_nanosleep(const timespec* rqtp, timespec* rmtp);
|
||||
|
||||
BAN::ErrorOr<long> sys_setenvp(char** envp);
|
||||
|
||||
|
|
|
@ -529,6 +529,13 @@ namespace Kernel
|
|||
return 0;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_nanosleep(const timespec* rqtp, timespec* rmtp)
|
||||
{
|
||||
(void)rmtp;
|
||||
SystemTimer::get().sleep(rqtp->tv_sec * 1000 + BAN::Math::div_round_up<uint64_t>(rqtp->tv_nsec, 1'000'000));
|
||||
return 0;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_setenvp(char** envp)
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
|
|
|
@ -182,6 +182,9 @@ namespace Kernel
|
|||
case SYS_FCNTL:
|
||||
ret = Process::current().sys_fcntl((int)arg1, (int)arg2, (int)arg3);
|
||||
break;
|
||||
case SYS_NANOSLEEP:
|
||||
ret = Process::current().sys_nanosleep((const timespec*)arg1, (timespec*)arg2);
|
||||
break;
|
||||
default:
|
||||
dwarnln("Unknown syscall {}", syscall);
|
||||
break;
|
||||
|
|
|
@ -51,6 +51,7 @@ __BEGIN_DECLS
|
|||
#define SYS_GET_PGID 44
|
||||
#define SYS_SET_PGID 45
|
||||
#define SYS_FCNTL 46
|
||||
#define SYS_NANOSLEEP 47
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -5,4 +5,9 @@
|
|||
int clock_gettime(clockid_t clock_id, struct timespec* tp)
|
||||
{
|
||||
return syscall(SYS_CLOCK_GETTIME, clock_id, tp);
|
||||
}
|
||||
|
||||
int nanosleep(const struct timespec* rqtp, struct timespec* rmtp)
|
||||
{
|
||||
return syscall(SYS_NANOSLEEP, rqtp, rmtp);
|
||||
}
|
Loading…
Reference in New Issue