Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Slightly reorganize log categories; remove unused ones.
[simgrid.git] / src / s4u / s4u_Io.cpp
1 /* Copyright (c) 2018-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/s4u/Disk.hpp"
7 #include "simgrid/s4u/Io.hpp"
8 #include "simgrid/s4u/Storage.hpp"
9 #include "src/kernel/activity/IoImpl.hpp"
10 #include "xbt/log.h"
11
12 namespace simgrid {
13 namespace s4u {
14
15 Io::Io(sg_disk_t disk, sg_size_t size, OpType type) : disk_(disk), size_(size), type_(type)
16 {
17   Activity::set_remaining(size_);
18   pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl());
19 }
20
21 Io::Io(sg_storage_t storage, sg_size_t size, OpType type) : storage_(storage), size_(size), type_(type)
22 {
23   Activity::set_remaining(size_);
24   pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl());
25 }
26
27 Io* Io::start()
28 {
29   kernel::actor::simcall([this] {
30     if (storage_) {
31       (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
32           .set_name(get_name())
33           .set_storage(storage_->get_impl())
34           .set_size(size_)
35           .set_type(type_)
36           .start();
37     } else {
38       (*boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_))
39           .set_name(get_name())
40           .set_disk(disk_->get_impl())
41           .set_size(size_)
42           .set_type(type_)
43           .start();
44     }
45   });
46   state_ = State::STARTED;
47   return this;
48 }
49
50 Io* Io::cancel()
51 {
52   simgrid::kernel::actor::simcall([this] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->cancel(); });
53   state_ = State::CANCELED;
54   return this;
55 }
56
57 Io* Io::wait()
58 {
59   simcall_io_wait(pimpl_);
60   state_ = State::FINISHED;
61   return this;
62 }
63
64 Io* Io::wait_for(double)
65 {
66   THROW_UNIMPLEMENTED;
67 }
68
69 bool Io::test()
70 {
71   xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED);
72
73   if (state_ == State::FINISHED)
74     return true;
75
76   if (state_ == State::INITED)
77     this->start();
78
79   THROW_UNIMPLEMENTED;
80
81   // return false
82 }
83
84 /** @brief Returns the amount of flops that remain to be done */
85 double Io::get_remaining()
86 {
87   return kernel::actor::simcall(
88       [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
89 }
90
91 sg_size_t Io::get_performed_ioops()
92 {
93   return kernel::actor::simcall(
94       [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
95 }
96
97 } // namespace s4u
98 } // namespace simgrid