1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:27:35 +00:00

Kernel+LibC: Implement clock_gettime() and clock_nanosleep()

Only the CLOCK_MONOTONIC clock is supported at the moment, and it only
has millisecond precision. :^)
This commit is contained in:
Andreas Kling 2019-11-02 19:34:06 +01:00
parent 73b2cb9ed8
commit cc68654a44
9 changed files with 127 additions and 7 deletions

View file

@ -117,4 +117,18 @@ clock_t clock()
times(&tms);
return tms.tms_utime + tms.tms_stime;
}
int clock_gettime(clockid_t clock_id, struct timespec* ts)
{
int rc = syscall(SC_clock_gettime, clock_id, ts);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec* requested_sleep, struct timespec* remaining_sleep)
{
Syscall::SC_clock_nanosleep_params params { clock_id, flags, requested_sleep, remaining_sleep };
int rc = syscall(SC_clock_nanosleep, &params);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
}

View file

@ -36,15 +36,23 @@ char* asctime(const struct tm*);
#define CLOCKS_PER_SEC 1000
clock_t clock();
double difftime(time_t, time_t);
size_t strftime(char* s, size_t max, const char* format, const struct tm*);
#define difftime(t1, t0) (double)(t1 - t0)
// This is c++11+, but we have no macro for that now.
struct timespec {
time_t tv_sec;
long tv_nsec;
};
typedef int clockid_t;
#define CLOCK_MONOTONIC 1
#define TIMER_ABSTIME 99
int clock_gettime(clockid_t, struct timespec*);
int clock_nanosleep(clockid_t, int flags, const struct timespec* requested_sleep, struct timespec* remaining_sleep);
double difftime(time_t, time_t);
size_t strftime(char* s, size_t max, const char* format, const struct tm*);
#define difftime(t1, t0) (double)(t1 - t0)
__END_DECLS