7#include "libxr_def.hpp"
11extern struct timeval libxr_linux_start_time;
12extern struct timespec libxr_linux_start_time_spec;
19 ts.tv_sec = milliseconds / 1000;
20 ts.tv_nsec =
static_cast<__syscall_slong_t
>((milliseconds % 1000) * 1000000);
21 UNUSED(clock_nanosleep(CLOCK_REALTIME, 0, &ts,
nullptr));
26 last_waskup_time = last_waskup_time + time_to_sleep;
28 struct timespec ts = libxr_linux_start_time_spec;
30 uint32_t secs = last_waskup_time / 1000;
31 int64_t raw_time =
static_cast<int64_t
>(last_waskup_time) * 1000U * 1000U;
32 add = raw_time / (
static_cast<int64_t
>(1000U * 1000U * 1000U));
33 ts.tv_sec += (add + secs);
34 ts.tv_nsec = raw_time % (
static_cast<int64_t
>(1000U * 1000U * 1000U));
36 while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, &ts) && errno == EINTR)
44 gettimeofday(&tv,
nullptr);
45 return ((tv.tv_sec - libxr_linux_start_time.tv_sec) * 1000 +
46 (tv.tv_usec - libxr_linux_start_time.tv_usec) / 1000) %
表示毫秒级时间戳的类。Class representing a timestamp in milliseconds.
线程管理类,封装 POSIX 线程创建和调度 Thread management class encapsulating POSIX thread creation and scheduling
Thread()
默认构造函数,初始化空线程 Default constructor initializing an empty thread
static uint32_t GetTime()
获取当前系统时间(毫秒) Gets the current system time in milliseconds
static void SleepUntil(MillisecondTimestamp &last_waskup_time, uint32_t time_to_sleep)
让线程休眠直到指定时间点 Puts the thread to sleep until a specified time
static Thread Current(void)
获取当前线程对象 Gets the current thread object
static void Sleep(uint32_t milliseconds)
让线程进入休眠状态 Puts the thread to sleep
static void Yield()
让出 CPU 以执行其他线程 Yields CPU execution to allow other threads to run