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 // Parameter "timeout" may be 0 for non-blocking operation, -1 for
38 // infinite waiting, or any positive timeout.
39 bool recv(message*& msg, m_host_t& from, double timeout);
41 // Try to flush pending sending communications.
42 // If "wait" is true, blocks until success.
43 void flush(bool wait);
49 // Used to synchronize main and receiver thread
53 // List of pending send communications
54 std::list<msg_comm_t> sent_comm;
56 // Queue of received messages
57 std::queue<m_task_t> received;
59 // Control channel for receiving
60 m_task_t ctrl_task; // receive buffer
61 msg_comm_t ctrl_comm; // receive communication
63 // Data channel for receiving
64 m_task_t data_task; // receive buffer
65 msg_comm_t data_comm; // receive communication
67 const char* get_ctrl_mbox() const { return host->get_ctrl_mbox(); }
68 const char* get_data_mbox() const { return host->get_data_mbox(); }
70 // Handling of receiving thread
71 m_process_t receiver_process;
72 static int receiver_wrapper(int, char* []);
75 // Used to test if a communication is over, and to destroy it if it is
76 static bool comm_test_n_destroy(msg_comm_t comm);
79 #endif // !COMMUNICATOR_H