#include #include #include #include #include #include #include #include #include #define EV_MULTIPLICITY 1 #define EV_SIGNAL_ENABLE 1 #define EV_ASYNC_ENABLE 1 #define EV_USE_FLOOR 1 #include #include #include #include #include struct io_thread:ev::dynamic_loop { std::atomic m_stop_flag{false}; std::thread*m_thread; ev::async m_async; ev::io m_io; ev::timer m_timer; uint64_t m_count; io_thread () { m_count=0; //异步 m_async.set(*this); m_async.set(this); m_async.start(); //tiemr.. //set loop m_timer.set(*this); m_timer.set(this); m_thread=new std::thread(std::bind(&io_thread::run,this)); m_timer.start(2,0); } void on_async() { if(m_stop_flag.load()) ev::dynamic_loop::break_loop(ev::ALL); ++m_count; //std_info("on_async%d:%d",std::this_thread::get_id(),m_count); } void on_timer() { //std_info("on_timer...."); m_timer.start(2,0); } void run() { dynamic_loop::run(0); //log_info("thread exit."); //std_info("thread exit.%d",std::this_thread::get_id()); } void destroy() { m_thread->join(); delete this; } void notify(int i) { if(i==0) { m_stop_flag.store(true); } m_async.send(); } private: ~io_thread() { delete m_thread; } }; int main() { // log_init("log.ini"); std::vector ivec; const int NUM_THREAD=4; for(int i=0;inotify(i); } if((i-1)%1000==0 && c.count_ms()>1000) { std_info("tps=%ld,all=%ld",tps,atps); tps=0; c.reset(); } } std::for_each(ivec.begin(),ivec.end(),[](io_thread*i){ i->notify(0); i->destroy(); std_info("thread_counter=%d",i->m_count); }); return 0; }