Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
align namespaces on directories for kernel::activity
[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/surf/surf_interface.hpp"
8 #include "src/simix/popping_private.h"
9 #include "src/simix/smx_private.h"
10
11 void simgrid::kernel::activity::Io::suspend()
12 {
13   if (surf_io)
14     surf_io->suspend();
15 }
16
17 void simgrid::kernel::activity::Io::resume()
18 {
19   if (surf_io)
20     surf_io->resume();
21 }
22
23 void simgrid::kernel::activity::Io::post()
24 {
25   for (smx_simcall_t simcall : simcalls) {
26     switch (simcall->call) {
27     case SIMCALL_FILE_OPEN: {
28       smx_file_t tmp = xbt_new(s_smx_file_t,1);
29       tmp->surf_file = surf_storage_action_get_file(surf_io);
30       simcall_file_open__set__result(simcall, tmp);
31       break;
32     }
33     case SIMCALL_FILE_CLOSE:
34       xbt_free(simcall_file_close__get__fd(simcall));
35       simcall_file_close__set__result(simcall, 0);
36       break;
37     case SIMCALL_FILE_WRITE:
38       simcall_file_write__set__result(simcall, surf_io->getCost());
39       break;
40
41     case SIMCALL_FILE_READ:
42       simcall_file_read__set__result(simcall, surf_io->getCost());
43       break;
44
45     default:
46       break;
47     }
48   }
49
50   switch (surf_io->getState()) {
51
52     case simgrid::surf::Action::State::failed:
53       state = SIMIX_FAILED;
54       break;
55
56     case simgrid::surf::Action::State::done:
57       state = SIMIX_DONE;
58       break;
59
60     default:
61       THROW_IMPOSSIBLE;
62       break;
63   }
64
65   SIMIX_io_finish(this);
66 }