Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e0158cf8e981cc248cd31f3e067cb8e8704b3da4
[simgrid.git] / src / kernel / activity / SynchroIo.cpp
1 /* Copyright (c) 2007-2018. 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 "src/kernel/activity/SynchroIo.hpp"
7 #include "simgrid/kernel/resource/Action.hpp"
8 #include "src/simix/smx_private.hpp"
9 #include "src/surf/surf_interface.hpp"
10
11 void simgrid::kernel::activity::IoImpl::suspend()
12 {
13   if (surf_io)
14     surf_io->suspend();
15 }
16
17 void simgrid::kernel::activity::IoImpl::resume()
18 {
19   if (surf_io)
20     surf_io->resume();
21 }
22
23 void simgrid::kernel::activity::IoImpl::post()
24 {
25   for (smx_simcall_t const& simcall : simcalls) {
26     switch (simcall->call) {
27       case SIMCALL_STORAGE_WRITE:
28         simcall_storage_write__set__result(simcall, surf_io->get_cost());
29         break;
30       case SIMCALL_STORAGE_READ:
31         simcall_storage_read__set__result(simcall, surf_io->get_cost());
32         break;
33       default:
34         break;
35     }
36   }
37
38   switch (surf_io->get_state()) {
39     case simgrid::kernel::resource::Action::State::failed:
40       state = SIMIX_FAILED;
41       break;
42     case simgrid::kernel::resource::Action::State::done:
43       state = SIMIX_DONE;
44       break;
45     default:
46       THROW_IMPOSSIBLE;
47       break;
48   }
49
50   SIMIX_io_finish(this);
51 }