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 // List of pending send communications
50 std::list<msg_comm_t> sent_comm;
52 // Queue of received messages
53 std::queue<m_task_t> received;
55 // Control channel for receiving
56 m_task_t ctrl_task; // receive buffer
57 msg_comm_t ctrl_comm; // receive communication
59 // Data channel for receiving
60 m_task_t data_task; // receive buffer
61 msg_comm_t data_comm; // receive communication
63 const char* get_ctrl_mbox() const { return host->get_ctrl_mbox(); }
64 const char* get_data_mbox() const { return host->get_data_mbox(); }
66 // Handling of receiving thread
67 xbt_mutex_t receiver_mutex;
68 xbt_cond_t receiver_cond;
69 m_process_t receiver_thread;
70 static int receiver_wrapper(int, char* []);
71 void receiver1(msg_comm_t& comm, m_task_t& task, const char* mbox);
74 // Used to chek if a communication is successfull before destroying it
75 static void comm_check_n_destroy(msg_comm_t comm);
76 // If comm is over, call comm_check_n_destroy(comm), and return true
77 static bool comm_test_n_destroy(msg_comm_t comm);
80 #endif // !COMMUNICATOR_H