central_control_data_buffer.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using tool;
  7. namespace chutian_parking_terminal.data_buffer
  8. {
  9. class Central_control_data_buffer:Singleton<Central_control_data_buffer>
  10. {
  11. private Central_control_data_buffer()
  12. {
  13. }
  14. public void central_control_data_buffer_init()
  15. {
  16. m_storing_process_statu_msg = new Message.Storing_process_statu_msg();
  17. m_picking_process_statu_msg = new Message.Picking_process_statu_msg();
  18. m_has_storing_process_statu_msg = false;
  19. m_has_picking_process_statu_msg = false;
  20. }
  21. public bool has_storing_process_statu_msg()
  22. {
  23. return m_has_storing_process_statu_msg;
  24. }
  25. public bool has_picking_process_statu_msg()
  26. {
  27. return m_has_picking_process_statu_msg;
  28. }
  29. //设置2条消息
  30. public void set_storing_process_statu_msg(Message.Storing_process_statu_msg msg)
  31. {
  32. lock (m_data_lock)
  33. {
  34. m_storing_process_statu_msg = msg;
  35. }
  36. m_has_storing_process_statu_msg = true;
  37. }
  38. public void set_picking_process_statu_msg(Message.Picking_process_statu_msg msg)
  39. {
  40. lock (m_data_lock)
  41. {
  42. m_picking_process_statu_msg = msg;
  43. }
  44. m_has_picking_process_statu_msg = true;
  45. }
  46. //获取2条消息
  47. public Message.Storing_process_statu_msg get_storing_process_statu_msg()
  48. {
  49. lock (m_data_lock)
  50. {
  51. return m_storing_process_statu_msg;
  52. }
  53. }
  54. public Message.Picking_process_statu_msg get_picking_process_statu_msg()
  55. {
  56. lock (m_data_lock)
  57. {
  58. return m_picking_process_statu_msg;
  59. }
  60. }
  61. //数据锁
  62. //作用:将会锁住代码块的内容,并阻止其他线程进入该代码块,直到该代码块运行完成,释放该锁。
  63. //注意:定义的锁对象应该是 私有的,静态的,只读的,引用类型的对象,这样可以防止外部改变锁对象
  64. private static readonly object m_data_lock = new object();
  65. //停车流程消息
  66. private Message.Storing_process_statu_msg m_storing_process_statu_msg;
  67. //取车流程消息
  68. private Message.Picking_process_statu_msg m_picking_process_statu_msg;
  69. //是否被赋值过(是否是有效数据)
  70. private bool m_has_storing_process_statu_msg;
  71. private bool m_has_picking_process_statu_msg;
  72. }
  73. }