1 // Asynchronous communicator
13 enum message_type { INFO, CREDIT, LOAD, CTRL_CLOSE, DATA_CLOSE };
15 message(message_type t, double a): type(t), amount(a) { }
17 message_type get_type() const { return type; }
18 double get_amount() const { return amount; }
20 std::string to_string();
32 // Start to listen for incoming messages
35 // Send a message to the "dest" mailbox
36 void send(const char* dest, message* msg);
38 // Try to receive a message. Returns true on success.
39 // If "wait" is true, blocks until success or error.
40 bool recv(message*& msg, m_host_t& from, bool wait);
42 // Try to flush pending sending communications.
43 // If "wait" is true, blocks until success.
44 void flush(bool wait);
46 // Advertise that the next "close" message is the last one, and
47 // that we do not await any message after that, either on the
48 // control or the data channel.
49 void next_close_on_ctrl_is_last();
50 void next_close_on_data_is_last();
56 // List of pending send communications
57 std::list<msg_comm_t> sent_comm;
58 static const int send_count_before_flush;
61 // Control channel for receiving
62 m_task_t ctrl_task; // receive buffer
63 msg_comm_t ctrl_comm; // receive communication
64 bool ctrl_close_is_last; // do not rearm comm after next close
66 // Data channel for receiving
67 m_task_t data_task; // receive buffer
68 msg_comm_t data_comm; // receive communication
69 bool data_close_is_last; // do not rearm comm after next close
71 const char* get_ctrl_mbox() const { return host->get_ctrl_mbox(); }
72 const char* get_data_mbox() const { return host->get_data_mbox(); }
74 // Used to test if a communication is over, and to destroy it if it is.
75 static bool comm_test_n_destroy(msg_comm_t comm);
78 #endif // !COMMUNICATOR_H