From f7623851a023484d8ba1d5c26134ee7850bac134 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 19 Jun 2017 09:16:42 +0200 Subject: [PATCH] ActivityImplPtr are not part of any C struct, only C++ classes the refcounting fails on malloc/free. We need new/delete for that. --- include/simgrid/msg.h | 13 ++++++++++++- src/msg/msg_gos.cpp | 16 +++++----------- src/msg/msg_private.h | 17 +++++++++++------ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index d5bd22ed36..427b2327ba 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -10,6 +10,17 @@ #include "simgrid/forward.h" #include "simgrid/simix.h" +#ifdef __cplusplus +namespace simgrid { +namespace msg { +class Comm; +} +} +typedef simgrid::msg::Comm sg_msg_Comm; +#else +typedef struct msg_Comm sg_msg_Comm; +#endif + SG_BEGIN_DECL() /* *************************** Network Zones ******************************** */ @@ -74,7 +85,7 @@ typedef sg_storage_t msg_storage_t; * * Object representing an ongoing communication between processes. Such beast is usually obtained by using #MSG_task_isend, #MSG_task_irecv or friends. */ -typedef struct msg_comm *msg_comm_t; +typedef sg_msg_Comm* msg_comm_t; /** \brief Default value for an uninitialized #msg_task_t. \ingroup m_task_management diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index 7f2e4b4bb8..d0127d7961 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -321,11 +321,7 @@ static inline msg_comm_t MSG_task_isend_internal(msg_task_t task, const char *al msg_comm_t comm = nullptr; if (not detached) { - comm = xbt_new0(s_msg_comm_t, 1); - comm->task_sent = task; - comm->task_received = nullptr; - comm->status = MSG_OK; - comm->s_comm = act; + comm = new simgrid::msg::Comm(task, nullptr, act); } if (TRACE_is_enabled()) @@ -465,11 +461,9 @@ msg_comm_t MSG_task_irecv_bounded(msg_task_t *task, const char *name, double rat XBT_CRITICAL("MSG_task_irecv() was asked to write in a non empty task struct."); /* Try to receive it by calling SIMIX network layer */ - msg_comm_t comm = xbt_new0(s_msg_comm_t, 1); - comm->task_sent = nullptr; - comm->task_received = task; - comm->status = MSG_OK; - comm->s_comm = simcall_comm_irecv(SIMIX_process_self(), mbox->getImpl(), task, nullptr, nullptr, nullptr, nullptr, rate); + msg_comm_t comm = + new simgrid::msg::Comm(nullptr, task, simcall_comm_irecv(SIMIX_process_self(), mbox->getImpl(), task, nullptr, + nullptr, nullptr, nullptr, rate)); return comm; } @@ -570,7 +564,7 @@ int MSG_comm_testany(xbt_dynar_t comms) */ void MSG_comm_destroy(msg_comm_t comm) { - xbt_free(comm); + delete comm; } /** \ingroup msg_task_usage diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index a62d92cc92..e3f98d88da 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -77,15 +77,20 @@ public: msg_error_t errno_ = MSG_OK; /* the last value returned by a MSG_function */ void* data = nullptr; /* user data */ }; -} -} -typedef struct msg_comm { - smx_activity_t s_comm; /* SIMIX communication object encapsulated (the same for both processes) */ +class Comm { +public: msg_task_t task_sent; /* task sent (NULL for the receiver) */ msg_task_t *task_received; /* where the task will be received (NULL for the sender) */ - msg_error_t status; /* status of the communication once finished */ -} s_msg_comm_t; + smx_activity_t s_comm; /* SIMIX communication object encapsulated (the same for both processes) */ + msg_error_t status = MSG_OK; /* status of the communication once finished */ + Comm(msg_task_t sent, msg_task_t* received, smx_activity_t comm) + : task_sent(sent), task_received(received), s_comm(std::move(comm)) + { + } +}; +} +} /************************** Global variables ********************************/ typedef struct MSG_Global { -- 2.20.1