Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer parameters in src/msg/.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 28 Dec 2019 21:51:55 +0000 (22:51 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 28 Dec 2019 21:52:56 +0000 (22:52 +0100)
include/simgrid/msg.h
src/bindings/java/jmsg_comm.cpp
src/bindings/java/jmsg_task.cpp
src/msg/msg_comm.cpp
src/msg/msg_legacy.cpp
src/msg/msg_private.hpp
src/msg/msg_task.cpp

index aa2f024..4d0687c 100644 (file)
@@ -39,17 +39,10 @@ class Task;
 }
 }
 typedef simgrid::msg::Comm sg_msg_Comm;
-/** @brief Task datatype.
- *
- *  Since most scheduling algorithms rely on a concept of task  that can be either <em>computed</em> locally or
- *  <em>transferred</em> on another processor, it seems to be the right level of abstraction for our purposes.
- *  A <em>task</em> may then be defined by a <em>computing amount</em>, a <em>message size</em> and
- *  some <em>private data</em>.
- */
-typedef simgrid::msg::Task* msg_task_t;
+typedef simgrid::msg::Task sg_msg_Task;
 #else
 typedef struct msg_Comm sg_msg_Comm;
-typedef struct msg_Task* msg_task_t;
+typedef struct msg_Task sg_msg_Task;
 #endif
 
 #ifdef __cplusplus
@@ -248,6 +241,17 @@ XBT_PUBLIC void MSG_process_unref(msg_process_t process);
  * \endrst
  */
 typedef sg_msg_Comm* msg_comm_t;
+typedef const sg_msg_Comm* const_msg_comm_t;
+
+/** @brief Task datatype.
+ *
+ *  Since most scheduling algorithms rely on a concept of task  that can be either <em>computed</em> locally or
+ *  <em>transferred</em> on another processor, it seems to be the right level of abstraction for our purposes.
+ *  A <em>task</em> may then be defined by a <em>computing amount</em>, a <em>message size</em> and
+ *  some <em>private data</em>.
+ */
+typedef sg_msg_Task* msg_task_t;
+typedef const sg_msg_Task* const_msg_task_t;
 
 /* ******************************** Task ************************************ */
 
@@ -331,7 +335,7 @@ XBT_PUBLIC void MSG_process_set_data_cleanup(void_f_pvoid_t data_cleanup);
 XBT_PUBLIC xbt_dynar_t MSG_processes_as_dynar();
 XBT_PUBLIC int MSG_process_get_number();
 
-XBT_PUBLIC void* MSG_process_get_data(msg_process_t process);
+XBT_PUBLIC void* MSG_process_get_data(const_sg_actor_t process);
 XBT_PUBLIC msg_error_t MSG_process_set_data(msg_process_t process, void* data);
 
 XBT_PUBLIC void MSG_process_on_exit(int_f_int_pvoid_t fun, void* data);
@@ -340,11 +344,11 @@ XBT_PUBLIC void MSG_process_on_exit(int_f_int_pvoid_t fun, void* data);
 XBT_PUBLIC msg_task_t MSG_task_create(const char* name, double flops_amount, double bytes_amount, void* data);
 XBT_PUBLIC msg_task_t MSG_parallel_task_create(const char* name, int host_nb, const msg_host_t* host_list,
                                                double* flops_amount, double* bytes_amount, void* data);
-XBT_PUBLIC void* MSG_task_get_data(msg_task_t task);
+XBT_PUBLIC void* MSG_task_get_data(const_msg_task_t task);
 XBT_PUBLIC void MSG_task_set_data(msg_task_t task, void* data);
-XBT_PUBLIC msg_process_t MSG_task_get_sender(msg_task_t task);
-XBT_PUBLIC msg_host_t MSG_task_get_source(msg_task_t task);
-XBT_PUBLIC const char* MSG_task_get_name(msg_task_t task);
+XBT_PUBLIC msg_process_t MSG_task_get_sender(const_msg_task_t task);
+XBT_PUBLIC msg_host_t MSG_task_get_source(const_msg_task_t task);
+XBT_PUBLIC const char* MSG_task_get_name(const_msg_task_t task);
 XBT_PUBLIC void MSG_task_set_name(msg_task_t task, const char* name);
 XBT_PUBLIC msg_error_t MSG_task_cancel(msg_task_t task);
 XBT_PUBLIC msg_error_t MSG_task_destroy(msg_task_t task);
