include include/simgrid/jedule/jedule_events.hpp
include include/simgrid/jedule/jedule_platform.hpp
include include/simgrid/jedule/jedule_sd_binding.h
+include include/simgrid/kernel/Timer.hpp
include include/simgrid/kernel/future.hpp
include include/simgrid/kernel/resource/Action.hpp
include include/simgrid/kernel/resource/Model.hpp
include src/kernel/routing/TorusZone_test.cpp
include src/kernel/routing/VivaldiZone.cpp
include src/kernel/routing/WifiZone.cpp
+include src/kernel/timer/Timer.cpp
include src/mc/AddressSpace.hpp
include src/mc/ModelChecker.cpp
include src/mc/ModelChecker.hpp
class DiskImpl;
class DiskModel;
}
+namespace timer {
+class Timer;
+}
namespace routing {
class NetPoint;
class NetZoneImpl;
} // namespace kernel
namespace simix {
class Host;
- class Timer;
}
namespace surf {
class HostImpl;
using s4u_NetZone = simgrid::s4u::NetZone;
using s4u_VM = simgrid::s4u::VirtualMachine;
-using smx_timer_t = simgrid::simix::Timer*;
+using smx_timer_t = simgrid::kernel::timer::Timer*;
using smx_actor_t = simgrid::kernel::actor::ActorImpl*;
using smx_activity_t = simgrid::kernel::activity::ActivityImpl*;
using smx_cond_t = simgrid::kernel::activity::ConditionVariableImpl*;
--- /dev/null
+/* Copyright (c) 2021. 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 SRC_KERNEL_TIMER_TIMER_HPP_
+#define SRC_KERNEL_TIMER_TIMER_HPP_
+
+#include <simgrid/forward.h>
+#include <xbt/functional.hpp>
+#include <xbt/utility.hpp>
+
+#include <boost/heap/fibonacci_heap.hpp>
+
+namespace simgrid {
+namespace kernel {
+namespace timer {
+
+inline auto& kernel_timers() // avoid static initialization order fiasco
+{
+ using TimerQelt = std::pair<double, Timer*>;
+ static boost::heap::fibonacci_heap<TimerQelt, boost::heap::compare<xbt::HeapComparator<TimerQelt>>> value;
+ return value;
+}
+
+/** @brief Timer datatype */
+class Timer {
+public:
+ const double date;
+ std::remove_reference_t<decltype(kernel_timers())>::handle_type handle_;
+
+ Timer(double date, xbt::Task<void()>&& callback) : date(date), callback(std::move(callback)) {}
+
+ xbt::Task<void()> callback;
+ void remove();
+
+ template <class F> static inline Timer* set(double date, F callback)
+ {
+ return set(date, xbt::Task<void()>(std::move(callback)));
+ }
+
+ static Timer* set(double date, xbt::Task<void()>&& callback);
+ static double next() { return kernel_timers().empty() ? -1.0 : kernel_timers().top().first; }
+};
+
+} // namespace timer
+} // namespace kernel
+} // namespace simgrid
+
+#endif /* SRC_KERNEL_TIMER_TIMER_HPP_ */
* auto promise = std::make_shared<simgrid::kernel::Promise<T>>();
* auto future = promise->get_future();
*
- * simgrid::simix::Timer::set(date, [promise] {
+ * simgrid::kernel::timer::Timer::set(date, [promise] {
* try {
* int value = compute_the_value();
* if (value < 0)
XBT_PUBLIC void SIMIX_run();
XBT_PUBLIC double SIMIX_get_clock();
-XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::set()") XBT_PUBLIC smx_timer_t
+XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::kernel::timer::Timer::set()") XBT_PUBLIC smx_timer_t
SIMIX_timer_set(double date, void (*function)(void*), void* arg);
-XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::remove()") XBT_PUBLIC
+XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::kernel::timer::Timer::remove()") XBT_PUBLIC
void SIMIX_timer_remove(smx_timer_t timer);
-XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::next()") XBT_PUBLIC double SIMIX_timer_next();
-XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::get_date()") XBT_PUBLIC
+XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::kernel::timer::Timer::next()") XBT_PUBLIC double SIMIX_timer_next();
+XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::kernel::timer::Timer::get_date()") XBT_PUBLIC
double SIMIX_timer_get_date(smx_timer_t timer);
XBT_ATTRIB_DEPRECATED_v329("Please use simix_global->display_all_actor_status()") XBT_PUBLIC
#define SIMGRID_SIMIX_HPP
#include <simgrid/simix.h>
-#include <xbt/functional.hpp>
#include <xbt/promise.hpp>
#include <xbt/signal.hpp>
-#include <xbt/utility.hpp>
-#include <boost/heap/fibonacci_heap.hpp>
#include <string>
#include <unordered_map>
XBT_PUBLIC void unblock(smx_actor_t process);
-inline auto& simix_timers() // avoid static initialization order fiasco
-{
- using TimerQelt = std::pair<double, Timer*>;
- static boost::heap::fibonacci_heap<TimerQelt, boost::heap::compare<xbt::HeapComparator<TimerQelt>>> value;
- return value;
-}
-
-/** @brief Timer datatype */
-class Timer {
-public:
- const double date;
- std::remove_reference_t<decltype(simix_timers())>::handle_type handle_;
-
- Timer(double date, simgrid::xbt::Task<void()>&& callback) : date(date), callback(std::move(callback)) {}
-
- simgrid::xbt::Task<void()> callback;
- void remove();
-
- template <class F> static inline Timer* set(double date, F callback)
- {
- return set(date, simgrid::xbt::Task<void()>(std::move(callback)));
- }
-
- static Timer* set(double date, simgrid::xbt::Task<void()>&& callback);
- static double next() { return simix_timers().empty() ? -1.0 : simix_timers().top().first; }
-};
-
// In MC mode, the application sends these pointers to the MC
xbt_dynar_t simix_global_get_actors_addr();
xbt_dynar_t simix_global_get_dead_actors_addr();
if (timeout < 0.0) {
issuer->simcall_.timeout_cb_ = nullptr;
} else {
- issuer->simcall_.timeout_cb_ = simix::Timer::set(SIMIX_get_clock() + timeout, [issuer, comms]() {
+ issuer->simcall_.timeout_cb_ = timer::Timer::set(SIMIX_get_clock() + timeout, [issuer, comms]() {
// FIXME: Vector `comms' is copied here. Use a reference once its lifetime is extended (i.e. when the simcall is
// modernized).
issuer->simcall_.timeout_cb_ = nullptr;
if (timeout < 0.0) {
issuer->simcall_.timeout_cb_ = nullptr;
} else {
- issuer->simcall_.timeout_cb_ = simix::Timer::set(SIMIX_get_clock() + timeout, [issuer, &execs]() {
+ issuer->simcall_.timeout_cb_ = timer::Timer::set(SIMIX_get_clock() + timeout, [issuer, &execs]() {
issuer->simcall_.timeout_cb_ = nullptr;
for (auto* exec : execs)
exec->unregister_simcall(&issuer->simcall_);
if (timeout < 0.0) {
issuer->simcall_.timeout_cb_ = nullptr;
} else {
- issuer->simcall_.timeout_cb_ = simix::Timer::set(SIMIX_get_clock() + timeout, [issuer, &ios]() {
+ issuer->simcall_.timeout_cb_ = timer::Timer::set(SIMIX_get_clock() + timeout, [issuer, &ios]() {
issuer->simcall_.timeout_cb_ = nullptr;
for (auto* io : ios)
io->unregister_simcall(&issuer->simcall_);
if (kill_time <= SIMIX_get_clock())
return;
XBT_DEBUG("Set kill time %f for actor %s@%s", kill_time, get_cname(), host_->get_cname());
- kill_timer_ = simix::Timer::set(kill_time, [this] {
+ kill_timer_ = timer::Timer::set(kill_time, [this] {
this->exit();
kill_timer_ = nullptr;
});
#ifndef SIMGRID_KERNEL_ACTOR_ACTORIMPL_HPP
#define SIMGRID_KERNEL_ACTOR_ACTORIMPL_HPP
+#include "simgrid/kernel/Timer.hpp"
#include "simgrid/s4u/Actor.hpp"
#include "src/simix/popping_private.hpp"
#include "xbt/PropertyHolder.hpp"
std::make_shared<std::vector<std::function<void(bool)>>>();
std::function<void()> code_;
- simix::Timer* kill_timer_ = nullptr;
+ timer::Timer* kill_timer_ = nullptr;
private:
/* Refcounting */
--- /dev/null
+/* Copyright (c) 2021. 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. */
+
+#include "simgrid/kernel/Timer.hpp"
+
+namespace simgrid {
+namespace kernel {
+namespace timer {
+
+Timer* Timer::set(double date, xbt::Task<void()>&& callback)
+{
+ auto* timer = new Timer(date, std::move(callback));
+ timer->handle_ = kernel_timers().emplace(std::make_pair(date, timer));
+ return timer;
+}
+
+/** @brief cancels a timer that was added earlier */
+void Timer::remove()
+{
+ kernel_timers().erase(handle_);
+ delete this;
+}
+
+} // namespace timer
+} // namespace kernel
+} // namespace simgrid
* @brief Represents a simcall to the kernel.
*/
struct s_smx_simcall {
- simgrid::simix::Simcall call_ = simgrid::simix::Simcall::NONE;
- smx_actor_t issuer_ = nullptr;
- smx_timer_t timeout_cb_ = nullptr; // Callback to timeouts
+ simgrid::simix::Simcall call_ = simgrid::simix::Simcall::NONE;
+ smx_actor_t issuer_ = nullptr;
+ simgrid::kernel::timer::Timer* timeout_cb_ = nullptr; // Callback to timeouts
simgrid::kernel::actor::SimcallObserver* observer_ = nullptr; // makes that simcall observable by the MC
unsigned int mc_max_consider_ =
0; // How many times this simcall should be used. If >1, this will be a fork in the state space.
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "mc/mc.h"
+#include "simgrid/kernel/Timer.hpp"
#include "simgrid/s4u/Engine.hpp"
#include "simgrid/s4u/Host.hpp"
#include "src/smpi/include/smpi_actor.hpp"
namespace simgrid {
namespace simix {
-Timer* Timer::set(double date, xbt::Task<void()>&& callback)
-{
- auto* timer = new Timer(date, std::move(callback));
- timer->handle_ = simix_timers().emplace(std::make_pair(date, timer));
- return timer;
-}
-
-/** @brief cancels a timer that was added earlier */
-void Timer::remove()
-{
- simix_timers().erase(handle_);
- delete this;
-}
-
/** Execute all the tasks that are queued, e.g. `.then()` callbacks of futures. */
bool Global::execute_tasks()
{
/* Exit the SIMIX network module */
SIMIX_mailbox_exit();
- while (not simgrid::simix::simix_timers().empty()) {
- delete simgrid::simix::simix_timers().top().second;
- simgrid::simix::simix_timers().pop();
+ while (not simgrid::kernel::timer::kernel_timers().empty()) {
+ delete simgrid::kernel::timer::kernel_timers().top().second;
+ simgrid::kernel::timer::kernel_timers().pop();
}
/* Free the remaining data structures */
simix_global->actors_to_run.clear();
static bool SIMIX_execute_timers()
{
bool result = false;
- while (not simgrid::simix::simix_timers().empty() &&
- SIMIX_get_clock() >= simgrid::simix::simix_timers().top().first) {
+ while (not simgrid::kernel::timer::kernel_timers().empty() &&
+ SIMIX_get_clock() >= simgrid::kernel::timer::kernel_timers().top().first) {
result = true;
// FIXME: make the timers being real callbacks (i.e. provide dispatchers that read and expand the args)
- smx_timer_t timer = simgrid::simix::simix_timers().top().second;
- simgrid::simix::simix_timers().pop();
+ simgrid::kernel::timer::Timer* timer = simgrid::kernel::timer::kernel_timers().top().second;
+ simgrid::kernel::timer::kernel_timers().pop();
timer->callback();
delete timer;
}
}
}
- time = simgrid::simix::Timer::next();
+ time = simgrid::kernel::timer::Timer::next();
if (time > -1.0 || not simix_global->process_list.empty()) {
XBT_DEBUG("Calling surf_solve");
time = surf_solve(time);
double SIMIX_timer_next() // XBT_ATTRIB_DEPRECATED_v329
{
- return simgrid::simix::Timer::next();
+ return simgrid::kernel::timer::Timer::next();
}
smx_timer_t SIMIX_timer_set(double date, void (*callback)(void*), void* arg) // XBT_ATTRIB_DEPRECATED_v329
{
- return simgrid::simix::Timer::set(date, std::bind(callback, arg));
+ return simgrid::kernel::timer::Timer::set(date, std::bind(callback, arg));
}
/** @brief cancels a timer that was added earlier */
auto_restart);
XBT_DEBUG("Process %s@%s will be started at time %f", arg->name.c_str(), arg->host->get_cname(), start_time);
- simgrid::simix::Timer::set(start_time, [arg, auto_restart]() {
+ simgrid::kernel::timer::Timer::set(start_time, [arg, auto_restart]() {
simgrid::kernel::actor::ActorImplPtr new_actor =
simgrid::kernel::actor::ActorImpl::create(arg->name.c_str(), arg->code, arg->data, arg->host, nullptr);
new_actor->set_properties(arg->properties);
#include <xbt/promise.hpp>
+#include <simgrid/kernel/Timer.hpp>
#include <simgrid/kernel/future.hpp>
#include <simgrid/s4u/Actor.hpp>
#include <simgrid/s4u/Engine.hpp>
{
auto promise = std::make_shared<simgrid::kernel::Promise<void>>();
auto future = promise->get_future();
- simgrid::simix::Timer::set(date, [promise] { promise->set_value(); });
+ simgrid::kernel::timer::Timer::set(date, [promise] { promise->set_value(); });
return future;
}
src/kernel/routing/VivaldiZone.cpp
src/kernel/routing/WifiZone.cpp
+ src/kernel/timer/Timer.cpp
+
src/kernel/EngineImpl.cpp
src/kernel/EngineImpl.hpp
include/simgrid/forward.h
include/simgrid/simix.h
include/simgrid/simix.hpp
+ include/simgrid/kernel/Timer.hpp
include/simgrid/kernel/future.hpp
include/simgrid/disk.h
include/simgrid/host.h