#include #include "easy_timer.h" #include #define TICK_ONE_TIME 14 // 一个 tick 14ms #define MS_TO_TICK(ms) ((ms) / TICK_ONE_TIME) //创建一个windows线程 HANDLE thread; //延迟函数 static void sleep_func() { Sleep(1); } EXPORT_SLEEP_FUNC(sleep_func); void hello_world() { printf("hello world\n"); } EXPORT_EASY_TIMER_HANDLE(hello_world,TIMER_CONTINUE_TRIGGER, MS_TO_TICK(1000)); void hello_dog(){ printf("hello dog\n"); } EXPORT_EASY_TIMER_HANDLE(hello_dog,TIMER_CONTINUE_TRIGGER, MS_TO_TICK(1000)); void hello_once(){ printf("hello once\n"); } EXPORT_EASY_TIMER_HANDLE(hello_once,TIMER_SIGNAL_TRIGGER, MS_TO_TICK(1000)); /** * @brief 获取当前时间 * @return 时间 * @note 用于测量Sleep函数的精度 */ double get_time() { LARGE_INTEGER frequency; LARGE_INTEGER count; // 获取高精度计数器的频率 QueryPerformanceFrequency(&frequency); // 获取当前的高精度计数器值 QueryPerformanceCounter(&count); // 将计数器值转换为秒 return (double)count.QuadPart / (double)frequency.QuadPart; } //定义线程函数 DWORD WINAPI easy_timer_thread(LPVOID lpParam) { while (1) { easy_timer_core(); } return 0; } int main() { //创建线程 thread = CreateThread(NULL, 0, easy_timer_thread, NULL, 0, NULL); //启动线程 if (thread) { // printf("easy_timer_run start...\n"); WaitForSingleObject(thread, INFINITE); } return 0; }