@@ -356,12 +360,12 @@ XBT_PUBLIC void MSG_task_set_priority(msg_task_t task, double priority);
 XBT_PUBLIC void MSG_task_set_bound(msg_task_t task, double bound);
 
 XBT_PUBLIC void MSG_task_set_flops_amount(msg_task_t task, double flops_amount);
-XBT_PUBLIC double MSG_task_get_flops_amount(msg_task_t task);
-XBT_PUBLIC double MSG_task_get_remaining_work_ratio(msg_task_t task);
+XBT_PUBLIC double MSG_task_get_flops_amount(const_msg_task_t task);
+XBT_PUBLIC double MSG_task_get_remaining_work_ratio(const_msg_task_t task);
 XBT_PUBLIC void MSG_task_set_bytes_amount(msg_task_t task, double bytes_amount);
 
-XBT_PUBLIC double MSG_task_get_remaining_communication(msg_task_t task);
-XBT_PUBLIC double MSG_task_get_bytes_amount(msg_task_t task);
+XBT_PUBLIC double MSG_task_get_remaining_communication(const_msg_task_t task);
+XBT_PUBLIC double MSG_task_get_bytes_amount(const_msg_task_t task);
 
 XBT_PUBLIC msg_error_t MSG_task_receive_with_timeout(msg_task_t* task, const char* alias, double timeout);
 
@@ -382,12 +386,12 @@ XBT_PUBLIC msg_comm_t MSG_task_irecv(msg_task_t* task, const char* alias);
 XBT_PUBLIC msg_comm_t MSG_task_irecv_bounded(msg_task_t* task, const char* alias, double rate);
 XBT_PUBLIC int MSG_comm_test(msg_comm_t comm);
 XBT_PUBLIC int MSG_comm_testany(xbt_dynar_t comms);
-XBT_PUBLIC void MSG_comm_destroy(msg_comm_t comm);
+XBT_PUBLIC void MSG_comm_destroy(const_msg_comm_t comm);
 XBT_PUBLIC msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout);
 XBT_PUBLIC void MSG_comm_waitall(msg_comm_t* comm, int nb_elem, double timeout);
 XBT_PUBLIC int MSG_comm_waitany(xbt_dynar_t comms);
-XBT_PUBLIC msg_task_t MSG_comm_get_task(msg_comm_t comm);
-XBT_PUBLIC msg_error_t MSG_comm_get_status(msg_comm_t comm);
+XBT_PUBLIC msg_task_t MSG_comm_get_task(const_msg_comm_t comm);
+XBT_PUBLIC msg_error_t MSG_comm_get_status(const_msg_comm_t comm);
 
 /** @brief Check if there is a communication going on in a mailbox.
  *
@@ -403,7 +407,7 @@ XBT_PUBLIC msg_error_t MSG_task_send(msg_task_t task, const char* alias);
 XBT_PUBLIC msg_error_t MSG_task_send_bounded(msg_task_t task, const char* alias, double rate);
 XBT_PUBLIC int MSG_task_listen_from(const char* alias);
 XBT_PUBLIC void MSG_task_set_category(msg_task_t task, const char* category);
-XBT_PUBLIC const char* MSG_task_get_category(msg_task_t task);
+XBT_PUBLIC const char* MSG_task_get_category(const_msg_task_t task);
 
 /************************** Mailbox handling ************************************/
 
