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 // Handling of receiving thread
56 xbt_mutex_t receiver_mutex;
57 xbt_cond_t receiver_cond;
58 m_process_t receiver_thread;
59 static int receiver_wrapper(int, char* []);
62 // Used to chek if a communication is successfull before destroying it
63 static void comm_check_n_destroy(msg_comm_t comm);
64 // If comm is over, call comm_check_n_destroy(comm), and return true
65 static bool comm_test_n_destroy(msg_comm_t comm);
68 #endif // !COMMUNICATOR_H