Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
no need for a lib to store the netcards. A dict is easier
[simgrid.git] / src / mc / mc_xbt.cpp
1 /* Copyright (c) 2014-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <cstddef>
8
9 #include "src/mc/RemotePtr.hpp"
10 #include "src/mc/AddressSpace.hpp"
11 #include "src/mc/mc_xbt.hpp"
12
13 #include <xbt/dynar.h>
14 #include <xbt/sysdep.h>
15
16 namespace simgrid {
17 namespace mc {
18
19 void read_element(AddressSpace const& as,
20   void* local, RemotePtr<s_xbt_dynar_t> addr, std::size_t i, std::size_t len)
21 {
22   s_xbt_dynar_t d;
23   as.read_bytes(&d, sizeof(d), addr);
24   if (i >= d.used)
25     xbt_die("Out of bound index %zi/%lu", i, d.used);
26   if (len != d.elmsize)
27     xbt_die("Bad size in simgrid::mc::read_element");
28   as.read_bytes(local, len, remote(xbt_dynar_get_ptr(&d, i)));
29 }
30
31 std::size_t read_length(AddressSpace const& as, RemotePtr<s_xbt_dynar_t> addr)
32 {
33   if (!addr)
34     return 0;
35   unsigned long res;
36   as.read_bytes(&res, sizeof(res),
37     remote(&((xbt_dynar_t)addr.address())->used));
38   return res;
39 }
40
41 }
42 }