From 7f960794190d563e58d57286c7401f0d4e2892d4 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 18 Nov 2020 15:06:09 +0100 Subject: [PATCH] More const. --- docs/source/app_s4u.rst | 16 ++++++++-------- examples/c/actor-join/actor-join.c | 2 +- include/simgrid/actor.h | 2 +- include/simgrid/msg.h | 6 +++--- include/simgrid/s4u/Actor.hpp | 4 ++-- include/simgrid/s4u/Semaphore.hpp | 4 ++-- include/simgrid/s4u/VirtualMachine.hpp | 2 +- include/simgrid/semaphore.h | 4 ++-- src/bindings/java/jmsg_vm.cpp | 2 +- src/bindings/python/simgrid_python.cpp | 2 +- src/msg/msg_legacy.cpp | 6 +++--- src/plugins/vm/s4u_VirtualMachine.cpp | 2 +- src/s4u/s4u_Actor.cpp | 6 +++--- src/s4u/s4u_Semaphore.cpp | 8 ++++---- 14 files changed, 33 insertions(+), 33 deletions(-) diff --git a/docs/source/app_s4u.rst b/docs/source/app_s4u.rst index e241839035..be046e3f65 100644 --- a/docs/source/app_s4u.rst +++ b/docs/source/app_s4u.rst @@ -579,8 +579,8 @@ Reacting to the end of actors .. group-tab:: C++ .. autodoxymethod:: simgrid::s4u::Actor::on_exit - .. autodoxymethod:: simgrid::s4u::Actor::join() - .. autodoxymethod:: simgrid::s4u::Actor::join(double timeout) + .. autodoxymethod:: simgrid::s4u::Actor::join() const + .. autodoxymethod:: simgrid::s4u::Actor::join(double timeout) const .. autodoxymethod:: simgrid::s4u::Actor::set_auto_restart(bool autorestart) .. group-tab:: Python @@ -589,7 +589,7 @@ Reacting to the end of actors .. group-tab:: C - .. autodoxymethod:: sg_actor_join(sg_actor_t actor, double timeout) + .. autodoxymethod:: sg_actor_join(const_sg_actor_t actor, double timeout) .. autodoxymethod:: sg_actor_set_auto_restart(sg_actor_t actor, int auto_restart) Signals @@ -1625,7 +1625,7 @@ Querying info .. autodoxymethod:: simgrid::s4u::VirtualMachine::get_pm() const .. autodoxymethod:: simgrid::s4u::VirtualMachine::get_ramsize() const - .. autodoxymethod:: simgrid::s4u::VirtualMachine::get_state() + .. autodoxymethod:: simgrid::s4u::VirtualMachine::get_state() const .. autodoxymethod:: simgrid::s4u::VirtualMachine::set_bound(double bound) .. autodoxymethod:: simgrid::s4u::VirtualMachine::set_pm(Host *pm) @@ -2168,17 +2168,17 @@ Locking .. autodoxymethod:: simgrid::s4u::Semaphore::acquire() .. autodoxymethod:: simgrid::s4u::Semaphore::acquire_timeout(double timeout) - .. autodoxymethod:: simgrid::s4u::Semaphore::get_capacity() + .. autodoxymethod:: simgrid::s4u::Semaphore::get_capacity() const .. autodoxymethod:: simgrid::s4u::Semaphore::release() - .. autodoxymethod:: simgrid::s4u::Semaphore::would_block() + .. autodoxymethod:: simgrid::s4u::Semaphore::would_block() const .. group-tab:: C .. autodoxymethod:: sg_sem_acquire(sg_sem_t sem) .. autodoxymethod:: sg_sem_acquire_timeout(sg_sem_t sem, double timeout) - .. autodoxymethod:: sg_sem_get_capacity(sg_sem_t sem) + .. autodoxymethod:: sg_sem_get_capacity(const_sg_sem_t sem) .. autodoxymethod:: sg_sem_release(sg_sem_t sem) - .. autodoxymethod:: sg_sem_would_block(sg_sem_t sem) + .. autodoxymethod:: sg_sem_would_block(const_sg_sem_t sem) .. |hr| raw:: html diff --git a/examples/c/actor-join/actor-join.c b/examples/c/actor-join/actor-join.c index fdbd215cba..efdaa19585 100644 --- a/examples/c/actor-join/actor-join.c +++ b/examples/c/actor-join/actor-join.c @@ -22,7 +22,7 @@ static void sleeper(int argc, char* argv[]) static void master(int argc, char* argv[]) { - sg_actor_t actor; + const_sg_actor_t actor; XBT_INFO("Start sleeper"); actor = sg_actor_create("sleeper from master", sg_host_self(), sleeper, 0, NULL); diff --git a/include/simgrid/actor.h b/include/simgrid/actor.h index 3278ef63bd..6fb3693480 100644 --- a/include/simgrid/actor.h +++ b/include/simgrid/actor.h @@ -56,7 +56,7 @@ XBT_ATTRIB_DEPRECATED_v329("Please use sg_actor_set_host() instead") XBT_PUBLIC #endif XBT_PUBLIC void sg_actor_set_host(sg_actor_t actor, sg_host_t host); -XBT_PUBLIC void sg_actor_join(sg_actor_t actor, double timeout); +XBT_PUBLIC void sg_actor_join(const_sg_actor_t actor, double timeout); XBT_PUBLIC void sg_actor_kill(sg_actor_t actor); XBT_PUBLIC void sg_actor_kill_all(); XBT_PUBLIC void sg_actor_set_kill_time(sg_actor_t actor, double kill_time); diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 33ab45c106..b39a6723d0 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -223,7 +223,7 @@ XBT_PUBLIC void MSG_process_migrate(msg_process_t process, msg_host_t host); * @param process the process to wait for * @param timeout wait until the process is over, or the timeout occurs */ -XBT_PUBLIC void MSG_process_join(msg_process_t process, double timeout); +XBT_PUBLIC void MSG_process_join(const_sg_actor_t process, double timeout); /** @brief Kills a process */ XBT_PUBLIC void MSG_process_kill(msg_process_t process); /** @brief Kill all running process */ @@ -435,9 +435,9 @@ XBT_PUBLIC msg_sem_t MSG_sem_init(int initial_value); XBT_PUBLIC void MSG_sem_acquire(msg_sem_t sem); XBT_PUBLIC int MSG_sem_acquire_timeout(msg_sem_t sem, double timeout); XBT_PUBLIC void MSG_sem_release(msg_sem_t sem); -XBT_PUBLIC int MSG_sem_get_capacity(msg_sem_t sem); +XBT_PUBLIC int MSG_sem_get_capacity(const_sg_sem_t sem); XBT_PUBLIC void MSG_sem_destroy(const_sg_sem_t sem); -XBT_PUBLIC int MSG_sem_would_block(msg_sem_t sem); +XBT_PUBLIC int MSG_sem_would_block(const_sg_sem_t sem); /** @brief Opaque type representing a barrier identifier */ typedef sg_bar_t msg_bar_t; diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index a4b6438c60..0f8b058907 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -207,14 +207,14 @@ public: * Blocks the calling actor until the joined actor is terminated. If actor alice executes bob.join(), then alice is * blocked until bob terminates. */ - void join(); + void join() const; /** Wait for the actor to finish, or for the timeout to elapse. * * Blocks the calling actor until the joined actor is terminated. If actor alice executes bob.join(), then alice is * blocked until bob terminates. */ - void join(double timeout); + void join(double timeout) const; /** Kill that actor and restart it from start. */ Actor* restart(); diff --git a/include/simgrid/s4u/Semaphore.hpp b/include/simgrid/s4u/Semaphore.hpp index 602553d4cb..c3296bfcf7 100644 --- a/include/simgrid/s4u/Semaphore.hpp +++ b/include/simgrid/s4u/Semaphore.hpp @@ -50,8 +50,8 @@ public: void acquire(); int acquire_timeout(double timeout); void release(); - int get_capacity(); - int would_block(); + int get_capacity() const; + int would_block() const; }; } // namespace s4u diff --git a/include/simgrid/s4u/VirtualMachine.hpp b/include/simgrid/s4u/VirtualMachine.hpp index 1ef5069fb2..f228203e53 100644 --- a/include/simgrid/s4u/VirtualMachine.hpp +++ b/include/simgrid/s4u/VirtualMachine.hpp @@ -54,7 +54,7 @@ public: VirtualMachine* set_ramsize(size_t ramsize); VirtualMachine* set_bound(double bound); - VirtualMachine::state get_state(); + VirtualMachine::state get_state() const; static xbt::signal on_start; static xbt::signal on_started; static xbt::signal on_shutdown; diff --git a/include/simgrid/semaphore.h b/include/simgrid/semaphore.h index 730a0899c1..ad11cacf9e 100644 --- a/include/simgrid/semaphore.h +++ b/include/simgrid/semaphore.h @@ -16,9 +16,9 @@ XBT_PUBLIC sg_sem_t sg_sem_init(int initial_value); 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 int sg_sem_get_capacity(const_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); +XBT_PUBLIC int sg_sem_would_block(const_sg_sem_t sem); SG_END_DECL diff --git a/src/bindings/java/jmsg_vm.cpp b/src/bindings/java/jmsg_vm.cpp index 8e3193b441..639c15d309 100644 --- a/src/bindings/java/jmsg_vm.cpp +++ b/src/bindings/java/jmsg_vm.cpp @@ -89,7 +89,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_VM_all(JNIEnv* env, jclass c std::vector vms; for (size_t i = 0; i < host_count; i++) { - auto* vm = dynamic_cast(hosts[i]); + const auto* vm = dynamic_cast(hosts[i]); if (vm != nullptr && vm->get_state() != simgrid::s4u::VirtualMachine::state::DESTROYED) { auto jvm = static_cast(vm->extension(JAVA_HOST_LEVEL)); vms.push_back(jvm); diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index b8791b02fb..fc492d5b2d 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -344,7 +344,7 @@ PYBIND11_MODULE(simgrid, m) .def("is_daemon", &Actor::is_daemon, "Returns True if that actor is a daemon and will be terminated automatically when the last non-daemon actor " "terminates.") - .def("join", py::overload_cast(&Actor::join), py::call_guard(), + .def("join", py::overload_cast(&Actor::join, py::const_), py::call_guard(), "Wait for the actor to finish (more info in the C++ documentation).", py::arg("timeout")) .def("kill", &Actor::kill, py::call_guard(), "Kill that actor") .def("kill_all", &Actor::kill_all, py::call_guard(), "Kill all actors but the caller.") diff --git a/src/msg/msg_legacy.cpp b/src/msg/msg_legacy.cpp index 4d0d80acc4..4adb63186c 100644 --- a/src/msg/msg_legacy.cpp +++ b/src/msg/msg_legacy.cpp @@ -117,7 +117,7 @@ void MSG_process_migrate(sg_actor_t actor, sg_host_t host) { sg_actor_set_host(actor, host); } -void MSG_process_join(sg_actor_t actor, double timeout) +void MSG_process_join(const_sg_actor_t actor, double timeout) { sg_actor_join(actor, timeout); } @@ -499,7 +499,7 @@ void MSG_sem_release(sg_sem_t sem) { sg_sem_release(sem); } -int MSG_sem_get_capacity(sg_sem_t sem) +int MSG_sem_get_capacity(const_sg_sem_t sem) { return sg_sem_get_capacity(sem); } @@ -507,7 +507,7 @@ void MSG_sem_destroy(const_sg_sem_t sem) { sg_sem_destroy(sem); } -int MSG_sem_would_block(sg_sem_t sem) +int MSG_sem_would_block(const_sg_sem_t sem) { return sg_sem_would_block(sem); } diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 8c3963ad60..6813e18e18 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -137,7 +137,7 @@ VirtualMachine* VirtualMachine::set_pm(simgrid::s4u::Host* pm) return this; } -VirtualMachine::state VirtualMachine::get_state() +VirtualMachine::state VirtualMachine::get_state() const { return kernel::actor::simcall([this]() { return pimpl_vm_->get_state(); }); } diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index f9b4272006..5588ce955f 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -103,12 +103,12 @@ int Actor::get_refcount() const // ***** Actor methods ***** -void Actor::join() +void Actor::join() const { join(-1); } -void Actor::join(double timeout) +void Actor::join(double timeout) const { kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self(); const kernel::actor::ActorImpl* target = pimpl_; @@ -676,7 +676,7 @@ void sg_actor_migrate(sg_actor_t process, sg_host_t host) // XBT_ATTRIB_DEPRECAT * @param actor the actor to wait for * @param timeout wait until the actor is over, or the timeout expires */ -void sg_actor_join(sg_actor_t actor, double timeout) +void sg_actor_join(const_sg_actor_t actor, double timeout) { actor->join(timeout); } diff --git a/src/s4u/s4u_Semaphore.cpp b/src/s4u/s4u_Semaphore.cpp index b4a5ed709c..3d8d8c0b1d 100644 --- a/src/s4u/s4u_Semaphore.cpp +++ b/src/s4u/s4u_Semaphore.cpp @@ -46,12 +46,12 @@ void Semaphore::release() kernel::actor::simcall([this] { sem_->release(); }); } -int Semaphore::get_capacity() +int Semaphore::get_capacity() const { return kernel::actor::simcall([this] { return sem_->get_capacity(); }); } -int Semaphore::would_block() +int Semaphore::would_block() const { return kernel::actor::simcall([this] { return sem_->would_block(); }); } @@ -99,7 +99,7 @@ void sg_sem_release(sg_sem_t sem) sem->release(); } -int sg_sem_get_capacity(sg_sem_t sem) +int sg_sem_get_capacity(const_sg_sem_t sem) { return sem->get_capacity(); } @@ -114,7 +114,7 @@ void sg_sem_destroy(const_sg_sem_t sem) * Note that the returned value may be wrong right after the function call, when you try to use it... * But that's a classical semaphore issue, and SimGrid's semaphore are not different to usual ones here. */ -int sg_sem_would_block(sg_sem_t sem) +int sg_sem_would_block(const_sg_sem_t sem) { return sem->would_block(); } -- 2.20.1