1 /* Copyright (c) 2017. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_S4U_EXEC_HPP
7 #define SIMGRID_S4U_EXEC_HPP
9 #include "src/kernel/activity/ExecImpl.hpp"
10 #include <simgrid/forward.h>
11 #include <simgrid/s4u/forward.hpp>
16 XBT_PUBLIC_CLASS Exec : public Activity
18 Exec() : Activity() {}
20 friend void intrusive_ptr_release(simgrid::s4u::Exec * e)
22 if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
23 std::atomic_thread_fence(std::memory_order_acquire);
28 friend void intrusive_ptr_add_ref(simgrid::s4u::Exec * e) { e->refcount_.fetch_add(1, std::memory_order_relaxed); }
30 friend Actor; // Factory of Exec
36 pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0.);
39 void wait() override { this->wait(-1); }
40 void wait(double timeout) override { simcall_execution_wait(pimpl_); }
44 return simgrid::simix::kernelImmediate(
45 [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->remains(); });
49 smx_actor_t runner_ = nullptr;
50 double flops_amount_ = 0.0;
51 double priority_ = 1.0;
54 std::atomic_int_fast32_t refcount_{0};
57 }; // Namespace simgrid::s4u
59 #endif /* SIMGRID_S4U_EXEC_HPP */