1
0

worker.h 864 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef _WORKER_HPP_
  2. #define _WORKER_HPP_
  3. #include <ev++.h>
  4. struct task
  5. {
  6. uint32_t m_cmd_code;
  7. uint32_t m_hash_id;
  8. char m_d[1];
  9. void destroy()
  10. {
  11. free(this);
  12. }
  13. template<typename T> const T&body()const
  14. {
  15. const void*x=&m_d[0];
  16. return *(T*)x;
  17. }
  18. template<typename T> T&body()
  19. {
  20. void*x=&m_d[0];
  21. return *(T*)x;
  22. }
  23. static size_t align(size_t n)
  24. {
  25. return (n+31)&~0x1F;
  26. }
  27. template<typename T> static task*alloc()
  28. {
  29. return (task*)malloc(align(sizeof(T)+sizeof(task)));
  30. }
  31. };
  32. struct area_business;
  33. struct message_change_business
  34. {
  35. int area_id;
  36. std::atomic<int> ref_count;
  37. std::vector<area_business*> del_list,add_list,new_list;
  38. };
  39. struct worker
  40. {
  41. virtual void stop()=0;
  42. virtual void request(task*tk)=0;
  43. virtual void broadcast(task*tk)
  44. {
  45. }
  46. virtual int num_thread()
  47. {
  48. return 1;
  49. }
  50. static worker*instance();
  51. };
  52. #endif