index 7de0a98..43d1e1e 100644 (file)
@@ -21,7 +21,7 @@ static jfieldID jtask_field_Comm_task;
 static jfieldID jcomm_field_Comm_taskBind;
 
 void jcomm_bind_task(JNIEnv *env, jobject jcomm) {
-  msg_comm_t comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
+  const_msg_comm_t comm = (msg_comm_t)(uintptr_t)env->GetLongField(jcomm, jcomm_field_Comm_bind);
   //test if we are receiving or sending a task.
   jboolean jreceiving = env->GetBooleanField(jcomm, jcomm_field_Comm_receiving);
   if (jreceiving == JNI_TRUE) {
@@ -59,13 +59,12 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeFinalize(JNIEnv *env, jobject jcomm) {
-  msg_comm_t comm;
   msg_task_t *task_received;
 
   task_received = (msg_task_t*)  (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_taskBind);
   delete task_received;
 
-  comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
+  const_msg_comm_t comm = (msg_comm_t)(uintptr_t)env->GetLongField(jcomm, jcomm_field_Comm_bind);
   MSG_comm_destroy(comm);
 }
 
index 09aa323..6189706 100644 (file)
@@ -151,7 +151,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setBound(JNIEnv * env, jobject
 }
 
 JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName(JNIEnv * env, jobject jtask) {
-  msg_task_t task = jtask_to_native(jtask, env);
+  const_msg_task_t task = jtask_to_native(jtask, env);
 
   if (not task) {
     jxbt_throw_notbound(env, "task", jtask);
@@ -162,7 +162,7 @@ JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName(JNIEnv * env, jobjec
 }
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender(JNIEnv * env, jobject jtask) {
-  msg_task_t task = jtask_to_native(jtask, env);
+  const_msg_task_t task = jtask_to_native(jtask, env);
 
   if (not task) {
     jxbt_throw_notbound(env, "task", jtask);
@@ -178,7 +178,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender(JNIEnv * env, jobj
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSource(JNIEnv * env, jobject jtask)
 {
-  msg_task_t task = jtask_to_native(jtask, env);
+  const_msg_task_t task = jtask_to_native(jtask, env);
 
   if (not task) {
     jxbt_throw_notbound(env, "task", jtask);
@@ -199,7 +199,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSource(JNIEnv * env, jobj
 
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Task_getFlopsAmount(JNIEnv * env, jobject jtask)
 {
-  msg_task_t ptask = jtask_to_native(jtask, env);
+  const_msg_task_t ptask = jtask_to_native(jtask, env);
 
   if (not ptask) {
     jxbt_throw_notbound(env, "task", jtask);
index e706353..60135b6 100644 (file)
@@ -124,7 +124,7 @@ int MSG_comm_testany(xbt_dynar_t comms)
 }
 
 /** @brief Destroys the provided communication. */
-void MSG_comm_destroy(msg_comm_t comm)
+void MSG_comm_destroy(const_msg_comm_t comm)
 {
   delete comm;
 }
@@ -205,7 +205,7 @@ int MSG_comm_waitany(xbt_dynar_t comms)
  * @param comm a finished communication
  * @return the status of the communication, or #MSG_OK if no error occurred during the communication
  */
-msg_error_t MSG_comm_get_status(msg_comm_t comm)
+msg_error_t MSG_comm_get_status(const_msg_comm_t comm)
 {
   return comm->get_status();
 }
@@ -215,7 +215,7 @@ msg_error_t MSG_comm_get_status(msg_comm_t comm)
  * @param comm the communication where to get the task
  * @return the task from the communication
  */
-msg_task_t MSG_comm_get_task(msg_comm_t comm)
+msg_task_t MSG_comm_get_task(const_msg_comm_t comm)
 {
   xbt_assert(comm, "Invalid parameter");
 
index 124b077..2454b2e 100644 (file)
@@ -139,7 +139,7 @@ msg_error_t MSG_process_sleep(double duration)
  *
  * This function checks whether @a process is a valid pointer and returns the user data associated to this process.
  */
-void* MSG_process_get_data(msg_process_t process)
+void* MSG_process_get_data(const_sg_actor_t process)
 {
   xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!");
 
index 505c892..9c5095f 100644 (file)
@@ -48,30 +48,30 @@ public:
   Task& operator=(const Task&) = delete;
   ~Task()                      = default;
 
-  bool is_used() { return is_used_; }
-  bool is_parallel() { return parallel_; }
+  bool is_used() const { return is_used_; }
+  bool is_parallel() const { return parallel_; }
 
   void set_used();
   void set_not_used() { this->is_used_ = false; }
   const std::string& get_name() const { return name_; }
-  const char* get_cname() { return name_.c_str(); }
+  const char* get_cname() const { return name_.c_str(); }
   void set_name(const char* new_name) { name_ = std::string(new_name); }
   void set_tracing_category(const char* category) { tracing_category_ = category ? std::string(category) : ""; }
-  const std::string& get_tracing_category() { return tracing_category_; }
+  const std::string& get_tracing_category() const { return tracing_category_; }
   bool has_tracing_category() { return not tracing_category_.empty(); }
   XBT_ATTRIB_DEPRECATED_v329("Please use set_data()") void* get_user_data() { return get_data(); }
   XBT_ATTRIB_DEPRECATED_v329("Please use get_data()") void set_user_data(void* data) { set_data(data); }
-  long long int get_id() { return id_; }
-  double get_priority() { return priority_; }
+  long long int get_id() const { return id_; }
+  double get_priority() const { return priority_; }
   void set_priority(double priority);
   void set_bound(double bound) { bound_ = bound; }
-  double get_bound() { return bound_; }
+  double get_bound() const { return bound_; }
   void set_rate(double rate) { rate_ = rate; }
-  double get_rate() { return rate_; }
+  double get_rate() const { return rate_; }
   void set_timeout(double timeout) { timeout_ = timeout; }
 
-  s4u::Actor* get_sender();
-  s4u::Host* get_source();
+  s4u::Actor* get_sender() const;
+  s4u::Host* get_source() const;
 
   s4u::ExecPtr compute = nullptr; /* S4U modeling of computation */
   s4u::CommPtr comm    = nullptr; /* S4U modeling of communication */
@@ -98,7 +98,7 @@ public:
   bool test();
   msg_error_t wait_for(double timeout);
   void set_status(msg_error_t status) { status_ = status; }
-  msg_error_t get_status() { return status_; }
+  msg_error_t get_status() const { return status_; }
 };
 
 } // namespace msg
index 24cbd4b..f401abb 100644 (file)
@@ -161,12 +161,12 @@ void Task::set_priority(double priority)
   priority_ = 1.0 / priority;
 }
 
-s4u::Actor* Task::get_sender()
+s4u::Actor* Task::get_sender() const
 {
   return comm ? comm->get_sender() : nullptr;
 }
 
-s4u::Host* Task::get_source()
+s4u::Host* Task::get_source() const
 {
   return comm ? comm->get_sender()->get_host() : nullptr;
 }
@@ -241,7 +241,7 @@ msg_task_t MSG_parallel_task_create(const char *name, int host_nb, const msg_hos
 }
 
 /** @brief Return the user data of the given task */
-void* MSG_task_get_data(msg_task_t task)
+void* MSG_task_get_data(const_msg_task_t task)
 {
   return task->get_data();
 }
@@ -253,19 +253,19 @@ void MSG_task_set_data(msg_task_t task, void *data)
 }
 
 /** @brief Returns the sender of the given task */
-msg_process_t MSG_task_get_sender(msg_task_t task)
+msg_process_t MSG_task_get_sender(const_msg_task_t task)
 {
   return task->get_sender();
 }
 
 /** @brief Returns the source (the sender's host) of the given task */
-msg_host_t MSG_task_get_source(msg_task_t task)
+msg_host_t MSG_task_get_source(const_msg_task_t task)
 {
   return task->get_source();
 }
 
 /** @brief Returns the name of the given task. */
-const char *MSG_task_get_name(msg_task_t task)
+const char* MSG_task_get_name(const_msg_task_t task)
 {
   return task->get_cname();
 }
@@ -682,7 +682,7 @@ msg_error_t MSG_task_cancel(msg_task_t task)
  *
  * It works for either parallel or sequential tasks.
  */
-double MSG_task_get_remaining_work_ratio(msg_task_t task)
+double MSG_task_get_remaining_work_ratio(const_msg_task_t task)
 {
   xbt_assert((task != nullptr), "Cannot get information from a nullptr task");
   if (task->compute) {
@@ -701,7 +701,8 @@ double MSG_task_get_remaining_work_ratio(msg_task_t task)
  * It works for sequential tasks, but the remaining amount of work is not a scalar value for parallel tasks.
  * So you will get an exception if you call this function on parallel tasks. Just don't do it.
  */
-double MSG_task_get_flops_amount(msg_task_t task) {
+double MSG_task_get_flops_amount(const_msg_task_t task)
+{
   if (task->compute != nullptr) {
     return task->compute->get_remaining();
   } else {
@@ -737,14 +738,14 @@ void MSG_task_set_bytes_amount(msg_task_t task, double data_size)
  *  If the communication does not exist it will return 0.
  *  So, if the communication has FINISHED or FAILED it returns zero.
  */
-double MSG_task_get_remaining_communication(msg_task_t task)
+double MSG_task_get_remaining_communication(const_msg_task_t task)
 {
   XBT_DEBUG("calling simcall_communication_get_remains(%p)", task->comm.get());
   return task->comm->get_remaining();
 }
 
 /** @brief Returns the size of the data attached to the given task. */
-double MSG_task_get_bytes_amount(msg_task_t task)
+double MSG_task_get_bytes_amount(const_msg_task_t task)
 {
   xbt_assert(task != nullptr, "Invalid parameter");
   return task->bytes_amount;
@@ -807,7 +808,7 @@ void MSG_task_set_category(msg_task_t task, const char* category)
  * @param task the task to be considered
  * @return Returns the name of the tracing category of the given task, "" otherwise
  */
-const char* MSG_task_get_category(msg_task_t task)
+const char* MSG_task_get_category(const_msg_task_t task)
 {
   return task->get_tracing_category().c_str();
 }