From efd5719fdcd06a99d1fd644b81c7e9d578c08fc5 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Wed, 13 Jan 2016 11:24:21 +0100 Subject: [PATCH] Public simgrid::xbt:signal class It is either an alias for boost::signals2::signal or a wrapper around sigc::signal. We are going to need it in order to exposer the signals to users and move them in simgrid::Host. --- include/simgrid_config.h.in | 2 ++ include/xbt/signal.hpp | 52 ++++++++++++++++++++++++++++++++++ src/simix/libsmx.cpp | 37 ++++++++++++------------ src/surf/cpu_interface.cpp | 4 +-- src/surf/cpu_interface.hpp | 2 +- src/surf/host_interface.cpp | 6 ++-- src/surf/host_interface.hpp | 6 ++-- src/surf/network_interface.cpp | 10 +++---- src/surf/network_interface.hpp | 10 +++---- src/surf/storage_interface.cpp | 8 +++--- src/surf/storage_interface.hpp | 9 +++--- src/surf/surf_interface.cpp | 2 +- src/surf/surf_interface.hpp | 44 +++------------------------- src/surf/surf_routing.cpp | 4 +-- src/surf/surf_routing.hpp | 5 ++-- src/surf/virtual_machine.cpp | 6 ++-- src/surf/virtual_machine.hpp | 6 ++-- tools/cmake/MakeLib.cmake | 1 + 18 files changed, 118 insertions(+), 96 deletions(-) create mode 100644 include/xbt/signal.hpp diff --git a/include/simgrid_config.h.in b/include/simgrid_config.h.in index ba2e9720af..1ee0a15454 100644 --- a/include/simgrid_config.h.in +++ b/include/simgrid_config.h.in @@ -90,4 +90,6 @@ /* If Model-Checking support was requested */ #cmakedefine HAVE_MC @HAVE_MC@ +#cmakedefine SIMGRID_HAVE_LIBSIG @SIMGRID_HAVE_LIBSIG@ + #endif /* SIMGRID_PUBLIC_CONFIG_H */ diff --git a/include/xbt/signal.hpp b/include/xbt/signal.hpp new file mode 100644 index 0000000000..2068546289 --- /dev/null +++ b/include/xbt/signal.hpp @@ -0,0 +1,52 @@ +/* Copyright (c) 2014-2015. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef SIMGRID_XBT_SIGNAL_HPP +#define SIMGRID_XBT_SIGNAL_HPP + +#ifdef SIMGRID_HAVE_LIBSIG +#include + +namespace simgrid { +namespace xbt { + // Wraps sigc++ signals with the interface of boost::signals2: + template class signal; + template + class signal { + private: + sigc::signal sig_; + public: + template XBT_ALWAYS_INLINE + void connect(U&& slot) + { + sig_.connect(std::forward(slot)); + } + template XBT_ALWAYS_INLINE + void connect(Res(*slot)(Args...)) + { + sig_.connect(sigc::ptr_fun(slot)); + } + template XBT_ALWAYS_INLINE + R operator()(Args&&... args) const + { + return sig_.emit(std::forward(args)...); + } + }; +} +} + +#else + +#include +namespace simgrid { +namespace xbt { + template + using signal = ::boost::signals2::signal; +} +} + +#endif + +#endif diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 7d8618afa3..32194f9ef8 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -11,13 +11,14 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include /* std::isfinite() */ + #include #include "src/mc/mc_replay.h" #include "smx_private.h" #include "src/mc/mc_forward.h" #include "xbt/ex.h" -#include /* isfinite() */ #include "mc/mc.h" #include "src/simix/smx_host_private.h" #include "src/simix/smx_private.hpp" @@ -122,8 +123,8 @@ smx_synchro_t simcall_process_execute(const char *name, double priority, double bound, unsigned long affinity_mask) { /* checking for infinite values */ - xbt_assert(isfinite(flops_amount), "flops_amount is not finite!"); - xbt_assert(isfinite(priority), "priority is not finite!"); + xbt_assert(std::isfinite(flops_amount), "flops_amount is not finite!"); + xbt_assert(std::isfinite(priority), "priority is not finite!"); return simcall_BODY_process_execute(name, flops_amount, priority, bound, affinity_mask); } @@ -154,15 +155,15 @@ smx_synchro_t simcall_process_parallel_execute(const char *name, int i,j; /* checking for infinite values */ for (i = 0 ; i < host_nb ; ++i) { - xbt_assert(isfinite(flops_amount[i]), "flops_amount[%d] is not finite!", i); + xbt_assert(std::isfinite(flops_amount[i]), "flops_amount[%d] is not finite!", i); for (j = 0 ; j < host_nb ; ++j) { - xbt_assert(isfinite(bytes_amount[i + host_nb * j]), + xbt_assert(std::isfinite(bytes_amount[i + host_nb * j]), "bytes_amount[%d+%d*%d] is not finite!", i, host_nb, j); } } - xbt_assert(isfinite(amount), "amount is not finite!"); - xbt_assert(isfinite(rate), "rate is not finite!"); + xbt_assert(std::isfinite(amount), "amount is not finite!"); + xbt_assert(std::isfinite(rate), "rate is not finite!"); return simcall_BODY_process_parallel_execute(name, host_nb, host_list, flops_amount, @@ -230,7 +231,7 @@ e_smx_state_t simcall_process_execution_get_state(smx_synchro_t execution) void simcall_process_execution_set_priority(smx_synchro_t execution, double priority) { /* checking for infinite values */ - xbt_assert(isfinite(priority), "priority is not finite!"); + xbt_assert(std::isfinite(priority), "priority is not finite!"); simcall_BODY_process_execution_set_priority(execution, priority); } @@ -720,7 +721,7 @@ XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process) e_smx_state_t simcall_process_sleep(double duration) { /* checking for infinite values */ - xbt_assert(isfinite(duration), "duration is not finite!"); + xbt_assert(std::isfinite(duration), "duration is not finite!"); return (e_smx_state_t) simcall_BODY_process_sleep(duration); } @@ -804,9 +805,9 @@ void simcall_comm_send(smx_process_t sender, smx_rdv_t rdv, double task_size, do double timeout) { /* checking for infinite values */ - xbt_assert(isfinite(task_size), "task_size is not finite!"); - xbt_assert(isfinite(rate), "rate is not finite!"); - xbt_assert(isfinite(timeout), "timeout is not finite!"); + xbt_assert(std::isfinite(task_size), "task_size is not finite!"); + xbt_assert(std::isfinite(rate), "rate is not finite!"); + xbt_assert(std::isfinite(timeout), "timeout is not finite!"); xbt_assert(rdv, "No rendez-vous point defined for send"); @@ -836,8 +837,8 @@ smx_synchro_t simcall_comm_isend(smx_process_t sender, smx_rdv_t rdv, double tas int detached) { /* checking for infinite values */ - xbt_assert(isfinite(task_size), "task_size is not finite!"); - xbt_assert(isfinite(rate), "rate is not finite!"); + xbt_assert(std::isfinite(task_size), "task_size is not finite!"); + xbt_assert(std::isfinite(rate), "rate is not finite!"); xbt_assert(rdv, "No rendez-vous point defined for isend"); @@ -854,7 +855,7 @@ void simcall_comm_recv(smx_process_t receiver, smx_rdv_t rdv, void *dst_buff, si void (*copy_data_fun)(smx_synchro_t, void*, size_t), void *data, double timeout, double rate) { - xbt_assert(isfinite(timeout), "timeout is not finite!"); + xbt_assert(std::isfinite(timeout), "timeout is not finite!"); xbt_assert(rdv, "No rendez-vous point defined for recv"); if (MC_is_active() || MC_record_replay_is_active()) { @@ -926,7 +927,7 @@ int simcall_comm_testany(xbt_dynar_t comms) */ void simcall_comm_wait(smx_synchro_t comm, double timeout) { - xbt_assert(isfinite(timeout), "timeout is not finite!"); + xbt_assert(std::isfinite(timeout), "timeout is not finite!"); simcall_BODY_comm_wait(comm, timeout); } @@ -1108,7 +1109,7 @@ void simcall_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double timeout) { - xbt_assert(isfinite(timeout), "timeout is not finite!"); + xbt_assert(std::isfinite(timeout), "timeout is not finite!"); simcall_BODY_cond_wait_timeout(cond, mutex, timeout); } @@ -1172,7 +1173,7 @@ void simcall_sem_acquire(smx_sem_t sem) */ void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout) { - xbt_assert(isfinite(timeout), "timeout is not finite!"); + xbt_assert(std::isfinite(timeout), "timeout is not finite!"); simcall_BODY_sem_acquire_timeout(sem, timeout); } diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index e50e704156..d8fd429171 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -31,7 +31,7 @@ Cpu *getActionCpu(CpuAction *action) { action->getVariable(), 0))); } -simgrid::surf::signal cpuActionStateChangedCallbacks; +simgrid::xbt::signal cpuActionStateChangedCallbacks; void cpu_add_traces(){ surf_cpu_model_pm->addTraces(); @@ -349,7 +349,7 @@ void CpuAction::setAffinity(Cpu *cpu, unsigned long mask) XBT_OUT(); } -simgrid::surf::signal CpuAction::onStateChange; +simgrid::xbt::signal CpuAction::onStateChange; void CpuAction::setState(e_surf_action_state_t state){ e_surf_action_state_t old = getState(); diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 861ab24b0f..38c6c70929 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -178,7 +178,7 @@ public: /** @brief Callbacks handler which emit the callbacks after CpuAction State changed * * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t old, e_surf_action_state_t current)` */ - static simgrid::surf::signal onStateChange; + static simgrid::xbt::signal onStateChange; /** @brief CpuAction constructor */ CpuAction(simgrid::surf::Model *model, double cost, bool failed) diff --git a/src/surf/host_interface.cpp b/src/surf/host_interface.cpp index 9fa80220fa..ae57db2e00 100644 --- a/src/surf/host_interface.cpp +++ b/src/surf/host_interface.cpp @@ -82,9 +82,9 @@ void HostModel::adjustWeightOfDummyCpuActions() /************ * Resource * ************/ -simgrid::surf::signal Host::onCreation; -simgrid::surf::signal Host::onDestruction; -simgrid::surf::signal Host::onStateChange; +simgrid::xbt::signal Host::onCreation; +simgrid::xbt::signal Host::onDestruction; +simgrid::xbt::signal Host::onStateChange; void Host::classInit() { diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index 16bdb110d9..02f977ff58 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -79,9 +79,9 @@ public: static simgrid::xbt::Extension EXTENSION_ID; /* callbacks */ - static simgrid::surf::signal onCreation; /** Called on each newly created object */ - static simgrid::surf::signal onDestruction; /** Called just before destructing an object */ - static simgrid::surf::signal onStateChange; /** Called when the machine is turned on or off */ + static simgrid::xbt::signal onCreation; /** Called on each newly created object */ + static simgrid::xbt::signal onDestruction; /** Called just before destructing an object */ + static simgrid::xbt::signal onStateChange; /** Called when the machine is turned on or off */ public: static void classInit(); // must be called before the first use of that class diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 236a8ac44d..c7a81c5848 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -95,12 +95,12 @@ void Link::linksExit() { * Callbacks * *************/ -simgrid::surf::signal Link::onCreation; -simgrid::surf::signal Link::onDestruction; -simgrid::surf::signal Link::onStateChange; // signature: wasOn, currentlyOn +simgrid::xbt::signal Link::onCreation; +simgrid::xbt::signal Link::onDestruction; +simgrid::xbt::signal Link::onStateChange; // signature: wasOn, currentlyOn -simgrid::surf::signal networkActionStateChangedCallbacks; -simgrid::surf::signal networkCommunicateCallbacks; +simgrid::xbt::signal networkActionStateChangedCallbacks; +simgrid::xbt::signal networkCommunicateCallbacks; } } diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index cf080ee9d0..a229068980 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -36,11 +36,11 @@ class NetworkAction; /** @brief Callback signal fired when the state of a NetworkAction changes * Signature: `void(NetworkAction *action, e_surf_action_state_t old, e_surf_action_state_t current)` */ -XBT_PUBLIC_DATA(simgrid::surf::signal) networkActionStateChangedCallbacks; +XBT_PUBLIC_DATA(simgrid::xbt::signal) networkActionStateChangedCallbacks; /** @brief Callback signal fired when a NetworkAction is created (when a communication starts) * Signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst, double size, double rate)` */ -XBT_PUBLIC_DATA(simgrid::surf::signal) networkCommunicateCallbacks; +XBT_PUBLIC_DATA(simgrid::xbt::signal) networkCommunicateCallbacks; } } @@ -207,15 +207,15 @@ private: public: /** @brief Callback signal fired when a new Link is created. * Signature: void(Link*) */ - static simgrid::surf::signal onCreation; + static simgrid::xbt::signal onCreation; /** @brief Callback signal fired when a Link is destroyed. * Signature: void(Link*) */ - static simgrid::surf::signal onDestruction; + static simgrid::xbt::signal onDestruction; /** @brief Callback signal fired when the state of a Link changes * Signature: `void(LinkAction *action, int previouslyOn, int currentlyOn)` */ - static simgrid::surf::signal onStateChange; + static simgrid::xbt::signal onStateChange; /** @brief Get the bandwidth in bytes per second of current Link */ diff --git a/src/surf/storage_interface.cpp b/src/surf/storage_interface.cpp index e9a35b7741..d0d1cb98ee 100644 --- a/src/surf/storage_interface.cpp +++ b/src/surf/storage_interface.cpp @@ -28,10 +28,10 @@ namespace surf { * Callbacks * *************/ -simgrid::surf::signal storageCreatedCallbacks; -simgrid::surf::signal storageDestructedCallbacks; -simgrid::surf::signal storageStateChangedCallbacks; // signature: wasOn, isOn -simgrid::surf::signal storageActionStateChangedCallbacks; +simgrid::xbt::signal storageCreatedCallbacks; +simgrid::xbt::signal storageDestructedCallbacks; +simgrid::xbt::signal storageStateChangedCallbacks; // signature: wasOn, isOn +simgrid::xbt::signal storageActionStateChangedCallbacks; /********* * Model * diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index 125962e092..545cb1b571 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -5,6 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include +#include #include "surf_interface.hpp" #include "src/surf/PropertyHolder.hpp" @@ -33,25 +34,25 @@ class StorageAction; * @brief Callbacks handler which emit the callbacks after Storage creation * * @details Callback functions have the following signature: `void(Storage*)` */ -XBT_PUBLIC_DATA(simgrid::surf::signal) storageCreatedCallbacks; +XBT_PUBLIC_DATA(simgrid::xbt::signal) storageCreatedCallbacks; /** @ingroup SURF_callbacks * @brief Callbacks handler which emit the callbacks after Storage destruction * * @details Callback functions have the following signature: `void(StoragePtr)` */ -XBT_PUBLIC_DATA(simgrid::surf::signal) storageDestructedCallbacks; +XBT_PUBLIC_DATA(simgrid::xbt::signal) storageDestructedCallbacks; /** @ingroup SURF_callbacks * @brief Callbacks handler which emit the callbacks after Storage State changed * * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int currentlyOn)` */ -XBT_PUBLIC_DATA(simgrid::surf::signal) storageStateChangedCallbacks; +XBT_PUBLIC_DATA(simgrid::xbt::signal) storageStateChangedCallbacks; /** @ingroup SURF_callbacks * @brief Callbacks handler which emit the callbacks after StorageAction State changed * * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_action_state_t old, e_surf_action_state_t current)` */ -XBT_PUBLIC_DATA(simgrid::surf::signal) storageActionStateChangedCallbacks; +XBT_PUBLIC_DATA(simgrid::xbt::signal) storageActionStateChangedCallbacks; /********* * Model * diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index b8d0eafb36..6a004ce853 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -38,7 +38,7 @@ xbt_dict_t watched_hosts_lib; namespace simgrid { namespace surf { -simgrid::surf::signal surfExitCallbacks; +simgrid::xbt::signal surfExitCallbacks; } } diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index ea0d647085..f450f3bd2e 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -14,6 +14,9 @@ #include #include + +#include + #include "surf/trace_mgr.h" #include "xbt/lib.h" #include "surf/surf_routing.h" @@ -22,45 +25,6 @@ #include "src/surf/surf_private.h" #include "src/internal_config.h" -#ifdef LIBSIGC -#include -namespace simgrid { -namespace surf { - // Wraps sigc++ signals with the interface of boost::signals2: - template class signal; - template - class signal { - private: - sigc::signal sig_; - public: - template XBT_ALWAYS_INLINE - void connect(U&& slot) - { - sig_.connect(std::forward(slot)); - } - template XBT_ALWAYS_INLINE - void connect(Res(*slot)(Args...)) - { - sig_.connect(sigc::ptr_fun(slot)); - } - template XBT_ALWAYS_INLINE - R operator()(Args&&... args) const - { - return sig_.emit(std::forward(args)...); - } - }; -} -} -#else -#include -namespace simgrid { -namespace surf { - template - using signal = ::boost::signals2::signal; -} -} -#endif - extern XBT_PRIVATE tmgr_history_t history; #define NO_MAX_DURATION -1.0 @@ -86,7 +50,7 @@ extern XBT_PRIVATE double sg_sender_gap; namespace simgrid { namespace surf { -extern XBT_PRIVATE simgrid::surf::signal surfExitCallbacks; +extern XBT_PRIVATE simgrid::xbt::signal surfExitCallbacks; } } diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index b79cae75e1..af1ceee345 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -23,8 +23,8 @@ namespace simgrid { namespace surf { -simgrid::surf::signal routingEdgeCreatedCallbacks; -simgrid::surf::signal asCreatedCallbacks; +simgrid::xbt::signal routingEdgeCreatedCallbacks; +simgrid::xbt::signal asCreatedCallbacks; } } diff --git a/src/surf/surf_routing.hpp b/src/surf/surf_routing.hpp index 721888dfbf..c5d0d5db2e 100644 --- a/src/surf/surf_routing.hpp +++ b/src/surf/surf_routing.hpp @@ -8,6 +8,7 @@ #define NETWORK_ROUTING_HPP_ #include +#include #include "surf_interface.hpp" #include @@ -149,8 +150,8 @@ public: * Callbacks * *************/ -XBT_PUBLIC_DATA(simgrid::surf::signal) routingEdgeCreatedCallbacks; -XBT_PUBLIC_DATA(simgrid::surf::signal) asCreatedCallbacks; +XBT_PUBLIC_DATA(simgrid::xbt::signal) routingEdgeCreatedCallbacks; +XBT_PUBLIC_DATA(simgrid::xbt::signal) asCreatedCallbacks; } } diff --git a/src/surf/virtual_machine.cpp b/src/surf/virtual_machine.cpp index 87755cebab..4c25e536a3 100644 --- a/src/surf/virtual_machine.cpp +++ b/src/surf/virtual_machine.cpp @@ -19,9 +19,9 @@ namespace surf { * Callbacks * *************/ -simgrid::surf::signal VMCreatedCallbacks; -simgrid::surf::signal VMDestructedCallbacks; -simgrid::surf::signal VMStateChangedCallbacks; +simgrid::xbt::signal VMCreatedCallbacks; +simgrid::xbt::signal VMDestructedCallbacks; +simgrid::xbt::signal VMStateChangedCallbacks; /********* * Model * diff --git a/src/surf/virtual_machine.hpp b/src/surf/virtual_machine.hpp index c28b44dd34..99f1e39675 100644 --- a/src/surf/virtual_machine.hpp +++ b/src/surf/virtual_machine.hpp @@ -31,17 +31,17 @@ class XBT_PRIVATE VirtualMachine; /** @ingroup SURF_callbacks * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)` */ -extern XBT_PRIVATE simgrid::surf::signal VMCreatedCallbacks; +extern XBT_PRIVATE simgrid::xbt::signal VMCreatedCallbacks; /** @ingroup SURF_callbacks * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)` */ -extern XBT_PRIVATE simgrid::surf::signal VMDestructedCallbacks; +extern XBT_PRIVATE simgrid::xbt::signal VMDestructedCallbacks; /** @ingroup SURF_callbacks * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)` */ -extern XBT_PRIVATE simgrid::surf::signal VMStateChangedCallbacks; +extern XBT_PRIVATE simgrid::xbt::signal VMStateChangedCallbacks; /************ * Resource * diff --git a/tools/cmake/MakeLib.cmake b/tools/cmake/MakeLib.cmake index 2dbc52eb05..b21a0ce23c 100644 --- a/tools/cmake/MakeLib.cmake +++ b/tools/cmake/MakeLib.cmake @@ -73,6 +73,7 @@ endif() if(HAVE_LIBSIGC++) SET(SIMGRID_DEP "${SIMGRID_DEP} -lsigc-2.0") add_definitions(-DLIBSIGC) + set(SIMGRID_HAVE_LIBSIG 1) endif() if(HAVE_MC) -- 2.20.1