1 // Asynchronous communicator
14 enum message_type { INFO, CREDIT, LOAD, CTRL_CLOSE, DATA_CLOSE };
16 message(message_type t, double a): type(t), amount(a) { }
18 message_type get_type() const { return type; }
19 double get_amount() const { return amount; }
21 std::string to_string();
33 // Send a message to the "dest" mailbox
34 void send(const char* dest, message* msg);
36 // Try to get a message. Returns true on success.
37 // If "wait" is true, blocks until success.
38 bool recv(message*& msg, m_host_t& from, bool wait);
40 // Try to flush pending sending communications.
41 // If "wait" is true, blocks until success.
42 void flush(bool wait);
48 // Used to synchronize main and receiver thread
52 // List of pending send communications
53 std::list<msg_comm_t> sent_comm;
55 // Queue of received messages
56 std::queue<m_task_t> received;
58 // Control channel for receiving
59 m_task_t ctrl_task; // receive buffer
60 msg_comm_t ctrl_comm; // receive communication
62 // Data channel for receiving
63 m_task_t data_task; // receive buffer
64 msg_comm_t data_comm; // receive communication
66 const char* get_ctrl_mbox() const { return host->get_ctrl_mbox(); }
67 const char* get_data_mbox() const { return host->get_data_mbox(); }
69 // Handling of receiving thread
70 m_process_t receiver_process;
71 static int receiver_wrapper(int, char* []);
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