From 75e8b2ae65722d849ef899616de7091286ec91f5 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sun, 29 Dec 2019 12:43:14 +0100 Subject: [PATCH] [sonar] Constify pointer and reference parameters in src/s4u/. This commit is too big, but it's too late to split it :( --- .../simdag/scheduling/sd_scheduling.c | 7 +-- examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp | 2 +- include/simgrid/actor.h | 12 ++--- include/simgrid/barrier.h | 2 +- include/simgrid/cond.h | 2 +- include/simgrid/forward.h | 17 ++++--- include/simgrid/host.h | 38 +++++++-------- include/simgrid/link.h | 10 ++-- include/simgrid/msg.h | 40 ++++++++-------- include/simgrid/mutex.h | 2 +- include/simgrid/s4u/Actor.hpp | 4 +- include/simgrid/s4u/Comm.hpp | 8 ++-- include/simgrid/s4u/ConditionVariable.hpp | 22 ++++----- include/simgrid/s4u/Disk.hpp | 4 +- include/simgrid/s4u/Engine.hpp | 6 +-- include/simgrid/s4u/Host.hpp | 8 ++-- include/simgrid/s4u/Link.hpp | 6 +-- include/simgrid/s4u/Mutex.hpp | 4 +- include/simgrid/s4u/NetZone.hpp | 4 +- include/simgrid/s4u/Storage.hpp | 4 +- include/simgrid/semaphore.h | 2 +- include/simgrid/storage.h | 10 ++-- include/simgrid/zone.h | 10 ++-- src/bindings/java/jmsg.cpp | 2 +- src/bindings/java/jmsg_host.cpp | 18 ++++---- src/bindings/java/jmsg_process.cpp | 8 ++-- src/bindings/java/jmsg_process.h | 4 +- src/bindings/python/simgrid_python.cpp | 5 +- src/kernel/resource/DiskImpl.hpp | 2 +- src/msg/msg_legacy.cpp | 40 ++++++++-------- src/s4u/s4u_Actor.cpp | 16 +++---- src/s4u/s4u_Barrier.cpp | 2 +- src/s4u/s4u_Comm.cpp | 6 +-- src/s4u/s4u_ConditionVariable.cpp | 12 ++--- src/s4u/s4u_Disk.cpp | 4 +- src/s4u/s4u_Engine.cpp | 6 +-- src/s4u/s4u_Host.cpp | 46 +++++++++---------- src/s4u/s4u_Link.cpp | 16 +++---- src/s4u/s4u_Mutex.cpp | 6 +-- src/s4u/s4u_Netzone.cpp | 14 +++--- src/s4u/s4u_Semaphore.cpp | 2 +- src/s4u/s4u_Storage.cpp | 12 ++--- .../msg/process-migration/process-migration.c | 2 +- .../basic-parsing-test/basic-parsing-test.c | 8 ++-- .../evaluate-get-route-time.c | 4 +- teshsuite/simdag/flatifier/flatifier.cpp | 2 +- 46 files changed, 234 insertions(+), 227 deletions(-) diff --git a/examples/deprecated/simdag/scheduling/sd_scheduling.c b/examples/deprecated/simdag/scheduling/sd_scheduling.c index f8afd59b5d..1ad679b119 100644 --- a/examples/deprecated/simdag/scheduling/sd_scheduling.c +++ b/examples/deprecated/simdag/scheduling/sd_scheduling.c @@ -22,7 +22,7 @@ struct _HostAttribute { SD_task_t last_scheduled_task; }; -static double sg_host_get_available_at(sg_host_t host) +static double sg_host_get_available_at(const_sg_host_t host) { const struct _HostAttribute* attr = (HostAttribute)sg_host_data(host); return attr->available_at; @@ -35,7 +35,8 @@ static void sg_host_set_available_at(sg_host_t host, double time) sg_host_data_set(host, attr); } -static SD_task_t sg_host_get_last_scheduled_task( sg_host_t host){ +static SD_task_t sg_host_get_last_scheduled_task(const_sg_host_t host) +{ const struct _HostAttribute* attr = (HostAttribute)sg_host_data(host); return attr->last_scheduled_task; } @@ -63,7 +64,7 @@ static xbt_dynar_t get_ready_tasks(const_xbt_dynar_t dax) return ready_tasks; } -static double finish_on_at(SD_task_t task, sg_host_t host) +static double finish_on_at(SD_task_t task, const_sg_host_t host) { double result; diff --git a/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp b/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp index 49c9093846..abe529fa28 100644 --- a/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp +++ b/examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp @@ -18,7 +18,7 @@ static void host() std::vector const& disk_list = simgrid::s4u::Host::current()->get_disks(); /* - For each disk mounted on host, display disk name and mount point */ - for (auto disk : disk_list) + for (auto const& disk : disk_list) XBT_INFO("Disk name: %s (read: %.0f B/s -- write: %.0f B/s ", disk->get_cname(), disk->get_read_bandwidth(), disk->get_write_bandwidth()); diff --git a/include/simgrid/actor.h b/include/simgrid/actor.h index cebaa6798c..a053ee4a0d 100644 --- a/include/simgrid/actor.h +++ b/include/simgrid/actor.h @@ -25,13 +25,13 @@ XBT_PUBLIC sg_actor_t sg_actor_init(const char* name, sg_host_t host); * * Note that argv is copied over, so you should free your own copy once the actor is started. */ XBT_PUBLIC void sg_actor_start(sg_actor_t actor, xbt_main_func_t code, int argc, char** argv); -XBT_PUBLIC aid_t sg_actor_get_PID(sg_actor_t actor); -XBT_PUBLIC aid_t sg_actor_get_PPID(sg_actor_t actor); +XBT_PUBLIC aid_t sg_actor_get_PID(const_sg_actor_t actor); +XBT_PUBLIC aid_t sg_actor_get_PPID(const_sg_actor_t actor); XBT_PUBLIC sg_actor_t sg_actor_by_PID(aid_t pid); -XBT_PUBLIC const char* sg_actor_get_name(sg_actor_t actor); -XBT_PUBLIC sg_host_t sg_actor_get_host(sg_actor_t actor); -XBT_PUBLIC const char* sg_actor_get_property_value(sg_actor_t actor, const char* name); -XBT_PUBLIC xbt_dict_t sg_actor_get_properties(sg_actor_t actor); +XBT_PUBLIC const char* sg_actor_get_name(const_sg_actor_t actor); +XBT_PUBLIC sg_host_t sg_actor_get_host(const_sg_actor_t actor); +XBT_PUBLIC const char* sg_actor_get_property_value(const_sg_actor_t actor, const char* name); +XBT_PUBLIC xbt_dict_t sg_actor_get_properties(const_sg_actor_t actor); XBT_PUBLIC void sg_actor_suspend(sg_actor_t actor); XBT_PUBLIC void sg_actor_resume(sg_actor_t actor); XBT_PUBLIC int sg_actor_is_suspended(sg_actor_t actor); diff --git a/include/simgrid/barrier.h b/include/simgrid/barrier.h index 83347fea4d..829766c477 100644 --- a/include/simgrid/barrier.h +++ b/include/simgrid/barrier.h @@ -20,7 +20,7 @@ constexpr int SG_BARRIER_SERIAL_THREAD = -1; SG_BEGIN_DECL XBT_PUBLIC sg_bar_t sg_barrier_init(unsigned int count); -XBT_PUBLIC void sg_barrier_destroy(sg_bar_t bar); +XBT_PUBLIC void sg_barrier_destroy(const_sg_bar_t bar); XBT_PUBLIC int sg_barrier_wait(sg_bar_t bar); SG_END_DECL diff --git a/include/simgrid/cond.h b/include/simgrid/cond.h index 2bdfc41a95..40b3374902 100644 --- a/include/simgrid/cond.h +++ b/include/simgrid/cond.h @@ -23,7 +23,7 @@ XBT_PUBLIC void sg_cond_notify_one(sg_cond_t cond); /** @brief Broadcasts the given mutex variable */ XBT_PUBLIC void sg_cond_notify_all(sg_cond_t cond); /** @brief Destroys the given mutex variable */ -XBT_PUBLIC void sg_cond_destroy(sg_cond_t cond); +XBT_PUBLIC void sg_cond_destroy(const_sg_cond_t cond); SG_END_DECL diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index eb8125ac9a..8a2edfbd16 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -20,8 +20,8 @@ class Activity; class Actor; /** Smart pointer to a simgrid::s4u::Actor */ typedef boost::intrusive_ptr ActorPtr; -XBT_PUBLIC void intrusive_ptr_release(Actor* actor); -XBT_PUBLIC void intrusive_ptr_add_ref(Actor* actor); +XBT_PUBLIC void intrusive_ptr_release(const Actor* actor); +XBT_PUBLIC void intrusive_ptr_add_ref(const Actor* actor); class Barrier; /** Smart pointer to a simgrid::s4u::Barrier */ @@ -38,8 +38,8 @@ XBT_PUBLIC void intrusive_ptr_add_ref(Comm* c); class ConditionVariable; /** Smart pointer to a simgrid::s4u::ConditionVariable */ typedef boost::intrusive_ptr ConditionVariablePtr; -XBT_PUBLIC void intrusive_ptr_release(ConditionVariable* c); -XBT_PUBLIC void intrusive_ptr_add_ref(ConditionVariable* c); +XBT_PUBLIC void intrusive_ptr_release(const ConditionVariable* c); +XBT_PUBLIC void intrusive_ptr_add_ref(const ConditionVariable* c); class Engine; @@ -66,8 +66,8 @@ class Link; class Mailbox; class Mutex; -XBT_PUBLIC void intrusive_ptr_release(Mutex* m); -XBT_PUBLIC void intrusive_ptr_add_ref(Mutex* m); +XBT_PUBLIC void intrusive_ptr_release(const Mutex* m); +XBT_PUBLIC void intrusive_ptr_add_ref(const Mutex* m); /** Smart pointer to a simgrid::s4u::Mutex */ typedef boost::intrusive_ptr MutexPtr; @@ -227,10 +227,15 @@ typedef struct s_smx_sem* smx_sem_t; #endif typedef s4u_Barrier* sg_bar_t; +typedef const s4u_Barrier* const_sg_bar_t; typedef s4u_ConditionVariable* sg_cond_t; +typedef const s4u_ConditionVariable* const_sg_cond_t; typedef s4u_Mutex* sg_mutex_t; +typedef const s4u_Mutex* const_sg_mutex_t; typedef s4u_Semaphore* sg_sem_t; +typedef const s4u_Semaphore* const_sg_sem_t; typedef s4u_NetZone* sg_netzone_t; +typedef const s4u_NetZone* const_sg_netzone_t; typedef s4u_Host* sg_host_t; typedef const s4u_Host* const_sg_host_t; typedef s4u_Link* sg_link_t; diff --git a/include/simgrid/host.h b/include/simgrid/host.h index a7cce00f17..83c110c63b 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -31,7 +31,7 @@ XBT_PUBLIC size_t sg_host_count(); XBT_PUBLIC xbt_dynar_t sg_hosts_as_dynar(); XBT_PUBLIC size_t sg_host_extension_create(void (*deleter)(void*)); -XBT_PUBLIC void* sg_host_extension_get(sg_host_t host, size_t rank); +XBT_PUBLIC void* sg_host_extension_get(const_sg_host_t host, size_t rank); /** @brief Finds a sg_host_t using its name. * @@ -42,14 +42,14 @@ XBT_PUBLIC void* sg_host_extension_get(sg_host_t host, size_t rank); XBT_PUBLIC sg_host_t sg_host_by_name(const char* name); /** @brief Return the name of the #sg_host_t. */ -XBT_PUBLIC const char* sg_host_get_name(sg_host_t host); +XBT_PUBLIC const char* sg_host_get_name(const_sg_host_t host); // ========== User Data ============== /** @brief Return the user data of a #sg_host_t. * * This functions returns the user data associated to @a host if any. */ -XBT_PUBLIC void* sg_host_data(sg_host_t host); +XBT_PUBLIC void* sg_host_data(const_sg_host_t host); XBT_ATTRIB_DEPRECATED_v328("Please use sg_host_data()") XBT_PUBLIC void* sg_host_user(sg_host_t host); /** @brief Set the user data of a #sg_host_t. * @@ -71,21 +71,21 @@ XBT_PUBLIC xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host); * @param host a host * @return a dynar containing all storages (name) attached to the host */ -XBT_PUBLIC xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host); +XBT_PUBLIC xbt_dynar_t sg_host_get_attached_storage_list(const_sg_host_t host); // =========== user-level functions =============== /** @brief Return the speed of the processor (in flop/s), regardless of the current load on the machine. */ -XBT_PUBLIC double sg_host_speed(sg_host_t host); -XBT_PUBLIC double sg_host_get_pstate_speed(sg_host_t host, int pstate_index); +XBT_PUBLIC double sg_host_speed(const_sg_host_t host); +XBT_PUBLIC double sg_host_get_pstate_speed(const_sg_host_t host, int pstate_index); -XBT_PUBLIC double sg_host_get_available_speed(sg_host_t host); +XBT_PUBLIC double sg_host_get_available_speed(const_sg_host_t host); -XBT_PUBLIC int sg_host_core_count(sg_host_t host); +XBT_PUBLIC int sg_host_core_count(const_sg_host_t host); /** @brief Returns the current computation load (in flops per second). * @param host a host */ -XBT_PUBLIC double sg_host_load(sg_host_t host); +XBT_PUBLIC double sg_host_load(const_sg_host_t host); /** @brief Return the location on which the current process is running. */ XBT_PUBLIC sg_host_t sg_host_self(); @@ -96,14 +96,14 @@ XBT_PUBLIC const char* sg_host_self_get_name(); * * @param host host to test */ -XBT_PUBLIC int sg_host_get_nb_pstates(sg_host_t host); +XBT_PUBLIC int sg_host_get_nb_pstates(const_sg_host_t host); -XBT_PUBLIC int sg_host_get_pstate(sg_host_t host); +XBT_PUBLIC int sg_host_get_pstate(const_sg_host_t host); XBT_PUBLIC void sg_host_set_pstate(sg_host_t host, int pstate); XBT_PUBLIC void sg_host_turn_on(sg_host_t host); XBT_PUBLIC void sg_host_turn_off(sg_host_t host); -XBT_PUBLIC int sg_host_is_on(sg_host_t host); +XBT_PUBLIC int sg_host_is_on(const_sg_host_t host); /** @ingroup m_host_management * @brief Returns a xbt_dict_t consisting of the list of properties assigned to this host @@ -111,7 +111,7 @@ XBT_PUBLIC int sg_host_is_on(sg_host_t host); * @param host a host * @return a dict containing the properties */ -XBT_PUBLIC xbt_dict_t sg_host_get_properties(sg_host_t host); +XBT_PUBLIC xbt_dict_t sg_host_get_properties(const_sg_host_t host); /** @ingroup m_host_management * @brief Returns the value of a given host property @@ -120,7 +120,7 @@ XBT_PUBLIC xbt_dict_t sg_host_get_properties(sg_host_t host); * @param name a property name * @return value of a property (or nullptr if property not set) */ -XBT_PUBLIC const char* sg_host_get_property_value(sg_host_t host, const char* name); +XBT_PUBLIC const char* sg_host_get_property_value(const_sg_host_t host, const char* name); /** @ingroup m_host_management * @brief Change the value of a given host property @@ -131,14 +131,14 @@ XBT_PUBLIC const char* sg_host_get_property_value(sg_host_t host, const char* na */ XBT_PUBLIC void sg_host_set_property_value(sg_host_t host, const char* name, const char* value); -XBT_PUBLIC void sg_host_route(sg_host_t from, sg_host_t to, xbt_dynar_t links); -XBT_PUBLIC double sg_host_route_latency(sg_host_t from, sg_host_t to); -XBT_PUBLIC double sg_host_route_bandwidth(sg_host_t from, sg_host_t to); +XBT_PUBLIC void sg_host_route(const_sg_host_t from, const_sg_host_t to, xbt_dynar_t links); +XBT_PUBLIC double sg_host_route_latency(const_sg_host_t from, const_sg_host_t to); +XBT_PUBLIC double sg_host_route_bandwidth(const_sg_host_t from, const_sg_host_t to); void sg_host_send_to(sg_host_t from, sg_host_t to, double byte_amount); -XBT_PUBLIC void sg_host_dump(sg_host_t ws); +XBT_PUBLIC void sg_host_dump(const_sg_host_t ws); -XBT_PUBLIC void sg_host_get_actor_list(sg_host_t host, xbt_dynar_t whereto); +XBT_PUBLIC void sg_host_get_actor_list(const_sg_host_t host, xbt_dynar_t whereto); SG_END_DECL #endif /* SIMGRID_HOST_H_ */ diff --git a/include/simgrid/link.h b/include/simgrid/link.h index 2664a53df5..010459b55e 100644 --- a/include/simgrid/link.h +++ b/include/simgrid/link.h @@ -13,12 +13,12 @@ /* C interface */ SG_BEGIN_DECL -XBT_PUBLIC const char* sg_link_name(sg_link_t link); +XBT_PUBLIC const char* sg_link_name(const_sg_link_t link); XBT_PUBLIC sg_link_t sg_link_by_name(const char* name); -XBT_PUBLIC int sg_link_is_shared(sg_link_t link); -XBT_PUBLIC double sg_link_bandwidth(sg_link_t link); -XBT_PUBLIC double sg_link_latency(sg_link_t link); -XBT_PUBLIC void* sg_link_data(sg_link_t link); +XBT_PUBLIC int sg_link_is_shared(const_sg_link_t link); +XBT_PUBLIC double sg_link_bandwidth(const_sg_link_t link); +XBT_PUBLIC double sg_link_latency(const_sg_link_t link); +XBT_PUBLIC void* sg_link_data(const_sg_link_t link); XBT_PUBLIC void sg_link_data_set(sg_link_t link, void* data); XBT_PUBLIC int sg_link_count(); XBT_PUBLIC sg_link_t* sg_link_list(); diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 7169d4294c..059ee658a4 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -98,18 +98,18 @@ XBT_PUBLIC size_t MSG_get_host_number(); XBT_PUBLIC xbt_dynar_t MSG_hosts_as_dynar(); /** @brief Returns the name of this host */ -XBT_PUBLIC const char* MSG_host_get_name(sg_host_t host); +XBT_PUBLIC const char* MSG_host_get_name(const_sg_host_t host); /** @brief Returns the user data of this host */ -XBT_PUBLIC void* MSG_host_get_data(sg_host_t host); +XBT_PUBLIC void* MSG_host_get_data(const_sg_host_t host); /** @brief Sets the user data of this host */ XBT_PUBLIC void MSG_host_set_data(sg_host_t host, void* data); XBT_PUBLIC xbt_dict_t MSG_host_get_mounted_storage_list(sg_host_t host); -XBT_PUBLIC xbt_dynar_t MSG_host_get_attached_storage_lists(sg_host_t host); -XBT_PUBLIC double MSG_host_get_speed(sg_host_t host); -XBT_PUBLIC double MSG_host_get_power_peak_at(sg_host_t host, int pstate_index); -XBT_PUBLIC int MSG_host_get_core_number(sg_host_t host); -XBT_PUBLIC int MSG_host_get_nb_pstates(sg_host_t host); -XBT_PUBLIC int MSG_host_get_pstate(sg_host_t host); +XBT_PUBLIC xbt_dynar_t MSG_host_get_attached_storage_lists(const_sg_host_t host); +XBT_PUBLIC double MSG_host_get_speed(const_sg_host_t host); +XBT_PUBLIC double MSG_host_get_power_peak_at(const_sg_host_t host, int pstate_index); +XBT_PUBLIC int MSG_host_get_core_number(const_sg_host_t host); +XBT_PUBLIC int MSG_host_get_nb_pstates(const_sg_host_t host); +XBT_PUBLIC int MSG_host_get_pstate(const_sg_host_t host); XBT_PUBLIC void MSG_host_set_pstate(sg_host_t host, int pstate); /** @brief Start the host if it is off * @@ -123,15 +123,15 @@ XBT_PUBLIC void MSG_host_on(sg_host_t h); * for more info on DVFS. */ XBT_PUBLIC void MSG_host_off(sg_host_t h); -XBT_PUBLIC int MSG_host_is_on(sg_host_t h); -XBT_PUBLIC xbt_dict_t MSG_host_get_properties(sg_host_t host); -XBT_PUBLIC const char* MSG_host_get_property_value(sg_host_t host, const char* name); +XBT_PUBLIC int MSG_host_is_on(const_sg_host_t h); +XBT_PUBLIC xbt_dict_t MSG_host_get_properties(const_sg_host_t host); +XBT_PUBLIC const char* MSG_host_get_property_value(const_sg_host_t host, const char* name); XBT_PUBLIC void MSG_host_set_property_value(sg_host_t host, const char* name, const char* value); -XBT_PUBLIC void MSG_host_get_process_list(sg_host_t host, xbt_dynar_t whereto); +XBT_PUBLIC void MSG_host_get_process_list(const_sg_host_t host, xbt_dynar_t whereto); /** @brief Return the location on which the current process is executed */ XBT_PUBLIC sg_host_t MSG_host_self(); -XBT_PUBLIC double MSG_host_get_load(sg_host_t host); +XBT_PUBLIC double MSG_host_get_load(const_sg_host_t host); /* ******************************** VMs ************************************* */ typedef sg_vm_t msg_vm_t; @@ -181,19 +181,19 @@ XBT_PUBLIC sg_size_t MSG_storage_write(msg_storage_t storage, sg_size_t size); */ typedef sg_actor_t msg_process_t; -XBT_PUBLIC int MSG_process_get_PID(msg_process_t process); -XBT_PUBLIC int MSG_process_get_PPID(msg_process_t process); +XBT_PUBLIC int MSG_process_get_PID(const_sg_actor_t process); +XBT_PUBLIC int MSG_process_get_PPID(const_sg_actor_t process); /** @brief Return a process from its PID (or NULL if not found). * * Note that the PID are unique in the whole simulation, not only on a given host. */ XBT_PUBLIC sg_actor_t MSG_process_from_PID(int pid); -XBT_PUBLIC const char* MSG_process_get_name(msg_process_t process); -XBT_PUBLIC sg_host_t MSG_process_get_host(msg_process_t process); +XBT_PUBLIC const char* MSG_process_get_name(const_sg_actor_t process); +XBT_PUBLIC sg_host_t MSG_process_get_host(const_sg_actor_t process); /*property handlers*/ -XBT_PUBLIC xbt_dict_t MSG_process_get_properties(msg_process_t process); -XBT_PUBLIC const char* MSG_process_get_property_value(msg_process_t process, const char* name); +XBT_PUBLIC xbt_dict_t MSG_process_get_properties(const_sg_actor_t process); +XBT_PUBLIC const char* MSG_process_get_property_value(const_sg_actor_t process, const char* name); XBT_PUBLIC void MSG_process_suspend(msg_process_t process); XBT_PUBLIC void MSG_process_resume(msg_process_t process); @@ -435,7 +435,7 @@ typedef sg_bar_t msg_bar_t; /** @brief Initializes a barrier, with count elements */ XBT_PUBLIC msg_bar_t MSG_barrier_init(unsigned int count); /** @brief Destroys barrier */ -XBT_PUBLIC void MSG_barrier_destroy(msg_bar_t bar); +XBT_PUBLIC void MSG_barrier_destroy(const_sg_bar_t bar); /** @brief Performs a barrier already initialized */ XBT_PUBLIC int MSG_barrier_wait(msg_bar_t bar); diff --git a/include/simgrid/mutex.h b/include/simgrid/mutex.h index 29ca33582a..b43342b1f9 100644 --- a/include/simgrid/mutex.h +++ b/include/simgrid/mutex.h @@ -14,7 +14,7 @@ XBT_PUBLIC sg_mutex_t sg_mutex_init(); XBT_PUBLIC void sg_mutex_lock(sg_mutex_t mutex); XBT_PUBLIC void sg_mutex_unlock(sg_mutex_t mutex); XBT_PUBLIC int sg_mutex_try_lock(sg_mutex_t mutex); -XBT_PUBLIC void sg_mutex_destroy(sg_mutex_t mutex); +XBT_PUBLIC void sg_mutex_destroy(const_sg_mutex_t mutex); SG_END_DECL diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 22aa42590f..f80ff49ae0 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -56,8 +56,8 @@ public: Actor& operator=(Actor const&) = delete; // ***** Reference count ***** - friend XBT_PUBLIC void intrusive_ptr_add_ref(Actor * actor); - friend XBT_PUBLIC void intrusive_ptr_release(Actor * actor); + friend XBT_PUBLIC void intrusive_ptr_add_ref(const Actor* actor); + friend XBT_PUBLIC void intrusive_ptr_release(const Actor* actor); #endif /** Retrieve the amount of references on that object. Useful to debug the automatic refcounting */ int get_refcount(); diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index 1b3668298a..8d831a25a8 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -49,14 +49,14 @@ public: /*! take a vector s4u::CommPtr and return when one of them is finished. * The return value is the rank of the first finished CommPtr. */ - static int wait_any(std::vector * comms) { return wait_any_for(comms, -1); } + static int wait_any(const std::vector* comms) { return wait_any_for(comms, -1); } /*! Same as wait_any, but with a timeout. If the timeout occurs, parameter last is returned.*/ - static int wait_any_for(std::vector* comms_in, double timeout); + static int wait_any_for(const std::vector* comms_in, double timeout); /*! take a vector s4u::CommPtr and return when all of them is finished. */ - static void wait_all(std::vector* comms); + static void wait_all(const std::vector* comms); /*! take a vector s4u::CommPtr and return the rank of the first finished one (or -1 if none is done). */ - static int test_any(std::vector * comms); + static int test_any(const std::vector* comms); Comm* start() override; Comm* wait() override; diff --git a/include/simgrid/s4u/ConditionVariable.hpp b/include/simgrid/s4u/ConditionVariable.hpp index 946a2d53a7..8e8412757a 100644 --- a/include/simgrid/s4u/ConditionVariable.hpp +++ b/include/simgrid/s4u/ConditionVariable.hpp @@ -35,8 +35,8 @@ public: ConditionVariable(ConditionVariable const&) = delete; ConditionVariable& operator=(ConditionVariable const&) = delete; - friend XBT_PUBLIC void intrusive_ptr_add_ref(ConditionVariable * cond); - friend XBT_PUBLIC void intrusive_ptr_release(ConditionVariable * cond); + friend XBT_PUBLIC void intrusive_ptr_add_ref(const ConditionVariable* cond); + friend XBT_PUBLIC void intrusive_ptr_release(const ConditionVariable* cond); #endif static ConditionVariablePtr create(); @@ -44,8 +44,8 @@ public: // Wait functions without time: void wait(MutexPtr lock); - void wait(std::unique_lock & lock); - template void wait(std::unique_lock & lock, P pred) + void wait(const std::unique_lock& lock); + template void wait(const std::unique_lock& lock, P pred) { while (not pred()) wait(lock); @@ -53,8 +53,8 @@ public: // Wait function taking a plain double as time: - std::cv_status wait_until(std::unique_lock & lock, double timeout_time); - std::cv_status wait_for(std::unique_lock & lock, double duration); + std::cv_status wait_until(const std::unique_lock& lock, double timeout_time); + std::cv_status wait_for(const std::unique_lock& lock, double duration); template bool wait_until(std::unique_lock & lock, double timeout_time, P pred) { while (not pred()) @@ -62,7 +62,7 @@ public: return pred(); return true; } - template bool wait_for(std::unique_lock & lock, double duration, P pred) + template bool wait_for(const std::unique_lock& lock, double duration, P pred) { return this->wait_until(lock, SIMIX_get_clock() + duration, std::move(pred)); } @@ -70,25 +70,25 @@ public: // Wait function taking a C++ style time: template - bool wait_for(std::unique_lock & lock, std::chrono::duration duration, P pred) + bool wait_for(const std::unique_lock& lock, std::chrono::duration duration, P pred) { auto seconds = std::chrono::duration_cast(duration); return this->wait_for(lock, seconds.count(), pred); } template - std::cv_status wait_for(std::unique_lock & lock, std::chrono::duration duration) + std::cv_status wait_for(const std::unique_lock& lock, std::chrono::duration duration) { auto seconds = std::chrono::duration_cast(duration); return this->wait_for(lock, seconds.count()); } template - std::cv_status wait_until(std::unique_lock & lock, const SimulationTimePoint& timeout_time) + std::cv_status wait_until(const std::unique_lock& lock, const SimulationTimePoint& timeout_time) { auto timeout_native = std::chrono::time_point_cast(timeout_time); return this->wait_until(lock, timeout_native.time_since_epoch().count()); } template - bool wait_until(std::unique_lock & lock, const SimulationTimePoint& timeout_time, P pred) + bool wait_until(const std::unique_lock& lock, const SimulationTimePoint& timeout_time, P pred) { auto timeout_native = std::chrono::time_point_cast(timeout_time); return this->wait_until(lock, timeout_native.time_since_epoch().count(), std::move(pred)); diff --git a/include/simgrid/s4u/Disk.hpp b/include/simgrid/s4u/Disk.hpp index 78c411564d..026302cbb2 100644 --- a/include/simgrid/s4u/Disk.hpp +++ b/include/simgrid/s4u/Disk.hpp @@ -50,11 +50,11 @@ public: /** @brief Retrieves the name of that disk as a C string */ const char* get_cname() const { return name_.c_str(); } double get_read_bandwidth() const; - double get_write_bandwidth(); + double get_write_bandwidth() const; const std::unordered_map* get_properties() const; const char* get_property(const std::string& key) const; void set_property(const std::string&, const std::string& value); - Host* get_host(); + Host* get_host() const; IoPtr io_init(sg_size_t size, s4u::Io::OpType type); diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 31f7540997..41586093f2 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -82,9 +82,9 @@ protected: friend kernel::resource::LinkImpl; void host_register(const std::string& name, Host* host); void host_unregister(const std::string& name); - void link_register(const std::string& name, Link* link); + void link_register(const std::string& name, const Link* link); void link_unregister(const std::string& name); - void storage_register(const std::string& name, Storage* storage); + void storage_register(const std::string& name, const Storage* storage); void storage_unregister(const std::string& name); void netpoint_register(simgrid::kernel::routing::NetPoint* card); void netpoint_unregister(simgrid::kernel::routing::NetPoint* card); @@ -119,7 +119,7 @@ public: kernel::routing::NetPoint* netpoint_by_name_or_null(const std::string& name); NetZone* get_netzone_root(); - void set_netzone_root(NetZone* netzone); + void set_netzone_root(const NetZone* netzone); NetZone* netzone_by_name_or_null(const std::string& name); diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index c36c54a71c..b045a2f5c4 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -81,8 +81,8 @@ public: kernel::routing::NetPoint* get_netpoint() const { return pimpl_netpoint_; } - int get_actor_count(); - std::vector get_all_actors(); + int get_actor_count() const; + std::vector get_all_actors() const; /** Turns that host on if it was previously off * @@ -129,8 +129,8 @@ public: */ std::unordered_map const& get_mounted_storages(); - void route_to(Host* dest, std::vector& links, double* latency); - void route_to(Host* dest, std::vector& links, double* latency); + void route_to(const Host* dest, std::vector& links, double* latency) const; + void route_to(const Host* dest, std::vector& links, double* latency) const; void send_to(Host* dest, double byte_amount); NetZone* get_englobing_zone(); diff --git a/include/simgrid/s4u/Link.hpp b/include/simgrid/s4u/Link.hpp index 566430e5e2..ec38e0a30e 100644 --- a/include/simgrid/s4u/Link.hpp +++ b/include/simgrid/s4u/Link.hpp @@ -52,13 +52,13 @@ public: double get_latency() const; /** @brief Describes how the link is shared between flows */ - SharingPolicy get_sharing_policy(); + SharingPolicy get_sharing_policy() const; /** @brief Returns the current load (in flops per second) */ - double get_usage(); + double get_usage() const; /** @brief Check if the Link is used (at least one flow uses the link) */ - bool is_used(); + bool is_used() const; void turn_on(); bool is_on() const; diff --git a/include/simgrid/s4u/Mutex.hpp b/include/simgrid/s4u/Mutex.hpp index fbab117a8d..c208d7d650 100644 --- a/include/simgrid/s4u/Mutex.hpp +++ b/include/simgrid/s4u/Mutex.hpp @@ -32,8 +32,8 @@ class XBT_PUBLIC Mutex { kernel::activity::MutexImpl* const pimpl_; /* refcounting */ - friend XBT_PUBLIC void intrusive_ptr_add_ref(Mutex* mutex); - friend XBT_PUBLIC void intrusive_ptr_release(Mutex* mutex); + friend XBT_PUBLIC void intrusive_ptr_add_ref(const Mutex* mutex); + friend XBT_PUBLIC void intrusive_ptr_release(const Mutex* mutex); public: explicit Mutex(kernel::activity::MutexImpl* mutex) : pimpl_(mutex) {} diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index e95407be73..14cb55f782 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -37,7 +37,7 @@ public: NetZone* get_father(); - std::vector get_all_hosts(); + std::vector get_all_hosts() const; int get_host_count(); kernel::routing::NetZoneImpl* get_impl() const { return pimpl_; } @@ -52,7 +52,7 @@ public: const char* get_property(const std::string& key) const; void set_property(const std::string& key, const std::string& value); - std::vector get_children(); + std::vector get_children() const; /* Add content to the netzone, at parsing time. It should be sealed afterward. */ int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */ diff --git a/include/simgrid/s4u/Storage.hpp b/include/simgrid/s4u/Storage.hpp index 3099a47242..d957650f4c 100644 --- a/include/simgrid/s4u/Storage.hpp +++ b/include/simgrid/s4u/Storage.hpp @@ -52,8 +52,8 @@ public: /** @brief Retrieves the name of that storage as a C string */ const char* get_cname() const { return name_.c_str(); } - const char* get_type(); - Host* get_host() { return attached_to_; }; + const char* get_type() const; + Host* get_host() const { return attached_to_; }; void set_host(Host* host) { attached_to_ = host; } const std::unordered_map* get_properties() const; diff --git a/include/simgrid/semaphore.h b/include/simgrid/semaphore.h index a1eb19e727..c07382543c 100644 --- a/include/simgrid/semaphore.h +++ b/include/simgrid/semaphore.h @@ -17,7 +17,7 @@ XBT_PUBLIC void sg_sem_acquire(sg_sem_t sem); XBT_PUBLIC int sg_sem_acquire_timeout(sg_sem_t sem, double timeout); XBT_PUBLIC void sg_sem_release(sg_sem_t sem); XBT_PUBLIC int sg_sem_get_capacity(sg_sem_t sem); -XBT_PUBLIC void sg_sem_destroy(sg_sem_t sem); +XBT_PUBLIC void sg_sem_destroy(const_sg_sem_t sem); XBT_PUBLIC int sg_sem_would_block(sg_sem_t sem); SG_END_DECL diff --git a/include/simgrid/storage.h b/include/simgrid/storage.h index 8336287350..36ba7c85e6 100644 --- a/include/simgrid/storage.h +++ b/include/simgrid/storage.h @@ -14,15 +14,15 @@ /* C interface */ SG_BEGIN_DECL -XBT_PUBLIC const char* sg_storage_get_name(sg_storage_t storage); +XBT_PUBLIC const char* sg_storage_get_name(const_sg_storage_t storage); XBT_PUBLIC sg_storage_t sg_storage_get_by_name(const char* name); -XBT_PUBLIC xbt_dict_t sg_storage_get_properties(sg_storage_t storage); +XBT_PUBLIC xbt_dict_t sg_storage_get_properties(const_sg_storage_t storage); XBT_PUBLIC void sg_storage_set_property_value(sg_storage_t storage, const char* name, const char* value); -XBT_PUBLIC const char* sg_storage_get_property_value(sg_storage_t storage, const char* name); +XBT_PUBLIC const char* sg_storage_get_property_value(const_sg_storage_t storage, const char* name); XBT_PUBLIC xbt_dynar_t sg_storages_as_dynar(); XBT_PUBLIC void sg_storage_set_data(sg_storage_t host, void* data); -XBT_PUBLIC void* sg_storage_get_data(sg_storage_t storage); -XBT_PUBLIC const char* sg_storage_get_host(sg_storage_t storage); +XBT_PUBLIC void* sg_storage_get_data(const_sg_storage_t storage); +XBT_PUBLIC const char* sg_storage_get_host(const_sg_storage_t storage); XBT_PUBLIC sg_size_t sg_storage_read(sg_storage_t storage, sg_size_t size); XBT_PUBLIC sg_size_t sg_storage_write(sg_storage_t storage, sg_size_t size); diff --git a/include/simgrid/zone.h b/include/simgrid/zone.h index 909f9f9a66..0d3cae0272 100644 --- a/include/simgrid/zone.h +++ b/include/simgrid/zone.h @@ -16,12 +16,12 @@ SG_BEGIN_DECL XBT_PUBLIC sg_netzone_t sg_zone_get_root(); -XBT_PUBLIC const char* sg_zone_get_name(sg_netzone_t zone); +XBT_PUBLIC const char* sg_zone_get_name(const_sg_netzone_t zone); XBT_PUBLIC sg_netzone_t sg_zone_get_by_name(const char* name); -XBT_PUBLIC void sg_zone_get_sons(sg_netzone_t zone, xbt_dict_t whereto); -XBT_PUBLIC const char* sg_zone_get_property_value(sg_netzone_t as, const char* name); -XBT_PUBLIC void sg_zone_set_property_value(sg_netzone_t netzone, const char* name, char* value); -XBT_PUBLIC void sg_zone_get_hosts(sg_netzone_t zone, xbt_dynar_t whereto); +XBT_PUBLIC void sg_zone_get_sons(const_sg_netzone_t zone, xbt_dict_t whereto); +XBT_PUBLIC const char* sg_zone_get_property_value(const_sg_netzone_t as, const char* name); +XBT_PUBLIC void sg_zone_set_property_value(sg_netzone_t netzone, const char* name, const char* value); +XBT_PUBLIC void sg_zone_get_hosts(const_sg_netzone_t zone, xbt_dynar_t whereto); SG_END_DECL diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index 15f74c1f0b..2ed532cc3c 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -312,7 +312,7 @@ static int java_main(int argc, char *argv[]) xbt_assert((jprocess != nullptr), "Process allocation failed."); jprocess = env->NewGlobalRef(jprocess); //bind the process to the context - msg_process_t process = MSG_process_self(); + const_sg_actor_t process = MSG_process_self(); context->jprocess_ = jprocess; /* sets the PID and the PPID of the process */ diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index 6233992e77..a0c640d7fa 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -155,7 +155,7 @@ JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass c } JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, jobject jhost) { - msg_host_t host = jhost_get_native(env, jhost); + const_sg_host_t host = jhost_get_native(env, jhost); if (not host) { jxbt_throw_notbound(env, "host", jhost); @@ -166,7 +166,7 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, jobje } JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, jobject jhost) { - msg_host_t host = jhost_get_native(env, jhost); + const_sg_host_t host = jhost_get_native(env, jhost); if (not host) { jxbt_throw_notbound(env, "host", jhost); @@ -177,7 +177,7 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, } JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname) { - msg_host_t host = jhost_get_native(env, jhost); + const_sg_host_t host = jhost_get_native(env, jhost); if (not host) { jxbt_throw_notbound(env, "host", jhost); @@ -217,7 +217,7 @@ Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isOn(JNIEnv * env, jobject jhost) { - msg_host_t host = jhost_get_native(env, jhost); + const_sg_host_t host = jhost_get_native(env, jhost); if (not host) { jxbt_throw_notbound(env, "host", jhost); @@ -357,28 +357,28 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setPstate(JNIEnv* env, jobject } JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstate(JNIEnv* env, jobject jhost) { - msg_host_t host = jhost_get_native(env, jhost); + const_sg_host_t host = jhost_get_native(env, jhost); return MSG_host_get_pstate(host); } JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstatesCount(JNIEnv* env, jobject jhost) { - msg_host_t host = jhost_get_native(env, jhost); + const_sg_host_t host = jhost_get_native(env, jhost); return MSG_host_get_nb_pstates(host); } JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentPowerPeak(JNIEnv* env, jobject jhost) { - msg_host_t host = jhost_get_native(env, jhost); + const_sg_host_t host = jhost_get_native(env, jhost); return MSG_host_get_speed(host); } JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env, jobject jhost, jint pstate) { - msg_host_t host = jhost_get_native(env, jhost); + const_sg_host_t host = jhost_get_native(env, jhost); return MSG_host_get_power_peak_at(host, pstate); } JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getLoad(JNIEnv* env, jobject jhost) { - msg_host_t host = jhost_get_native(env, jhost); + const_sg_host_t host = jhost_get_native(env, jhost); return MSG_host_get_load(host); } diff --git a/src/bindings/java/jmsg_process.cpp b/src/bindings/java/jmsg_process.cpp index 8a6509df80..1e0ac5b041 100644 --- a/src/bindings/java/jmsg_process.cpp +++ b/src/bindings/java/jmsg_process.cpp @@ -22,7 +22,7 @@ jfieldID jprocess_field_Process_name; jfieldID jprocess_field_Process_pid; jfieldID jprocess_field_Process_ppid; -jobject jprocess_from_native(const simgrid::s4u::Actor* process) +jobject jprocess_from_native(const_sg_actor_t process) { const simgrid::kernel::context::JavaContext* context = static_cast(process->get_impl()->context_.get()); @@ -44,7 +44,7 @@ msg_process_t jprocess_to_native(jobject jprocess, JNIEnv* env) return (msg_process_t)(intptr_t)env->GetLongField(jprocess, jprocess_field_Process_bind); } -void jprocess_bind(jobject jprocess, msg_process_t process, JNIEnv * env) +void jprocess_bind(jobject jprocess, const_sg_actor_t process, JNIEnv* env) { env->SetLongField(jprocess, jprocess_field_Process_bind, (intptr_t)process); } @@ -129,12 +129,12 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jcl JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_nativeGetPID(JNIEnv* env, jobject jprocess) { - msg_process_t process = jprocess_to_native(jprocess, env); + const_sg_actor_t process = jprocess_to_native(jprocess, env); return MSG_process_get_PID(process); } JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname) { - msg_process_t process = jprocess_to_native(jprocess, env); + const_sg_actor_t process = jprocess_to_native(jprocess, env); if (not process) { jxbt_throw_notbound(env, "process", jprocess); diff --git a/src/bindings/java/jmsg_process.h b/src/bindings/java/jmsg_process.h index 174cb087fa..2d94631c67 100644 --- a/src/bindings/java/jmsg_process.h +++ b/src/bindings/java/jmsg_process.h @@ -33,10 +33,10 @@ jobject jprocess_ref(jobject jprocess, JNIEnv* env); void jprocess_unref(jobject jprocess, JNIEnv* env); /** Binds a native instance to a java instance. */ -void jprocess_bind(jobject jprocess, msg_process_t process, JNIEnv* env); +void jprocess_bind(jobject jprocess, const_sg_actor_t process, JNIEnv* env); /** Extract the java instance from the native one */ -jobject jprocess_from_native(const simgrid::s4u::Actor* process); +jobject jprocess_from_native(const_sg_actor_t process); /** Extract the native instance from the java one */ msg_process_t jprocess_to_native(jobject jprocess, JNIEnv* env); diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 1f3acfd8b4..6e8550ef62 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -199,11 +199,12 @@ PYBIND11_MODULE(simgrid, m) "Test whether the communication is terminated, see :cpp:func:`simgrid::s4u::Comm::test()`") .def("wait", [](simgrid::s4u::CommPtr self) { self->wait(); }, "Block until the completion of that communication, see :cpp:func:`simgrid::s4u::Comm::wait()`") - .def("wait_all", [](std::vector* comms) { simgrid::s4u::Comm::wait_all(comms); }, + .def("wait_all", [](const std::vector* comms) { simgrid::s4u::Comm::wait_all(comms); }, "Block until the completion of all communications in the list, see " ":cpp:func:`simgrid::s4u::Comm::wait_all()`") .def( - "wait_any", [](std::vector* comms) { return simgrid::s4u::Comm::wait_any(comms); }, + "wait_any", + [](const std::vector* comms) { return simgrid::s4u::Comm::wait_any(comms); }, "Block until the completion of any communication in the list and return the index of the terminated one, see " ":cpp:func:`simgrid::s4u::Comm::wait_any()`"); py::class_(m, "Exec", "Execution, see :ref:`class s4u::Exec `") diff --git a/src/kernel/resource/DiskImpl.hpp b/src/kernel/resource/DiskImpl.hpp index 9ce6640235..bc1a65fec4 100644 --- a/src/kernel/resource/DiskImpl.hpp +++ b/src/kernel/resource/DiskImpl.hpp @@ -74,7 +74,7 @@ public: void turn_on() override; void turn_off() override; - s4u::Host* get_host() { return host_; } + s4u::Host* get_host() const { return host_; } void set_host(s4u::Host* host) { host_ = host; } void destroy(); // Must be called instead of the destructor diff --git a/src/msg/msg_legacy.cpp b/src/msg/msg_legacy.cpp index e4df590a11..80c28e0a53 100644 --- a/src/msg/msg_legacy.cpp +++ b/src/msg/msg_legacy.cpp @@ -47,11 +47,11 @@ int MSG_task_listen(const char* alias) } /* ************************** Actors *************************** */ -int MSG_process_get_PID(sg_actor_t actor) +int MSG_process_get_PID(const_sg_actor_t actor) { return sg_actor_get_PID(actor); } -int MSG_process_get_PPID(sg_actor_t actor) +int MSG_process_get_PPID(const_sg_actor_t actor) { return sg_actor_get_PPID(actor); } @@ -59,19 +59,19 @@ msg_process_t MSG_process_from_PID(int PID) { return sg_actor_by_PID(PID); } -const char* MSG_process_get_name(sg_actor_t actor) +const char* MSG_process_get_name(const_sg_actor_t actor) { return sg_actor_get_name(actor); } -sg_host_t MSG_process_get_host(sg_actor_t actor) +sg_host_t MSG_process_get_host(const_sg_actor_t actor) { return sg_actor_get_host(actor); } -xbt_dict_t MSG_process_get_properties(sg_actor_t actor) +xbt_dict_t MSG_process_get_properties(const_sg_actor_t actor) { return sg_actor_get_properties(actor); } -const char* MSG_process_get_property_value(sg_actor_t actor, const char* name) +const char* MSG_process_get_property_value(const_sg_actor_t actor, const char* name) { return sg_actor_get_property_value(actor, name); } @@ -304,11 +304,11 @@ sg_host_t MSG_host_by_name(const char* name) { return sg_host_by_name(name); } -const char* MSG_host_get_name(sg_host_t host) +const char* MSG_host_get_name(const_sg_host_t host) { return sg_host_get_name(host); } -void* MSG_host_get_data(sg_host_t host) +void* MSG_host_get_data(const_sg_host_t host) { return sg_host_data(host); } @@ -320,27 +320,27 @@ xbt_dict_t MSG_host_get_mounted_storage_list(sg_host_t host) { return sg_host_get_mounted_storage_list(host); } -xbt_dynar_t MSG_host_get_attached_storage_lists(sg_host_t host) +xbt_dynar_t MSG_host_get_attached_storage_lists(const_sg_host_t host) { return sg_host_get_attached_storage_list(host); } -double MSG_host_get_speed(sg_host_t host) +double MSG_host_get_speed(const_sg_host_t host) { return sg_host_speed(host); } -double MSG_host_get_power_peak_at(sg_host_t host, int pstate_index) +double MSG_host_get_power_peak_at(const_sg_host_t host, int pstate_index) { return sg_host_get_pstate_speed(host, pstate_index); } -int MSG_host_get_core_number(sg_host_t host) +int MSG_host_get_core_number(const_sg_host_t host) { return sg_host_core_count(host); } -int MSG_host_get_nb_pstates(sg_host_t host) +int MSG_host_get_nb_pstates(const_sg_host_t host) { return sg_host_get_nb_pstates(host); } -int MSG_host_get_pstate(sg_host_t host) +int MSG_host_get_pstate(const_sg_host_t host) { return sg_host_get_pstate(host); } @@ -356,15 +356,15 @@ void MSG_host_off(sg_host_t h) { sg_host_turn_off(h); } -int MSG_host_is_on(sg_host_t h) +int MSG_host_is_on(const_sg_host_t h) { return sg_host_is_on(h); } -xbt_dict_t MSG_host_get_properties(sg_host_t host) +xbt_dict_t MSG_host_get_properties(const_sg_host_t host) { return sg_host_get_properties(host); } -const char* MSG_host_get_property_value(sg_host_t host, const char* name) +const char* MSG_host_get_property_value(const_sg_host_t host, const char* name) { return sg_host_get_property_value(host, name); } @@ -372,7 +372,7 @@ void MSG_host_set_property_value(sg_host_t host, const char* name, const char* v { sg_host_set_property_value(host, name, value); } -void MSG_host_get_process_list(sg_host_t host, xbt_dynar_t whereto) +void MSG_host_get_process_list(const_sg_host_t host, xbt_dynar_t whereto) { sg_host_get_actor_list(host, whereto); } @@ -381,7 +381,7 @@ sg_host_t MSG_host_self() return sg_host_self(); } -double MSG_host_get_load(sg_host_t host) +double MSG_host_get_load(const_sg_host_t host) { return sg_host_load(host); } @@ -452,7 +452,7 @@ sg_bar_t MSG_barrier_init(unsigned int count) return sg_barrier_init(count); } -void MSG_barrier_destroy(sg_bar_t bar) +void MSG_barrier_destroy(const_sg_bar_t bar) { sg_barrier_destroy(bar); } diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index df7dc2d058..b3ed7d8221 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -74,11 +74,11 @@ ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::stri return create(name, host, factory(std::move(args))); } -void intrusive_ptr_add_ref(Actor* actor) +void intrusive_ptr_add_ref(const Actor* actor) { intrusive_ptr_add_ref(actor->pimpl_); } -void intrusive_ptr_release(Actor* actor) +void intrusive_ptr_release(const Actor* actor) { intrusive_ptr_release(actor->pimpl_); } @@ -479,7 +479,7 @@ void sg_actor_start(sg_actor_t actor, xbt_main_func_t code, int argc, char** arg * * This function checks whether @a actor is a valid pointer and return its PID (or 0 in case of problem). */ -aid_t sg_actor_get_PID(sg_actor_t actor) +aid_t sg_actor_get_PID(const_sg_actor_t actor) { /* Do not raise an exception here: this function is called by the logs * and the exceptions, so it would be called back again and again */ @@ -494,7 +494,7 @@ aid_t sg_actor_get_PID(sg_actor_t actor) * This function checks whether @a actor is a valid pointer and return its parent's PID. * Returns -1 if the actor has not been created by any other actor. */ -aid_t sg_actor_get_PPID(sg_actor_t actor) +aid_t sg_actor_get_PPID(const_sg_actor_t actor) { return actor->get_ppid(); } @@ -515,12 +515,12 @@ sg_actor_t sg_actor_by_PID(aid_t pid) /** @ingroup m_actor_management * @brief Return the name of an actor. */ -const char* sg_actor_get_name(sg_actor_t actor) +const char* sg_actor_get_name(const_sg_actor_t actor) { return actor->get_cname(); } -sg_host_t sg_actor_get_host(sg_actor_t actor) +sg_host_t sg_actor_get_host(const_sg_actor_t actor) { return actor->get_host(); } @@ -532,7 +532,7 @@ sg_host_t sg_actor_get_host(sg_actor_t actor) * @param name a property name * @return value of a property (or nullptr if the property is not set) */ -const char* sg_actor_get_property_value(sg_actor_t actor, const char* name) +const char* sg_actor_get_property_value(const_sg_actor_t actor, const char* name) { return actor->get_property(name); } @@ -542,7 +542,7 @@ const char* sg_actor_get_property_value(sg_actor_t actor, const char* name) * * This function returns all the parameters associated with an actor */ -xbt_dict_t sg_actor_get_properties(sg_actor_t actor) +xbt_dict_t sg_actor_get_properties(const_sg_actor_t actor) { xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr"); xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); diff --git a/src/s4u/s4u_Barrier.cpp b/src/s4u/s4u_Barrier.cpp index 5002e6f487..dc3dafff2d 100644 --- a/src/s4u/s4u_Barrier.cpp +++ b/src/s4u/s4u_Barrier.cpp @@ -74,7 +74,7 @@ sg_bar_t sg_barrier_init(unsigned int count) } /** @brief Initializes a barrier, with count elements */ -void sg_barrier_destroy(sg_bar_t bar) +void sg_barrier_destroy(const_sg_bar_t bar) { delete bar; } diff --git a/src/s4u/s4u_Comm.cpp b/src/s4u/s4u_Comm.cpp index 9b9ac8bbf2..ea08cc5c0b 100644 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -31,7 +31,7 @@ Comm::~Comm() } } -int Comm::wait_any_for(std::vector* comms, double timeout) +int Comm::wait_any_for(const std::vector* comms, double timeout) { std::unique_ptr rcomms(new kernel::activity::CommImpl*[comms->size()]); std::transform(begin(*comms), end(*comms), rcomms.get(), @@ -39,7 +39,7 @@ int Comm::wait_any_for(std::vector* comms, double timeout) return simcall_comm_waitany(rcomms.get(), comms->size(), timeout); } -void Comm::wait_all(std::vector* comms) +void Comm::wait_all(const std::vector* comms) { // TODO: this should be a simcall or something // TODO: we are missing a version with timeout @@ -182,7 +182,7 @@ Comm* Comm::wait_for(double timeout) } return this; } -int Comm::test_any(std::vector* comms) +int Comm::test_any(const std::vector* comms) { std::unique_ptr rcomms(new kernel::activity::CommImpl*[comms->size()]); std::transform(begin(*comms), end(*comms), rcomms.get(), diff --git a/src/s4u/s4u_ConditionVariable.cpp b/src/s4u/s4u_ConditionVariable.cpp index 0e9683f9db..a8ff8211ce 100644 --- a/src/s4u/s4u_ConditionVariable.cpp +++ b/src/s4u/s4u_ConditionVariable.cpp @@ -31,12 +31,12 @@ void ConditionVariable::wait(MutexPtr lock) simcall_cond_wait(cond_, lock->pimpl_); } -void ConditionVariable::wait(std::unique_lock& lock) +void ConditionVariable::wait(const std::unique_lock& lock) { simcall_cond_wait(cond_, lock.mutex()->pimpl_); } -std::cv_status s4u::ConditionVariable::wait_for(std::unique_lock& lock, double timeout) +std::cv_status s4u::ConditionVariable::wait_for(const std::unique_lock& lock, double timeout) { // The simcall uses -1 for "any timeout" but we don't want this: if (timeout < 0) @@ -51,7 +51,7 @@ std::cv_status s4u::ConditionVariable::wait_for(std::unique_lock& lock, d } } -std::cv_status ConditionVariable::wait_until(std::unique_lock& lock, double timeout_time) +std::cv_status ConditionVariable::wait_until(const std::unique_lock& lock, double timeout_time) { double now = SIMIX_get_clock(); double timeout; @@ -75,12 +75,12 @@ void ConditionVariable::notify_all() simgrid::kernel::actor::simcall([this]() { cond_->broadcast(); }); } -void intrusive_ptr_add_ref(ConditionVariable* cond) +void intrusive_ptr_add_ref(const ConditionVariable* cond) { intrusive_ptr_add_ref(cond->cond_); } -void intrusive_ptr_release(ConditionVariable* cond) +void intrusive_ptr_release(const ConditionVariable* cond) { intrusive_ptr_release(cond->cond_); } @@ -118,7 +118,7 @@ void sg_cond_notify_all(sg_cond_t cond) cond->notify_all(); } -void sg_cond_destroy(sg_cond_t cond) +void sg_cond_destroy(const_sg_cond_t cond) { delete cond; } diff --git a/src/s4u/s4u_Disk.cpp b/src/s4u/s4u_Disk.cpp index 806e090ec9..e974d8dc00 100644 --- a/src/s4u/s4u_Disk.cpp +++ b/src/s4u/s4u_Disk.cpp @@ -25,12 +25,12 @@ double Disk::get_read_bandwidth() const return this->pimpl_->get_read_bandwidth(); } -double Disk::get_write_bandwidth() +double Disk::get_write_bandwidth() const { return pimpl_->get_write_bandwidth(); } -Host* Disk::get_host() +Host* Disk::get_host() const { return pimpl_->get_host(); } diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index ad5327c077..7e7bcfba86 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -194,7 +194,7 @@ Link* Engine::link_by_name_or_null(const std::string& name) return link == pimpl->links_.end() ? nullptr : link->second->get_iface(); } -void Engine::link_register(const std::string& name, Link* link) +void Engine::link_register(const std::string& name, const Link* link) { pimpl->links_[name] = link->get_impl(); } @@ -238,7 +238,7 @@ Storage* Engine::storage_by_name_or_null(const std::string& name) return storage == pimpl->storages_.end() ? nullptr : storage->second->get_iface(); } -void Engine::storage_register(const std::string& name, Storage* storage) +void Engine::storage_register(const std::string& name, const Storage* storage) { pimpl->storages_[name] = storage->get_impl(); } @@ -318,7 +318,7 @@ s4u::NetZone* Engine::get_netzone_root() return pimpl->netzone_root_->get_iface(); } /** @brief Set the root netzone, containing all others. Once set, it cannot be changed. */ -void Engine::set_netzone_root(s4u::NetZone* netzone) +void Engine::set_netzone_root(const s4u::NetZone* netzone) { xbt_assert(pimpl->netzone_root_ == nullptr, "The root NetZone cannot be changed once set"); pimpl->netzone_root_ = netzone->get_impl(); diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 4401c47b8b..3f737173cc 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -126,13 +126,13 @@ int Host::get_pstate_count() const * * Daemons and regular actors are all mixed in this list. */ -std::vector Host::get_all_actors() +std::vector Host::get_all_actors() const { return pimpl_->get_all_actors(); } /** @brief Returns how many actors (daemonized or not) have been launched on this host */ -int Host::get_actor_count() +int Host::get_actor_count() const { return pimpl_->get_actor_count(); } @@ -149,7 +149,7 @@ int Host::get_actor_count() * walk through the routing components tree and find a route between hosts * by calling each "get_route" function in each routing component. */ -void Host::route_to(Host* dest, std::vector& links, double* latency) +void Host::route_to(const Host* dest, std::vector& links, double* latency) const { std::vector linkImpls; this->route_to(dest, linkImpls, latency); @@ -158,7 +158,7 @@ void Host::route_to(Host* dest, std::vector& links, double* latency) } /** @brief Just like Host::routeTo, but filling an array of link implementations */ -void Host::route_to(Host* dest, std::vector& links, double* latency) +void Host::route_to(const Host* dest, std::vector& links, double* latency) const { kernel::routing::NetZoneImpl::get_global_route(pimpl_netpoint_, dest->get_netpoint(), links, latency); if (XBT_LOG_ISENABLED(surf_route, xbt_log_priority_debug)) { @@ -361,12 +361,12 @@ sg_host_t* sg_host_list() return res; } -const char* sg_host_get_name(sg_host_t host) +const char* sg_host_get_name(const_sg_host_t host) { return host->get_cname(); } -void* sg_host_extension_get(sg_host_t host, size_t ext) +void* sg_host_extension_get(const_sg_host_t host, size_t ext) { return host->extension(ext); } @@ -399,7 +399,7 @@ xbt_dynar_t sg_hosts_as_dynar() // ========= Layering madness ==============* // ========== User data Layer ========== -void* sg_host_data(sg_host_t host) +void* sg_host_data(const_sg_host_t host) { return host->get_data(); } @@ -434,7 +434,7 @@ xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host) return res; } -xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host) +xbt_dynar_t sg_host_get_attached_storage_list(const_sg_host_t host) { xbt_dynar_t storage_dynar = xbt_dynar_new(sizeof(const char*), nullptr); std::vector storage_vector = host->get_attached_storages(); @@ -446,7 +446,7 @@ xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host) // =========== user-level functions =============== // ================================================ /** @brief Returns the total speed of a host */ -double sg_host_speed(sg_host_t host) +double sg_host_speed(const_sg_host_t host) { return host->get_speed(); } @@ -457,7 +457,7 @@ double sg_host_speed(sg_host_t host) * @param pstate_index pstate to test * @return Returns the processor speed associated with pstate_index */ -double sg_host_get_pstate_speed(sg_host_t host, int pstate_index) +double sg_host_get_pstate_speed(const_sg_host_t host, int pstate_index) { return host->get_pstate_speed(pstate_index); } @@ -468,12 +468,12 @@ double sg_host_get_pstate_speed(sg_host_t host, int pstate_index) * @param host a host * @return the number of cores */ -int sg_host_core_count(sg_host_t host) +int sg_host_core_count(const_sg_host_t host) { return host->get_core_count(); } -double sg_host_get_available_speed(sg_host_t host) +double sg_host_get_available_speed(const_sg_host_t host) { return host->get_available_speed(); } @@ -482,7 +482,7 @@ double sg_host_get_available_speed(sg_host_t host) * * See also @ref plugin_energy. */ -int sg_host_get_nb_pstates(sg_host_t host) +int sg_host_get_nb_pstates(const_sg_host_t host) { return host->get_pstate_count(); } @@ -491,7 +491,7 @@ int sg_host_get_nb_pstates(sg_host_t host) * * See also @ref plugin_energy. */ -int sg_host_get_pstate(sg_host_t host) +int sg_host_get_pstate(const_sg_host_t host) { return host->get_pstate(); } @@ -537,13 +537,13 @@ void sg_host_turn_off(sg_host_t host) * @param host host to test * @return Returns true if the host is up and running, and false if it's currently down */ -int sg_host_is_on(sg_host_t host) +int sg_host_is_on(const_sg_host_t host) { return host->is_on(); } /** @brief Get the properties of a host */ -xbt_dict_t sg_host_get_properties(sg_host_t host) +xbt_dict_t sg_host_get_properties(const_sg_host_t host) { xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); const std::unordered_map* props = host->get_properties(); @@ -562,7 +562,7 @@ xbt_dict_t sg_host_get_properties(sg_host_t host) * @param name a property name * @return value of a property (or nullptr if property not set) */ -const char* sg_host_get_property_value(sg_host_t host, const char* name) +const char* sg_host_get_property_value(const_sg_host_t host, const char* name) { return host->get_property(name); } @@ -579,7 +579,7 @@ void sg_host_set_property_value(sg_host_t host, const char* name, const char* va * @param to where to * @param links [OUT] where to store the list of links (must exist, cannot be nullptr). */ -void sg_host_route(sg_host_t from, sg_host_t to, xbt_dynar_t links) +void sg_host_route(const_sg_host_t from, const_sg_host_t to, xbt_dynar_t links) { std::vector vlinks; from->route_to(to, vlinks, nullptr); @@ -592,7 +592,7 @@ void sg_host_route(sg_host_t from, sg_host_t to, xbt_dynar_t links) * @param from where from * @param to where to */ -double sg_host_route_latency(sg_host_t from, sg_host_t to) +double sg_host_route_latency(const_sg_host_t from, const_sg_host_t to) { std::vector vlinks; double res = 0; @@ -605,7 +605,7 @@ double sg_host_route_latency(sg_host_t from, sg_host_t to) * @param from where from * @param to where to */ -double sg_host_route_bandwidth(sg_host_t from, sg_host_t to) +double sg_host_route_bandwidth(const_sg_host_t from, const_sg_host_t to) { double min_bandwidth = -1.0; @@ -625,7 +625,7 @@ void sg_host_send_to(sg_host_t from, sg_host_t to, double byte_amount) } /** @brief Displays debugging information about a host */ -void sg_host_dump(sg_host_t host) +void sg_host_dump(const_sg_host_t host) { XBT_INFO("Displaying host %s", host->get_cname()); XBT_INFO(" - speed: %.0f", host->get_speed()); @@ -645,7 +645,7 @@ void sg_host_dump(sg_host_t host) * @param host a host * @param whereto a dynar in which we should push actors living on that host */ -void sg_host_get_actor_list(sg_host_t host, xbt_dynar_t whereto) +void sg_host_get_actor_list(const_sg_host_t host, xbt_dynar_t whereto) { auto const actors = host->get_all_actors(); for (auto const& actor : actors) @@ -669,7 +669,7 @@ const char* sg_host_self_get_name() return res; } -double sg_host_load(sg_host_t host) +double sg_host_load(const_sg_host_t host) { return host->get_load(); } diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index 742f0628e3..75d34866cc 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -42,7 +42,7 @@ const char* Link::get_cname() const { return this->pimpl_->get_cname(); } -bool Link::is_used() +bool Link::is_used() const { return this->pimpl_->is_used(); } @@ -57,12 +57,12 @@ double Link::get_bandwidth() const return this->pimpl_->get_bandwidth(); } -Link::SharingPolicy Link::get_sharing_policy() +Link::SharingPolicy Link::get_sharing_policy() const { return this->pimpl_->get_sharing_policy(); } -double Link::get_usage() +double Link::get_usage() const { return this->pimpl_->get_constraint()->get_usage(); } @@ -107,7 +107,7 @@ void Link::set_property(const std::string& key, const std::string& value) /* **************************** Public C interface *************************** */ -const char* sg_link_name(sg_link_t link) +const char* sg_link_name(const_sg_link_t link) { return link->get_cname(); } @@ -116,19 +116,19 @@ sg_link_t sg_link_by_name(const char* name) return simgrid::s4u::Link::by_name(name); } -int sg_link_is_shared(sg_link_t link) +int sg_link_is_shared(const_sg_link_t link) { return (int)link->get_sharing_policy(); } -double sg_link_bandwidth(sg_link_t link) +double sg_link_bandwidth(const_sg_link_t link) { return link->get_bandwidth(); } -double sg_link_latency(sg_link_t link) +double sg_link_latency(const_sg_link_t link) { return link->get_latency(); } -void* sg_link_data(sg_link_t link) +void* sg_link_data(const_sg_link_t link) { return link->get_data(); } diff --git a/src/s4u/s4u_Mutex.cpp b/src/s4u/s4u_Mutex.cpp index 6494276c9a..e6c8d9e034 100644 --- a/src/s4u/s4u_Mutex.cpp +++ b/src/s4u/s4u_Mutex.cpp @@ -49,13 +49,13 @@ MutexPtr Mutex::create() } /* refcounting of the intrusive_ptr is delegated to the implementation object */ -void intrusive_ptr_add_ref(Mutex* mutex) +void intrusive_ptr_add_ref(const Mutex* mutex) { xbt_assert(mutex); if (mutex->pimpl_) mutex->pimpl_->ref(); } -void intrusive_ptr_release(Mutex* mutex) +void intrusive_ptr_release(const Mutex* mutex) { xbt_assert(mutex); if (mutex->pimpl_) @@ -89,7 +89,7 @@ int sg_mutex_try_lock(sg_mutex_t mutex) return mutex->try_lock(); } -void sg_mutex_destroy(sg_mutex_t mutex) +void sg_mutex_destroy(const_sg_mutex_t mutex) { delete mutex; } diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index b5cdbce1c9..acf827eaad 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -36,7 +36,7 @@ void NetZone::set_property(const std::string& key, const std::string& value) } /** @brief Returns the list of direct children (no grand-children) */ -std::vector NetZone::get_children() +std::vector NetZone::get_children() const { std::vector res; for (auto child : *(pimpl_->get_children())) @@ -62,7 +62,7 @@ NetZone* NetZone::get_father() * Only the hosts that are directly contained in this NetZone are retrieved, * not the ones contained in sub-netzones. */ -std::vector NetZone::get_all_hosts() +std::vector NetZone::get_all_hosts() const { return pimpl_->get_all_hosts(); } @@ -99,7 +99,7 @@ sg_netzone_t sg_zone_get_root() return simgrid::s4u::Engine::get_instance()->get_netzone_root(); } -const char* sg_zone_get_name(sg_netzone_t netzone) +const char* sg_zone_get_name(const_sg_netzone_t netzone) { return netzone->get_cname(); } @@ -109,24 +109,24 @@ sg_netzone_t sg_zone_get_by_name(const char* name) return simgrid::s4u::Engine::get_instance()->netzone_by_name_or_null(name); } -void sg_zone_get_sons(sg_netzone_t netzone, xbt_dict_t whereto) +void sg_zone_get_sons(const_sg_netzone_t netzone, xbt_dict_t whereto) { for (auto const& elem : netzone->get_children()) { xbt_dict_set(whereto, elem->get_cname(), static_cast(elem)); } } -const char* sg_zone_get_property_value(sg_netzone_t netzone, const char* name) +const char* sg_zone_get_property_value(const_sg_netzone_t netzone, const char* name) { return netzone->get_property(name); } -void sg_zone_set_property_value(sg_netzone_t netzone, const char* name, char* value) +void sg_zone_set_property_value(sg_netzone_t netzone, const char* name, const char* value) { netzone->set_property(name, value); } -void sg_zone_get_hosts(sg_netzone_t netzone, xbt_dynar_t whereto) +void sg_zone_get_hosts(const_sg_netzone_t netzone, xbt_dynar_t whereto) { /* converts vector to dynar */ std::vector hosts = netzone->get_all_hosts(); diff --git a/src/s4u/s4u_Semaphore.cpp b/src/s4u/s4u_Semaphore.cpp index debf3ecda3..9e14147af6 100644 --- a/src/s4u/s4u_Semaphore.cpp +++ b/src/s4u/s4u_Semaphore.cpp @@ -104,7 +104,7 @@ int sg_sem_get_capacity(sg_sem_t sem) return sem->get_capacity(); } -void sg_sem_destroy(sg_sem_t sem) +void sg_sem_destroy(const_sg_sem_t sem) { delete sem; } diff --git a/src/s4u/s4u_Storage.cpp b/src/s4u/s4u_Storage.cpp index ba76eac324..8b9a4ecb38 100644 --- a/src/s4u/s4u_Storage.cpp +++ b/src/s4u/s4u_Storage.cpp @@ -36,7 +36,7 @@ Storage* Storage::by_name_or_null(const std::string& name) return Engine::get_instance()->storage_by_name_or_null(name); } -const char* Storage::get_type() +const char* Storage::get_type() const { return pimpl_->typeId_.c_str(); } @@ -96,13 +96,13 @@ sg_size_t Storage::write(sg_size_t size) * * This functions checks whether a storage is a valid pointer or not and return its name. */ -const char* sg_storage_get_name(sg_storage_t storage) +const char* sg_storage_get_name(const_sg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters"); return storage->get_cname(); } -const char* sg_storage_get_host(sg_storage_t storage) +const char* sg_storage_get_host(const_sg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters"); return storage->get_host()->get_cname(); @@ -113,7 +113,7 @@ const char* sg_storage_get_host(sg_storage_t storage) * @param storage a storage * @return a dict containing the properties */ -xbt_dict_t sg_storage_get_properties(sg_storage_t storage) +xbt_dict_t sg_storage_get_properties(const_sg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)"); xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); @@ -145,7 +145,7 @@ void sg_storage_set_property_value(sg_storage_t storage, const char* name, const * @param name a property name * @return value of a property (or nullptr if property not set) */ -const char* sg_storage_get_property_value(sg_storage_t storage, const char* name) +const char* sg_storage_get_property_value(const_sg_storage_t storage, const char* name) { return storage->get_property(name); } @@ -172,7 +172,7 @@ xbt_dynar_t sg_storages_as_dynar() return res; } -void* sg_storage_get_data(sg_storage_t storage) +void* sg_storage_get_data(const_sg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters"); return storage->get_data(); diff --git a/teshsuite/msg/process-migration/process-migration.c b/teshsuite/msg/process-migration/process-migration.c index 66322d217b..f7911a3b4c 100644 --- a/teshsuite/msg/process-migration/process-migration.c +++ b/teshsuite/msg/process-migration/process-migration.c @@ -28,7 +28,7 @@ static int emigrant(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) controlled_process = MSG_process_self(); /* - Get controlled at checkpoint */ MSG_barrier_wait(barrier); MSG_process_suspend(MSG_process_self()); - msg_host_t h = MSG_process_get_host(MSG_process_self()); + const_sg_host_t h = MSG_process_get_host(MSG_process_self()); XBT_INFO("I've been moved on this new host: %s", MSG_host_get_name(h)); XBT_INFO("Uh, nothing to do here. Stopping now"); return 0; diff --git a/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c b/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c index c262726029..d59ce1d013 100644 --- a/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c +++ b/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c @@ -18,8 +18,8 @@ int main(int argc, char **argv) sg_host_t *hosts = sg_host_list(); if (argc >= 3) { if (!strcmp(argv[2], "ONE_LINK")) { - sg_host_t h1 = hosts[0]; - sg_host_t h2 = hosts[1]; + const_sg_host_t h1 = hosts[0]; + const_sg_host_t h2 = hosts[1]; const char *name1 = sg_host_get_name(h1); const char *name2 = sg_host_get_name(h2); @@ -39,10 +39,10 @@ int main(int argc, char **argv) if (!strcmp(argv[2], "FULL_LINK")) { int list_size = sg_host_count(); for (int i = 0; i < list_size; i++) { - sg_host_t h1 = hosts[i]; + const_sg_host_t h1 = hosts[i]; const char *name1 = sg_host_get_name(h1); for (int j = 0; j < list_size; j++) { - sg_host_t h2 = hosts[j]; + const_sg_host_t h2 = hosts[j]; const char *name2 = sg_host_get_name(h2); fprintf(stderr, "Route between %s and %s\n", name1, name2); xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL); diff --git a/teshsuite/simdag/evaluate-get-route-time/evaluate-get-route-time.c b/teshsuite/simdag/evaluate-get-route-time/evaluate-get-route-time.c index 7feb036100..1a6898e5d1 100644 --- a/teshsuite/simdag/evaluate-get-route-time/evaluate-get-route-time.c +++ b/teshsuite/simdag/evaluate-get-route-time/evaluate-get-route-time.c @@ -33,8 +33,8 @@ int main(int argc, char **argv) j = rand()%host_count; } while(i==j); - sg_host_t h1 = hosts[i]; - sg_host_t h2 = hosts[j]; + const_sg_host_t h1 = hosts[i]; + const_sg_host_t h2 = hosts[j]; printf("%d\tand\t%d\t\t",i,j); xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL); diff --git a/teshsuite/simdag/flatifier/flatifier.cpp b/teshsuite/simdag/flatifier/flatifier.cpp index 338f43b87f..fd9f9140ce 100644 --- a/teshsuite/simdag/flatifier/flatifier.cpp +++ b/teshsuite/simdag/flatifier/flatifier.cpp @@ -45,7 +45,7 @@ static void dump_hosts() unsigned int totalHosts = sg_host_count(); sg_host_t* hosts = sg_host_list(); std::sort(hosts, hosts + totalHosts, - [](sg_host_t a, sg_host_t b) { return strcmp(sg_host_get_name(a), sg_host_get_name(b)) < 0; }); + [](const_sg_host_t a, const_sg_host_t b) { return strcmp(sg_host_get_name(a), sg_host_get_name(b)) < 0; }); for (unsigned int i = 0; i < totalHosts; i++) { std::printf(" get_cname(), sg_host_speed(hosts[i])); -- 2.20.1