Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Abstract the process and a snapshot types with a address_space superclass
[simgrid.git] / src / mc / mc_address_space.h
1 /* Copyright (c) 2008-2014. 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 #ifndef MC_ADDRESS_SPACE_H
8 #define MC_ADDRESS_SPACE_H
9
10 #include <stdint.h>
11
12 #include "mc_forward.h"
13
14 // ***** Data types
15
16 typedef enum e_adress_space_read_flags {
17   MC_ADDRESS_SPACE_READ_FLAGS_NONE = 0,
18
19   /** Avoid a copy for when the data is available in the current process.
20    *
21    *  In this case, the return value of a MC_address_space_read might
22    *  be different from the provided buffer.
23    */
24   MC_ADDRESS_SPACE_READ_FLAGS_LAZY = 1
25 } e_adress_space_read_flags_t;
26
27 /** Process index used when no process is available
28  *
29  *  The expected behaviour is that if a process index is needed it will fail.
30  * */
31 #define MC_PROCESS_INDEX_MISSING -1
32
33 #define MC_PROCESS_INDEX_DISABLED -2
34
35 /** Process index when any process is suitable
36  *
37  * We could use a special negative value in the future.
38  */
39 #define MC_PROCESS_INDEX_ANY 0
40
41 // ***** Class definition
42
43 typedef struct s_mc_address_space s_mc_address_space_t, *mc_address_space_t;
44 typedef struct s_mc_address_space_class s_mc_address_space_class_t, *mc_address_space_class_t;
45
46 struct s_mc_address_space_class {
47   const void* (*read)(
48     mc_address_space_t address_space, e_adress_space_read_flags_t flags,
49     void* target, const void* addr, size_t size,
50     int process_index);
51 };
52
53 /** Base class for an address space (process and snapshot)
54  */
55 struct s_mc_address_space {
56   mc_address_space_class_t address_space_class;
57 };
58
59 // ***** Virtual/non-final methods
60
61 /** Read data from the given address space */
62 static inline __attribute__((always_inline))
63 const void* MC_address_space_read(
64   mc_address_space_t address_space, e_adress_space_read_flags_t flags,
65   void* target, const void* addr, size_t size,
66   int process_index)
67 {
68   return address_space->address_space_class->read(
69     address_space, flags, target, addr, size,
70     process_index);
71 }
72
73 #endif