12345678910111213141516171819202122232425262728293031323334 |
- #include <kernel.h>
- #include <ksched.h>
- #include <wait_q.h>
- #include <posix/time.h>
- #ifdef CONFIG_POSIX_CLOCK
- int64_t timespec_to_timeoutms(const struct timespec *abstime)
- {
- int64_t milli_secs, secs, nsecs;
- struct timespec curtime;
-
- clock_gettime(CLOCK_MONOTONIC, &curtime);
- secs = abstime->tv_sec - curtime.tv_sec;
- nsecs = abstime->tv_nsec - curtime.tv_nsec;
- if (secs < 0 || (secs == 0 && nsecs < NSEC_PER_MSEC)) {
- milli_secs = 0;
- } else {
- milli_secs = secs * MSEC_PER_SEC + nsecs / NSEC_PER_MSEC;
- }
- return milli_secs;
- }
- #endif
|