1 // Asynchronous communicator
12 // Cannot include "options.h" without error, so only declare the
15 bool parse_args(int* argc, char* argv[]);
22 enum message_type { INFO, CREDIT, LOAD, CTRL_CLOSE, DATA_CLOSE };
24 message(message_type t, double a): type(t), amount(a) { }
26 message_type get_type() const { return type; }
27 double get_amount() const { return amount; }
29 std::string to_string();
41 // Send a message to the "dest" mailbox
42 void send(const char* dest, message* msg);
44 // Try to get a message. Returns true on success.
45 // If "wait" is true, blocks until success.
46 bool recv(message*& msg, m_host_t& from, bool wait);
48 // Try to flush pending sending communications.
49 // If "wait" is true, blocks until success.
50 void flush(bool wait);
56 // Used to synchronize main and receiver thread
60 // List of pending send communications
61 std::list<msg_comm_t> sent_comm;
63 // Queue of received messages
64 std::queue<m_task_t> received;
66 // Control channel for receiving
67 m_task_t ctrl_task; // receive buffer
68 msg_comm_t ctrl_comm; // receive communication
70 // Data channel for receiving
71 m_task_t data_task; // receive buffer
72 msg_comm_t data_comm; // receive communication
74 const char* get_ctrl_mbox() const { return host->get_ctrl_mbox(); }
75 const char* get_data_mbox() const { return host->get_data_mbox(); }
77 // Handling of receiving thread
78 m_process_t receiver_process;
79 static int receiver_wrapper(int, char* []);
82 // Used to test if a communication is over, and to destroy it if it is
83 static bool comm_test_n_destroy(msg_comm_t comm);
86 #endif // !COMMUNICATOR_H