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;
62 static int send_count_before_flush;
65 // Queue of received messages
66 std::queue<m_task_t> received;
68 // Control channel for receiving
69 m_task_t ctrl_task; // receive buffer
70 msg_comm_t ctrl_comm; // receive communication
72 // Data channel for receiving
73 m_task_t data_task; // receive buffer
74 msg_comm_t data_comm; // receive communication
76 const char* get_ctrl_mbox() const { return host->get_ctrl_mbox(); }
77 const char* get_data_mbox() const { return host->get_data_mbox(); }
79 // Handling of receiving thread
80 m_process_t receiver_process;
81 static int receiver_wrapper(int, char* []);
84 // Used to test if a communication is over, and to destroy it if it is
85 static bool comm_test_n_destroy(msg_comm_t comm);
87 // Make opt::* functions our friends to provide them an access to
88 // send_count_before_flush
89 friend bool opt::parse_args(int*, char* []);
90 friend void opt::print();
91 friend void opt::usage();
94 #endif // !COMMUNICATOR_H