Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d09bd1ddeba1d1ef9ff8e6c0365c3e170c0c4e42
[simgrid.git] / src / kernel / activity / SynchroIo.cpp
1 /* Copyright (c) 2007-2016. 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 "src/simix/smx_private.h"
8 #include "src/surf/FileImpl.hpp"
9 #include "src/surf/StorageImpl.hpp"
10 #include "src/surf/surf_interface.hpp"
11
12 void simgrid::kernel::activity::IoImpl::suspend()
13 {
14   if (surf_io)
15     surf_io->suspend();
16 }
17
18 void simgrid::kernel::activity::IoImpl::resume()
19 {
20   if (surf_io)
21     surf_io->resume();
22 }
23
24 void simgrid::kernel::activity::IoImpl::post()
25 {
26   for (smx_simcall_t simcall : simcalls) {
27     switch (simcall->call) {
28     case SIMCALL_FILE_OPEN: {
29       surf_file_t tmp = static_cast<simgrid::surf::StorageAction*>(surf_io)->file_;
30       simcall_file_open__set__result(simcall, tmp);
31       break;
32     }
33     case SIMCALL_FILE_WRITE:
34       simcall_file_write__set__result(simcall, surf_io->getCost());
35       break;
36
37     case SIMCALL_FILE_READ:
38       simcall_file_read__set__result(simcall, surf_io->getCost());
39       break;
40
41     default:
42       break;
43     }
44   }
45
46   switch (surf_io->getState()) {
47
48     case simgrid::surf::Action::State::failed:
49       state = SIMIX_FAILED;
50       break;
51
52     case simgrid::surf::Action::State::done:
53       state = SIMIX_DONE;
54       break;
55
56     default:
57       THROW_IMPOSSIBLE;
58       break;
59   }
60
61   SIMIX_io_finish(this);
62 }