1 // Asynchronous communicator
7 #include <simgrid/msg.h>
10 #include "msg_thread.h"
11 #include "simgrid_features.h"
18 // Send a message to the "dest" mailbox
19 void ctrl_send(const char* dest, message* msg) {
20 ctrl_sent.push_back(real_send(dest, msg));
22 void data_send(const char* dest, message* msg) {
23 data_sent.push_back(real_send(dest, msg));
26 // Try to flush pending sending communications.
27 // If "wait" is true, blocks until success.
28 void ctrl_flush(bool wait) {
29 real_flush(ctrl_sent, wait);
31 void data_flush(bool wait) {
32 real_flush(data_sent, wait);
35 // Flush all sending_communications. Blocking.
38 // Try to get a message. Returns true on success.
39 // Parameter "timeout" may be 0 for non-blocking operation, -1 for
40 // infinite waiting, or any positive timeout.
41 bool ctrl_recv(message*& msg, msg_host_t& from, double timeout) {
42 return ctrl_received.pop(msg, from, timeout);
44 bool data_recv(message*& msg, msg_host_t& from, double timeout) {
45 return data_received.pop(msg, from, timeout);
52 // List of pending send communications
53 typedef std::vector<msg_comm_t> sent_comm_type;
54 sent_comm_type ctrl_sent;
55 sent_comm_type data_sent;
57 msg_comm_t real_send(const char* dest, message* msg);
58 void real_flush(sent_comm_type& sent_comm, bool wait);
60 // Queues of received messages
61 message_queue ctrl_received;
62 message_queue data_received;
64 // Handling of receiving thread
65 msg_thread* receiver_thread;
68 // Used to chek if a communication is successfull before destroying it
69 static void comm_check_n_destroy(msg_comm_t comm);
70 // If comm is over, call comm_check_n_destroy(comm), and return true
71 static bool comm_test_n_destroy(msg_comm_t comm);
74 #endif // !COMMUNICATOR_H