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;
54 static const int send_count_before_flush;
57 // Queue of received messages
58 std::queue<m_task_t> received;
60 // Control channel for receiving
61 m_task_t ctrl_task; // receive buffer
62 msg_comm_t ctrl_comm; // receive communication
64 // Data channel for receiving
65 m_task_t data_task; // receive buffer
66 msg_comm_t data_comm; // receive communication
68 const char* get_ctrl_mbox() const { return host->get_ctrl_mbox(); }
69 const char* get_data_mbox() const { return host->get_data_mbox(); }
71 // Handling of receiving thread
72 m_process_t receiver_process;
73 static int receiver_wrapper(int, char* []);
76 // Used to test if a communication is over, and to destroy it if it is
77 static bool comm_test_n_destroy(msg_comm_t comm);
80 #endif // !COMMUNICATOR_H