#pragma once #include "sol/sol.hpp" #include "core/structs.h" #include "util/thread.h" #include "util/queue.hpp" #include "module/basemodule.h" #include #include namespace module { struct timer_info { std::string filepath; std::string name; timestamp exec_msec = 0; timestamp msec = 0; sol::function function; }; /// /// 定时器 /// class timer:private ylib::ithread,public module::base { public: timer(); ~timer(); /// /// 增加 /// /// /// /// /// /// std::string add(const std::string& name,const std::string& filepath,int msec, sol::this_state ts); /// /// 移除 /// /// void remove(const std::string& name, sol::this_state ts); static void regist(sol::state* lua); virtual void regist_global(const char* name, sol::state* lua) override; virtual void delete_global() { delete this; } private: virtual bool run(); public: fastweb::app* m_app = nullptr; std::map m_list; ylib::queue m_removed; std::mutex m_mutex; bool m_insert = false; }; }