A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
kill dead code in the C interface to surf
[simgrid.git]
/
examples
/
msg
/
chainsend
/
peer.c
diff --git
a/examples/msg/chainsend/peer.c
b/examples/msg/chainsend/peer.c
index 1827df869cee0f4f9c4257d5cf72e4ba02c00384..6be29c17b7c0e4c107dc7507887bff8f6f053905 100644
(file)
--- a/
examples/msg/chainsend/peer.c
+++ b/
examples/msg/chainsend/peer.c
@@
-1,3
+1,9
@@
+/* Copyright (c) 2012-2014. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
#include "peer.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_peer,
#include "peer.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_peer,
@@
-17,7
+23,7
@@
void peer_init_chain(peer_t peer, message_t msg)
static void peer_forward_msg(peer_t peer, message_t msg)
{
static void peer_forward_msg(peer_t peer, message_t msg)
{
- msg_task_t task = task_message_data_new(
peer->me, peer->next,
NULL, msg->data_length);
+ msg_task_t task = task_message_data_new(NULL, msg->data_length);
msg_comm_t comm = NULL;
XBT_DEBUG("Sending (isend) from %s into mailbox %s", peer->me, peer->next);
comm = MSG_task_isend(task, peer->next);
msg_comm_t comm = NULL;
XBT_DEBUG("Sending (isend) from %s into mailbox %s", peer->me, peer->next);
comm = MSG_task_isend(task, peer->next);
@@
-93,28
+99,32
@@
void peer_init(peer_t p, int argc, char *argv[])
p->bytes = 0;
p->pending_recvs = xbt_dynar_new(sizeof(msg_comm_t), NULL);
p->pending_sends = xbt_dynar_new(sizeof(msg_comm_t), NULL);
p->bytes = 0;
p->pending_recvs = xbt_dynar_new(sizeof(msg_comm_t), NULL);
p->pending_sends = xbt_dynar_new(sizeof(msg_comm_t), NULL);
- p->me = xbt_new(char, HOSTNAME_LENGTH);
/* Set mailbox name: use host number from argv or hostname if no argument given */
if (argc > 1) {
/* Set mailbox name: use host number from argv or hostname if no argument given */
if (argc > 1) {
-
snprintf(p->me, HOSTNAME_LENGTH,
"host%s", argv[1]);
+
p->me = bprintf(
"host%s", argv[1]);
} else {
} else {
-
strncpy(p->me, MSG_host_get_name(MSG_host_self()), HOSTNAME_LENGTH
);
+
p->me = xbt_strdup(MSG_host_get_name(MSG_host_self())
);
}
}
void peer_shutdown(peer_t p)
{
}
}
void peer_shutdown(peer_t p)
{
- float start_time = MSG_get_clock();
- float end_time = start_time + PEER_SHUTDOWN_DEADLINE;
+ unsigned int size = xbt_dynar_length(p->pending_sends);
+ unsigned int idx;
+ msg_comm_t *comms = xbt_new(msg_comm_t, size);
+
+ for (idx = 0; idx < size; idx++) {
+ comms[idx] = xbt_dynar_get_as(p->pending_sends, idx, msg_comm_t);
+ }
XBT_DEBUG("Waiting for sends to finish before shutdown...");
XBT_DEBUG("Waiting for sends to finish before shutdown...");
- /* MSG_comm_waitall(p->pending_sends, PEER_SHUTDOWN_DEADLINE); FIXME: this doesn't work */
- while (xbt_dynar_length(p->pending_sends) && MSG_get_clock() < end_time) {
- process_pending_connections(p->pending_sends);
- MSG_
process_sleep(1
);
+ MSG_comm_waitall(comms, size, PEER_SHUTDOWN_DEADLINE);
+
+ for (idx = 0; idx < size; idx++) {
+ MSG_
comm_destroy(comms[idx]
);
}
}
- xbt_
assert(xbt_dynar_length(p->pending_sends) == 0, "Shutdown failed, sends still pending after deadline"
);
+ xbt_
free(comms
);
}
void peer_delete(peer_t p)
}
void peer_delete(peer_t p)
@@
-122,6
+132,8
@@
void peer_delete(peer_t p)
xbt_dynar_free(&p->pending_recvs);
xbt_dynar_free(&p->pending_sends);
xbt_free(p->me);
xbt_dynar_free(&p->pending_recvs);
xbt_dynar_free(&p->pending_sends);
xbt_free(p->me);
+ xbt_free(p->prev);
+ xbt_free(p->next);
xbt_free(p);
}
xbt_free(p);
}