#ifndef TIMER_H #define TIMER_H #include #include #include #include #include #include #include class Timer { public: Timer(); Timer(const Timer& timer); ~Timer(); public: void start(int interval, std::function task); void startOnce(int delay, std::function task); void stop(); bool IsStop() const {return mStop;} bool mStop; private: std::atomic _expired; // timer stopped status std::atomic _try_to_expire; // timer is in stop process std::mutex _mutex; std::condition_variable _expired_cond; }; #endif // TIMER_H