Forráskód Böngészése

V0.3.5
1、基本完成了时间轮定时器,但是一秒的误差有60多ms

Apple 5 hónapja
szülő
commit
0ff1196d53
3 módosított fájl, 25 hozzáadás és 6 törlés
  1. 2 2
      CMakeLists.txt
  2. 1 1
      demo/timer/CMakeLists.txt
  3. 22 3
      demo/timer/main.cpp

+ 2 - 2
CMakeLists.txt

@@ -142,9 +142,9 @@ file(GLOB GLOBAL_SRC
 # add_subdirectory(${CMAKE_SOURCE_DIR}/demo/mqtt)
 # add_subdirectory(${CMAKE_SOURCE_DIR}/demo/http)
 # add_subdirectory(${CMAKE_SOURCE_DIR}/demo/threadPool)
-add_subdirectory(${CMAKE_SOURCE_DIR}/demo/ftp)
+# add_subdirectory(${CMAKE_SOURCE_DIR}/demo/ftp)
 # add_subdirectory(${CMAKE_SOURCE_DIR}/demo/OneThread)
-# add_subdirectory(${CMAKE_SOURCE_DIR}/demo/timer)
+add_subdirectory(${CMAKE_SOURCE_DIR}/demo/timer)
 
 
 

+ 1 - 1
demo/timer/CMakeLists.txt

@@ -31,7 +31,7 @@ target_include_directories(${this_exe} PRIVATE
 
     ${CMAKE_CURRENT_SOURCE_DIR}
     ${CMAKE_SOURCE_DIR}/External/common/LightLog
-    ${CMAKE_SOURCE_DIR}/External/common/Logs
+    ${CMAKE_SOURCE_DIR}/External/common
     ${CMAKE_SOURCE_DIR}/External/common/FmtLog
     ${CMAKE_SOURCE_DIR}/External/common/Timer
     ${CMAKE_SOURCE_DIR}/External/common/ThreadPool

+ 22 - 3
demo/timer/main.cpp

@@ -1,14 +1,33 @@
 #include "widget.h"
 
 #include <QApplication>
-#include "loginit.h"
+#include "Logs/loginit.h"
+#include "spdlog/spdlog.h"
+#include "Timer/TWTimer.hpp"
 
+std::chrono::steady_clock::time_point lastTime = std::chrono::steady_clock::now();
+long count = 0;
+
+
+void print()
+{
+    std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
+    SPDLOG_INFO("count:{} 间隔: {} us",count, std::chrono::duration_cast<std::chrono::microseconds>(now - lastTime).count());
+    lastTime = now;
+    count++;
+}
 
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
     init_log();
-    Widget w;
-    w.show();
+
+    SPDLOG_INFO("********** Timer **********");
+
+    TimerWheel timer;
+    timer.Start();
+
+    timer.AddTask(1000, print, true);
+
     return a.exec();
 }