XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_migration, "Messages specific for this s4u example");
-static void worker(simgrid::s4u::Host* first, simgrid::s4u::Host* second)
+static void worker(simgrid::s4u::Host* first, const simgrid::s4u::Host* second)
{
double flopAmount = first->get_speed() * 5 + second->get_speed() * 5;
}
/** Indicates if the remote peer has a piece not stored by the local peer */
-bool Peer::isInterestedBy(Connection* remote_peer)
+bool Peer::isInterestedBy(const Connection* remote_peer) const
{
return remote_peer->bitfield & (bitfield_ ^ ((1 << FILE_PIECES) - 1));
}
-bool Peer::isInterestedByFree(Connection* remote_peer)
+bool Peer::isInterestedByFree(const Connection* remote_peer) const
{
for (unsigned int i = 0; i < FILE_PIECES; i++)
if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i))
explicit Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::by_name(std::to_string(id))){};
void addSpeedValue(double speed) { peer_speed = peer_speed * 0.6 + speed * 0.4; }
- bool hasPiece(unsigned int piece) { return bitfield & 1U << piece; }
+ bool hasPiece(unsigned int piece) const { return bitfield & 1U << piece; }
};
class Peer {
std::string getStatus();
bool hasFinished();
int nbInterestedPeers();
- bool isInterestedBy(Connection* remote_peer);
- bool isInterestedByFree(Connection* remote_peer);
+ bool isInterestedBy(const Connection* remote_peer) const;
+ bool isInterestedByFree(const Connection* remote_peer) const;
void updateActivePeersSet(Connection* remote_peer);
void updateInterestedAfterReceive();
void updateChokedPeers();
- bool hasNotPiece(unsigned int piece) { return not(bitfield_ & 1U << piece); }
+ bool hasNotPiece(unsigned int piece) const { return not(bitfield_ & 1U << piece); }
bool hasCompletedPiece(unsigned int piece);
unsigned int countPieces(unsigned int bitfield);
/** Check that a piece is not currently being download by the peer. */
- bool isNotDownloadingPiece(unsigned int piece) { return not(current_pieces & 1U << piece); }
+ bool isNotDownloadingPiece(unsigned int piece) const { return not(current_pieces & 1U << piece); }
int partiallyDownloadedPiece(Connection* remote_peer);
void updatePiecesCountFromBitfield(unsigned int bitfield);
void removeCurrentPiece(Connection* remote_peer, unsigned int current_piece);
/** @brief Merge two answers together, only keeping the best nodes
* @param source the source of the nodes to add
*/
-unsigned int Answer::merge(Answer* source)
+unsigned int Answer::merge(const Answer* source)
{
if (this == source)
return 0;
std::vector<std::pair<unsigned int, unsigned int>> nodes;
explicit Answer(unsigned int destination_id) : destination_id_(destination_id) {}
virtual ~Answer() = default;
- unsigned int getDestinationId() { return destination_id_; }
+ unsigned int getDestinationId() const { return destination_id_; }
unsigned int getSize() { return size_; }
void print();
- unsigned int merge(Answer* a);
+ unsigned int merge(const Answer* a);
void trim();
bool destinationFound();
void addBucket(const kademlia::Bucket* bucket);
* Sends to the best "KADEMLIA_ALPHA" nodes in the "node_list" array a "FIND_NODE" request, to ask them for their best
* nodes
*/
-unsigned int Node::sendFindNodeToBest(Answer* node_list)
+unsigned int Node::sendFindNodeToBest(const Answer* node_list)
{
unsigned int i = 0;
unsigned int j = 0;
}
/** @brief Handles the answer to an incoming "find_node" task */
-void Node::handleFindNode(Message* msg)
+void Node::handleFindNode(const Message* msg)
{
routingTableUpdate(msg->sender_id_);
XBT_VERB("Received a FIND_NODE from %s (%s), he's trying to find %08x", msg->answer_to_->get_cname(),
bool join(unsigned int known_id);
void sendFindNode(unsigned int id, unsigned int destination);
- unsigned int sendFindNodeToBest(Answer* node_list);
+ unsigned int sendFindNodeToBest(const Answer* node_list);
void routingTableUpdate(unsigned int id);
Answer* findClosest(unsigned int destination_id);
bool findNode(unsigned int id_to_find, bool count_in_stats);
void randomLookup();
- void handleFindNode(Message* msg);
+ void handleFindNode(const Message* msg);
};
}
// identifier functions
namespace filter {
/* First example of thing that we can use as a filtering criteria: a simple boolean function */
-static bool filter_speed_more_than_50Mf(simgrid::s4u::Host* host)
+static bool filter_speed_more_than_50Mf(const simgrid::s4u::Host* host)
{
return host->get_speed() > 50E6;
}
*/
class SingleCore {
public:
- bool operator()(simgrid::s4u::Host* host) { return host->get_core_count() == 1; }
+ bool operator()(const simgrid::s4u::Host* host) { return host->get_core_count() == 1; }
};
/* This functor is a bit more complex, as it saves the current state when created.
/* Use a lambda function to filter hosts: We only want multicore hosts */
XBT_INFO("Hosts currently registered with this engine: %zu", e.get_host_count());
std::vector<simgrid::s4u::Host*> list =
- e.get_filtered_hosts([](simgrid::s4u::Host* host) { return host->get_core_count() > 1; });
+ e.get_filtered_hosts([](const simgrid::s4u::Host* host) { return host->get_core_count() > 1; });
for (auto& host : list)
XBT_INFO("The following hosts have more than one core: %s", host->get_cname());
} else \
((void)0)
-static void log_action(simgrid::xbt::ReplayAction& action, double date)
+static void log_action(const simgrid::xbt::ReplayAction& action, double date)
{
if (XBT_LOG_ISENABLED(replay_comm, xbt_log_priority_verbose)) {
std::string s = boost::algorithm::join(action, " ");
} else \
((void)0)
-static void log_action(simgrid::xbt::ReplayAction& action, double date)
+static void log_action(const simgrid::xbt::ReplayAction& action, double date)
{
if (XBT_LOG_ISENABLED(replay_io, xbt_log_priority_verbose)) {
std::string s = boost::algorithm::join(action, " ");
simgrid::s4u::SemaphorePtr sem_empty = simgrid::s4u::Semaphore::create(1); /* indicates whether the buffer is empty */
simgrid::s4u::SemaphorePtr sem_full = simgrid::s4u::Semaphore::create(0); /* indicates whether the buffer is full */
-
-static void producer(std::vector<std::string>* args)
+static void producer(const std::vector<std::string>* args)
{
for (auto str : *args) {
sem_empty->acquire();
/* This shows how to extend the trace format by adding a new kind of events.
This function is registered through xbt_replay_action_register() below. */
-static void action_blah(simgrid::xbt::ReplayAction& /*args*/)
+static void action_blah(const simgrid::xbt::ReplayAction& /*args*/)
{
/* Add your answer to the blah event here.
args is a strings array containing the blank-separated parameters found in the trace for this event instance. */
}
// Sleeps for a given amount of time
-static int sleeper_process(int* param)
+static int sleeper_process(const int* param)
{
XBT_DEBUG("Sleeping for %d seconds", *param);
simgrid::s4u::this_actor::sleep_for(*param);
}
// Executes a workload of SMPI processes
-static int workload_executor_process(std::vector<Job*>* workload)
+static int workload_executor_process(const std::vector<Job*>* workload)
{
for (Job* job : *workload) {
// Let's wait until the job's waiting time if needed