time_linux.odin 743 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package time
  2. import "core:sys/linux"
  3. _IS_SUPPORTED :: true
  4. _now :: proc "contextless" () -> Time {
  5. time_spec_now, _ := linux.clock_gettime(.REALTIME)
  6. ns := time_spec_now.time_sec * 1e9 + time_spec_now.time_nsec
  7. return Time{_nsec=i64(ns)}
  8. }
  9. _sleep :: proc "contextless" (d: Duration) {
  10. ds := duration_seconds(d)
  11. seconds := uint(ds)
  12. nanoseconds := uint((ds - f64(seconds)) * 1e9)
  13. ts := linux.Time_Spec{
  14. time_sec = seconds,
  15. time_nsec = nanoseconds,
  16. }
  17. for {
  18. if linux.nanosleep(&ts, &ts) != .EINTR {
  19. break
  20. }
  21. }
  22. }
  23. _tick_now :: proc "contextless" () -> Tick {
  24. t, _ := linux.clock_gettime(.MONOTONIC_RAW)
  25. return Tick{_nsec = i64(t.time_sec*1e9 + t.time_nsec)}
  26. }
  27. _yield :: proc "contextless" () {
  28. linux.sched_yield()
  29. }