From e7dbf98c9905d9281223f93d53b0038cc6ea9a1e Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 22 May 2023 17:13:14 +0200 Subject: [PATCH] Add instance signals for all Disk signals --- docs/source/Plugins.rst | 2 ++ docs/source/app_s4u.rst | 2 ++ include/simgrid/s4u/Disk.hpp | 10 ++++++++-- src/kernel/resource/DiskImpl.cpp | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/source/Plugins.rst b/docs/source/Plugins.rst index a173215837..b3678c4a4d 100644 --- a/docs/source/Plugins.rst +++ b/docs/source/Plugins.rst @@ -90,7 +90,9 @@ Partial list of existing signals in s4u: :cpp:func:`CommImpl::on_completion ` - :cpp:func:`Disk::on_creation ` :cpp:func:`Disk::on_destruction ` + :cpp:func:`Disk::on_this_destruction ` :cpp:func:`Disk::on_state_change ` + :cpp:func:`Disk::on_this_state_change ` - :cpp:func:`Engine::on_platform_creation ` :cpp:func:`Engine::on_platform_created ` :cpp:func:`Engine::on_time_advance ` diff --git a/docs/source/app_s4u.rst b/docs/source/app_s4u.rst index b768946bc5..b5b7d66a56 100644 --- a/docs/source/app_s4u.rst +++ b/docs/source/app_s4u.rst @@ -1212,7 +1212,9 @@ Signals .. doxygenfunction:: simgrid::s4u::Disk::on_creation_cb .. doxygenfunction:: simgrid::s4u::Disk::on_destruction_cb + .. doxygenfunction:: simgrid::s4u::Disk::on_this_destruction_cb .. doxygenfunction:: simgrid::s4u::Disk::on_state_change_cb + .. doxygenfunction:: simgrid::s4u::Disk::on_this_state_change_cb .. _API_s4u_Host: diff --git a/include/simgrid/s4u/Disk.hpp b/include/simgrid/s4u/Disk.hpp index fcba914a0f..46fc2f72e3 100644 --- a/include/simgrid/s4u/Disk.hpp +++ b/include/simgrid/s4u/Disk.hpp @@ -135,15 +135,21 @@ public: /* The signals */ /** @brief Add a callback fired when a new Disk is created */ static void on_creation_cb(const std::function& cb) { on_creation.connect(cb); } - /** @brief Add a callback fired when a Disk is destroyed */ + /** @brief Add a callback fired when any Disk is destroyed */ static void on_destruction_cb(const std::function& cb) { on_destruction.connect(cb); } - /** @brief Add a callback fired when a Disk's state changes */ + /** @brief Add a callback fired when this specific Disk is destroyed */ + void on_this_destruction_cb(const std::function& cb) { on_this_destruction.connect(cb); } + /** @brief Add a callback fired when the state of any Disk changes */ static void on_state_change_cb(const std::function& cb) { on_state_change.connect(cb); } + /** @brief Add a callback fired when the state of this specific Disk changes */ + void on_this_state_change_cb(const std::function& cb) { on_this_state_change.connect(cb); } private: static xbt::signal on_creation; static xbt::signal on_destruction; + xbt::signal on_this_destruction; static xbt::signal on_state_change; + xbt::signal on_this_state_change; }; } // namespace s4u diff --git a/src/kernel/resource/DiskImpl.cpp b/src/kernel/resource/DiskImpl.cpp index 1903b81d68..bad94356a6 100644 --- a/src/kernel/resource/DiskImpl.cpp +++ b/src/kernel/resource/DiskImpl.cpp @@ -53,6 +53,7 @@ DiskImpl* DiskImpl::set_write_constraint(lmm::Constraint* constraint_write) void DiskImpl::destroy() { s4u::Disk::on_destruction(piface_); + piface_.on_this_destruction(piface_); delete this; } @@ -61,6 +62,7 @@ void DiskImpl::turn_on() if (not is_on()) { Resource::turn_on(); s4u::Disk::on_state_change(piface_); + piface_.on_this_state_change(piface_); } } void DiskImpl::turn_off() @@ -68,6 +70,7 @@ void DiskImpl::turn_off() if (is_on()) { Resource::turn_off(); s4u::Disk::on_state_change(piface_); + piface_.on_this_state_change(piface_); const kernel::lmm::Element* elem = nullptr; double now = EngineImpl::get_clock(); -- 2.20.1