| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- #ifndef __SCHEDULER_H__
- #define __SCHEDULER_H__
- #include <boost\bind.hpp>
- #include <chrono>
- #include <thread>
- #include <boost/asio.hpp>
- #include <atomic>
- #include <shared_mutex>
- class CScheduler
- {
- typedef CScheduler this_type;
- public:
- CScheduler();
- CScheduler(boost::asio::io_service& ios);
- ~CScheduler();
- void setTimer(const std::int32_t& nIDEvent, const std::int32_t& uElapse);
- void killTimer();
- typedef std::function<void(std::int32_t)> FimeFunCB;
- void setOnTimeFuncCB(FimeFunCB fun) ;
- private:
- void __onTimer();
- private:
- boost::asio::io_service m_ios;
- boost::asio::io_service::work work;
- boost::asio::steady_timer timer_; // 定时器
- std::unique_ptr<std::thread> m_pThread;// 异步线程
- std::int32_t m_DuratTime; // 定时器间隔,单位毫秒
- std::atomic_bool m_IsStop; // 定时器是否关闭
- std::shared_mutex m_IsStopLock; //
- FimeFunCB m_FunCB; //
- std::int32_t m_TimeId; // 定时器ID
- };
- #endif
|