#ifndef _WORKER_HPP_ #define _WORKER_HPP_ #include #include #include #include #include struct task { uint32_t m_cmd_code; uint32_t m_hash_id; task(uint32_t hash_id,uint32_t cmd_code) :m_cmd_code(cmd_code) ,m_hash_id(hash_id) { } task() {} void destroy() { delete this; } template const T&body()const { return *(T*)this; } template T&body() { return *(T*)this; } template static task*alloc() { return new T(); } virtual ~task(){} }; struct area_business; struct message_change_business:task { int area_id; std::atomic ref_count; std::vector del_list,add_list,new_list; }; struct message_change_card_display:task { uint64_t m_card_id; uint16_t m_display; }; struct worker { virtual void stop()=0; virtual void request(task*tk)=0; virtual void broadcast(task*tk) { } virtual int num_thread() { return 1; } static worker*instance(); }; struct loop_thread:zloop { std::unique_ptr m_thread; loop_thread (); ~loop_thread(); void run(); void stop(); void join(); void on_async(const std::list&task_list); virtual void loop_init(); virtual void do_task(task&t)=0; }; #endif