time.c 666 B

1234567891011121314151617181920212223242526272829303132
  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. }