*/
const int ProcessIndexAny = 0;
+/** Options for read operations
+ *
+ * This is a set of flags managed with bitwise operators. Only the
+ * meaningful operations are defined: addition, conversions to/from
+ * integers are not allowed.
+ */
+class ReadOptions {
+ std::uint32_t value_;
+ constexpr explicit ReadOptions(std::uint32_t value) : value_(value) {}
+public:
+ constexpr ReadOptions() : value_(0) {}
+
+ constexpr operator bool() const { return value_ != 0; }
+ constexpr operator!() const { return value_ == 0; }
+
+ constexpr ReadOptions operator|(ReadOptions const& that) const
+ {
+ return ReadOptions(value_ | that.value_);
+ }
+ constexpr ReadOptions operator&(ReadOptions const& that) const
+ {
+ return ReadOptions(value_ & that.value_);
+ }
+ constexpr ReadOptions operator^(ReadOptions const& that) const
+ {
+ return ReadOptions(value_ ^ that.value_);
+ }
+ constexpr ReadOptions operator~() const
+ {
+ return ReadOptions(~value_);
+ }
+
+ ReadOptions& operator|=(ReadOptions const& that)
+ {
+ value_ |= that.value_;
+ return *this;
+ }
+ ReadOptions& operator&=(ReadOptions const& that)
+ {
+ value_ &= that.value_;
+ return *this;
+ }
+ ReadOptions& operator^=(ReadOptions const& that)
+ {
+ value_ &= that.value_;
+ return *this;
+ }
+
+ /** Copy the data to the given buffer */
+ static constexpr ReadOptions none() { return ReadOptions(0); }
+
+ /** Allows to return a pointer to another buffer where the data is
+ * available instead of copying the data into the buffer
+ */
+ static constexpr ReadOptions lazy() { return ReadOptions(1); }
+};
+
/** A given state of a given process (abstract base class)
*
* Currently, this might either be:
private:
Process* process_;
public:
- enum ReadMode {
-
- /** Copy the data to the given buffer */
- Normal,
-
- /** Allows the `read_bytes` to return a pointer to another buffer
- * where the data is available instead of copying the data into the
- * buffer.
- *
- * This adds quite a level of ugliness but it was found to more
- * efficient at some point. We should check if there is still
- * a noticeable different and get rid of it.
- */
- Lazy
- };
AddressSpace(Process* process) : process_(process) {}
virtual ~AddressSpace();
* @param size number of bytes
* @param address remote source address of the data
* @param process_index which process (used for SMPI privatization)
- * @param mode
+ * @param options
*/
virtual const void* read_bytes(void* buffer, std::size_t size,
remote_ptr<void> address, int process_index = ProcessIndexAny,
- ReadMode mode = Normal) const = 0;
+ ReadOptions options = ReadOptions::none()) const = 0;
/** Read a given data structure from the address space */
template<class T> inline
const void *Process::read_bytes(void* buffer, std::size_t size,
remote_ptr<void> address, int process_index,
- AddressSpace::ReadMode mode) const
+ ReadOptions options) const
{
if (process_index != simgrid::mc::ProcessIndexDisabled) {
std::shared_ptr<simgrid::mc::ObjectInformation> const& info =
// Read memory:
const void* read_bytes(void* buffer, std::size_t size,
remote_ptr<void> address, int process_index = ProcessIndexAny,
- ReadMode mode = Normal) const override;
+ ReadOptions options = ReadOptions::none()) const override;
void read_variable(const char* name, void* target, size_t size) const;
template<class T>
T read_variable(const char *name) const
xbt_mheap_t heap1 = (xbt_mheap_t)s1->read_bytes(
alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
remote(process->heap_address),
- simgrid::mc::ProcessIndexMissing, simgrid::mc::AddressSpace::Lazy);
+ simgrid::mc::ProcessIndexMissing, simgrid::mc::ReadOptions::lazy());
xbt_mheap_t heap2 = (xbt_mheap_t)s2->read_bytes(
alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
remote(process->heap_address),
- simgrid::mc::ProcessIndexMissing, simgrid::mc::AddressSpace::Lazy);
+ simgrid::mc::ProcessIndexMissing, simgrid::mc::ReadOptions::lazy());
res_init = init_heap_information(heap1, heap2, &s1->to_ignore, &s2->to_ignore);
if (res_init == -1) {
#ifdef MC_DEBUG
/* Compare global variables */
is_diff =
- compare_global_variables(region1->object_info( ), simgrid::mc::AddressSpace::Normal,
+ compare_global_variables(region1->object_info(),
+ simgrid::mc::ProcessIndexDisabled,
region1, region2,
s1, s2);
const void* Snapshot::read_bytes(void* buffer, std::size_t size,
remote_ptr<void> address, int process_index,
- AddressSpace::ReadMode mode) const
+ ReadOptions options) const
{
mc_mem_region_t region = mc_get_snapshot_region((void*)address.address(), this, process_index);
if (region) {
const void* res = MC_region_read(region, buffer, (void*)address.address(), size);
- if (buffer == res || mode == AddressSpace::Lazy)
+ if (buffer == res || options & ReadOptions::lazy())
return res;
else {
memcpy(buffer, res, size);
}
else
return this->process()->read_bytes(
- buffer, size, address, process_index, mode);
+ buffer, size, address, process_index, options);
}
}
~Snapshot();
const void* read_bytes(void* buffer, std::size_t size,
remote_ptr<void> address, int process_index = ProcessIndexAny,
- ReadMode mode = Normal) const override;
+ ReadOptions options = ReadOptions::none()) const override;
public: // To be private
int num_state;
std::size_t heap_bytes_used;