time.c 817 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "time.h"
  2. #include "errno.h"
  3. #include "unistd.h"
  4. #include <libsystem/syscall.h>
  5. /**
  6. * @brief 休眠指定时间
  7. *
  8. * @param rqtp 指定休眠的时间
  9. * @param rmtp 返回的剩余休眠时间
  10. * @return int
  11. */
  12. int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
  13. {
  14. return syscall_invoke(SYS_NANOSLEEP, (uint64_t)rqtp, (uint64_t)rmtp, 0, 0, 0, 0, 0, 0);
  15. }
  16. /**
  17. * @brief 睡眠指定时间
  18. *
  19. * @param usec 微秒
  20. * @return int
  21. */
  22. int usleep(useconds_t usec)
  23. {
  24. struct timespec ts = {
  25. tv_sec : (long int)(usec / 1000000),
  26. tv_nsec : (long int)(usec % 1000000) * 1000UL
  27. };
  28. return nanosleep(&ts, NULL);
  29. }
  30. /**
  31. * @brief 获取系统当前cpu时间
  32. *
  33. * @return clock_t
  34. */
  35. clock_t clock()
  36. {
  37. return (clock_t)syscall_invoke(SYS_CLOCK, 0,0,0,0,0,0,0,0);
  38. }