namespace s4u {
class XBT_PUBLIC Io : public Activity {
- explicit Io(sg_size_t size) : Activity(), size_(size) {}
+public:
+ enum class OpType { READ, WRITE };
+
+private:
+ explicit Io(sg_size_t size, OpType type) : Activity(), size_(size), type_(type) {}
public:
friend XBT_PUBLIC void intrusive_ptr_release(simgrid::s4u::Io* i);
friend XBT_PUBLIC void intrusive_ptr_add_ref(simgrid::s4u::Io* i);
friend Storage; // Factory of IOs
- enum class OpType { READ, WRITE };
~Io() = default;
Activity* start() override;
double get_remaining() override;
sg_size_t get_performed_ioops();
- IoPtr set_io_type(OpType type);
private:
sg_size_t size_ = 0;
#define INCLUDE_SIMGRID_S4U_STORAGE_HPP_
#include <simgrid/forward.h>
+#include <simgrid/s4u/Io.hpp>
#include <xbt/Extendable.hpp>
#include <xbt/base.h>
#include <xbt/signal.hpp>
void set_data(void* data) { userdata_ = data; }
void* get_data() { return userdata_; }
- IoPtr io_init(sg_size_t size);
+ IoPtr io_init(sg_size_t size, s4u::Io::OpType type);
sg_size_t read(sg_size_t size);
sg_size_t write(sg_size_t size);
#include "src/kernel/activity/IoImpl.hpp"
#include "src/simix/smx_io_private.hpp"
#include "xbt/log.h"
+#include <string>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous IOs");
Activity* Io::start()
{
- set_remaining(size_);
- pimpl_ = simix::simcall([this] { return SIMIX_io_start(name_, size_, storage_, type_); });
+ Activity::set_remaining(size_);
+ pimpl_ = simix::simcall([this] {
+ return boost::static_pointer_cast<kernel::activity::IoImpl>(SIMIX_io_start(name_, size_, storage_, type_));
+ });
state_ = State::STARTED;
return this;
}
[this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
}
-IoPtr Io::set_io_type(OpType type)
-{
- xbt_assert(state_ == State::INITED, "Cannot change the name of an exec after its start");
- type_ = type;
- return this;
-}
-
void intrusive_ptr_release(simgrid::s4u::Io* i)
{
if (i->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
simgrid::simix::simcall([this, key, value] { this->pimpl_->set_property(key, value); });
}
-IoPtr Storage::io_init(sg_size_t size)
+IoPtr Storage::io_init(sg_size_t size, Io::OpType type)
{
- IoPtr res = IoPtr(new Io(size));
+ IoPtr res = IoPtr(new Io(size, type));
res->storage_ = this;
return res;
}
sg_size_t Storage::read(sg_size_t size)
{
- IoPtr i = io_init(size);
- i->set_io_type(Io::OpType::READ);
+ IoPtr i = io_init(size, Io::OpType::READ);
i->start()->wait();
return i->get_performed_ioops();
}
sg_size_t Storage::write(sg_size_t size)
{
- IoPtr i = io_init(size);
- i->set_io_type(Io::OpType::WRITE);
+ IoPtr i = io_init(size, Io::OpType::WRITE);
i->start()->wait();
return i->get_performed_ioops();
}