Logo AND Algorithmique Numérique Distribuée

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