ArkSysTime.swift 545 B

1234567891011121314151617
  1. import CSystem
  2. extension ArkSys {
  3. public struct Time {
  4. /// Returns the current monotonic timestamp in milliseconds.
  5. public static func currentMs() -> UInt64 {
  6. var ts = timespec()
  7. clock_gettime(CLOCK_MONOTONIC, &ts)
  8. return UInt64(ts.tv_sec) * 1000 + UInt64(ts.tv_nsec) / 1_000_000
  9. }
  10. /// Suspends the current thread for the specified number of milliseconds.
  11. public static func sleep(ms: UInt64) {
  12. usleep(useconds_t(ms * 1000))
  13. }
  14. }
  15. }