using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using tool; namespace chutian_parking_terminal.data_buffer { class Central_control_data_buffer:Singleton { private Central_control_data_buffer() { } public void central_control_data_buffer_init() { m_storing_process_statu_msg = new Message.Storing_process_statu_msg(); m_picking_process_statu_msg = new Message.Picking_process_statu_msg(); m_has_storing_process_statu_msg = false; m_has_picking_process_statu_msg = false; } public bool has_storing_process_statu_msg() { return m_has_storing_process_statu_msg; } public bool has_picking_process_statu_msg() { return m_has_picking_process_statu_msg; } //设置2条消息 public void set_storing_process_statu_msg(Message.Storing_process_statu_msg msg) { lock (m_data_lock) { m_storing_process_statu_msg = msg; } m_has_storing_process_statu_msg = true; } public void set_picking_process_statu_msg(Message.Picking_process_statu_msg msg) { lock (m_data_lock) { m_picking_process_statu_msg = msg; } m_has_picking_process_statu_msg = true; } //获取2条消息 public Message.Storing_process_statu_msg get_storing_process_statu_msg() { lock (m_data_lock) { return m_storing_process_statu_msg; } } public Message.Picking_process_statu_msg get_picking_process_statu_msg() { lock (m_data_lock) { return m_picking_process_statu_msg; } } //数据锁 //作用:将会锁住代码块的内容,并阻止其他线程进入该代码块,直到该代码块运行完成,释放该锁。 //注意:定义的锁对象应该是 私有的,静态的,只读的,引用类型的对象,这样可以防止外部改变锁对象 private static readonly object m_data_lock = new object(); //停车流程消息 private Message.Storing_process_statu_msg m_storing_process_statu_msg; //取车流程消息 private Message.Picking_process_statu_msg m_picking_process_statu_msg; //是否被赋值过(是否是有效数据) private bool m_has_storing_process_statu_msg; private bool m_has_picking_process_statu_msg; } }