summaryrefslogtreecommitdiffstats
path: root/osdep/timer-linux.c
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-09-10 02:09:28 +0200
committerDudemanguy <random342@airmail.cc>2023-09-29 20:48:58 +0000
commit9606c3fca9d568dc43711017dcb35a408c0d2883 (patch)
tree6261962679c5b86514dc0e08193daed9ecd5fa03 /osdep/timer-linux.c
parent40e0fea6ebede9452a430cfd6d39bf132e89472d (diff)
downloadmpv-9606c3fca9d568dc43711017dcb35a408c0d2883.tar.bz2
mpv-9606c3fca9d568dc43711017dcb35a408c0d2883.tar.xz
timer: teach it about nanoseconds
Those changes will alow to change vsync base to more precise time base. In general there is no reason to truncate values returned by system.
Diffstat (limited to 'osdep/timer-linux.c')
-rw-r--r--osdep/timer-linux.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/osdep/timer-linux.c b/osdep/timer-linux.c
index 281a6013f3..0289233695 100644
--- a/osdep/timer-linux.c
+++ b/osdep/timer-linux.c
@@ -18,10 +18,8 @@
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <unistd.h>
#include <stdlib.h>
#include <time.h>
-#include <sys/time.h>
#include "timer.h"
void mp_sleep_us(int64_t us)
@@ -34,22 +32,16 @@ void mp_sleep_us(int64_t us)
nanosleep(&ts, NULL);
}
-#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && defined(CLOCK_MONOTONIC)
-uint64_t mp_raw_time_us(void)
+uint64_t mp_raw_time_ns(void)
{
- struct timespec ts;
- if (clock_gettime(CLOCK_MONOTONIC, &ts))
- abort();
- return ts.tv_sec * 1000000LL + ts.tv_nsec / 1000;
-}
+ struct timespec tp = {0};
+#if defined(CLOCK_MONOTONIC_RAW)
+ clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
#else
-uint64_t mp_raw_time_us(void)
-{
- struct timeval tv;
- gettimeofday(&tv,NULL);
- return tv.tv_sec * 1000000LL + tv.tv_usec;
-}
+ timespec_get(&tp, TIME_UTC);
#endif
+ return tp.tv_sec * UINT64_C(1000000000) + tp.tv_nsec;
+}
void mp_raw_time_init(void)
{