summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-02 19:34:06 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-02 19:34:06 +0100
commitcc68654a44be00deb5edf3b2d2319a663012f015 (patch)
treebe559ccaa40533b6487c750b5ae052c50503b8c7 /Libraries
parent73b2cb9ed81124e294337738a323c2f28b0b64ec (diff)
downloadserenity-cc68654a44be00deb5edf3b2d2319a663012f015.zip
Kernel+LibC: Implement clock_gettime() and clock_nanosleep()
Only the CLOCK_MONOTONIC clock is supported at the moment, and it only has millisecond precision. :^)
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibC/time.cpp14
-rw-r--r--Libraries/LibC/time.h18
2 files changed, 27 insertions, 5 deletions
diff --git a/Libraries/LibC/time.cpp b/Libraries/LibC/time.cpp
index 6024664fed..8a301b3bb5 100644
--- a/Libraries/LibC/time.cpp
+++ b/Libraries/LibC/time.cpp
@@ -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);
+}
+
}
diff --git a/Libraries/LibC/time.h b/Libraries/LibC/time.h
index 0a720dadf4..fec9076e99 100644
--- a/Libraries/LibC/time.h
+++ b/Libraries/LibC/time.h
@@ -36,15 +36,23 @@ char* asctime(const struct tm*);
#define CLOCKS_PER_SEC 1000
clock_t clock();
+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)
-// This is c++11+, but we have no macro for that now.
-struct timespec {
- time_t tv_sec;
- long tv_nsec;
-};
__END_DECLS