time.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include "stddef.h"
  3. // 操作系统定义时间以ns为单位
  4. #define CLOCKS_PER_SEC 1000000
  5. struct tm
  6. {
  7. int tm_sec; /* Seconds. [0-60] (1 leap second) */
  8. int tm_min; /* Minutes. [0-59] */
  9. int tm_hour; /* Hours. [0-23] */
  10. int tm_mday; /* Day. [1-31] */
  11. int tm_mon; /* Month. [0-11] */
  12. int tm_year; /* Year - 1900. */
  13. int tm_wday; /* Day of week. [0-6] */
  14. int tm_yday; /* Days in year.[0-365] */
  15. int tm_isdst; /* DST. [-1/0/1]*/
  16. long int __tm_gmtoff; /* Seconds east of UTC. */
  17. const char *__tm_zone; /* Timezone abbreviation. */
  18. };
  19. struct timespec
  20. {
  21. long int tv_sec; // 秒
  22. long long tv_nsec; // 纳秒
  23. };
  24. /**
  25. * @brief 休眠指定时间
  26. *
  27. * @param rqtp 指定休眠的时间
  28. * @param rmtp 返回的剩余休眠时间
  29. * @return int
  30. */
  31. extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
  32. /**
  33. * @brief 睡眠指定时间
  34. *
  35. * @param usec 微秒
  36. * @return int
  37. */
  38. extern int usleep(useconds_t usec);
  39. /**
  40. * @brief 获取当前的CPU时间
  41. *
  42. * @return uint64_t timer_jiffies
  43. */
  44. extern uint64_t clock();