中间件底层,websocket

Scheduler.h 913B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef __SCHEDULER_H__
  2. #define __SCHEDULER_H__
  3. #include <boost\bind.hpp>
  4. #include <chrono>
  5. #include <thread>
  6. #include <boost/asio.hpp>
  7. #include <atomic>
  8. #include <shared_mutex>
  9. class CScheduler
  10. {
  11. typedef CScheduler this_type;
  12. public:
  13. CScheduler();
  14. CScheduler(boost::asio::io_service& ios);
  15. ~CScheduler();
  16. void setTimer(const std::int32_t& nIDEvent, const std::int32_t& uElapse);
  17. void killTimer();
  18. typedef std::function<void(std::int32_t)> FimeFunCB;
  19. void setOnTimeFuncCB(FimeFunCB fun) ;
  20. private:
  21. void __onTimer();
  22. private:
  23. boost::asio::io_service m_ios;
  24. boost::asio::io_service::work work;
  25. boost::asio::steady_timer timer_; // 定时器
  26. std::unique_ptr<std::thread> m_pThread;// 异步线程
  27. std::int32_t m_DuratTime; // 定时器间隔,单位毫秒
  28. std::atomic_bool m_IsStop; // 定时器是否关闭
  29. std::shared_mutex m_IsStopLock; //
  30. FimeFunCB m_FunCB; //
  31. std::int32_t m_TimeId; // 定时器ID
  32. };
  33. #endif