Skip to content

Source · fairmq/

UnmanagedRegion.hpublic header

Defines struct fair::mq::RegionBlock, struct fair::mq::RegionConfig, struct fair::mq::RegionInfo, struct fair::mq::UnmanagedRegion.

Described in readout: a readout chain, region: unmanaged regions, Move from the FairMQ* names, Unmanaged regions.

1/********************************************************************************2 * Copyright (C) 2021-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH  *3 *                                                                              *4 *              This software is distributed under the terms of the             *5 *              GNU Lesser General Public Licence (LGPL) version 3,             *6 *                  copied verbatim in the file "LICENSE"                       *7 ********************************************************************************/8 9#ifndef FAIR_MQ_UNMANAGEDREGION_H10#define FAIR_MQ_UNMANAGEDREGION_H11 12#include <fairmq/TransportEnum.h>13 14#include <cstddef>   // size_t15#include <cstdint>   // uint32_t16 17#include <functional>   // std::function18#include <memory>       // std::unique_ptr19#include <optional>     // std::optional20#include <ostream>21#include <string>22#include <vector>23 24namespace fair::mq {25 26class TransportFactory;27 28enum class RegionEvent : int29{30    created,31    destroyed,32    local_only33};34 35struct RegionInfo36{37    RegionInfo() = default;38 39    RegionInfo(bool _managed,40               uint64_t _id,41               void* _ptr,42               size_t _size,43               int64_t _flags,44               RegionEvent _event)45        : managed(_managed)46        , id(_id)47        , ptr(_ptr)48        , size(_size)49        , flags(_flags)50        , event(_event)51    {}52 53    bool managed = true;   // managed/unmanaged54    uint64_t id = 0;       // id of the region55    void* ptr = nullptr;   // pointer to the start of the region56    size_t size = 0;       // region size57    int64_t flags = 0;     // custom flags set by the creator58    RegionEvent event = RegionEvent::created;59};60 61struct RegionBlock62{63    void* ptr;64    size_t size;65    void* hint;66 67    RegionBlock(void* p, size_t s, void* h)68        : ptr(p)69        , size(s)70        , hint(h)71    {}72};73 74using RegionCallback = std::function<void(void*, size_t, void*)>;75using RegionBulkCallback = std::function<void(const std::vector<RegionBlock>&)>;76using RegionEventCallback = std::function<void(RegionInfo)>;77 78struct UnmanagedRegion79{80    UnmanagedRegion() = default;81    UnmanagedRegion(TransportFactory* factory)82        : fTransport(factory)83    {}84 85    UnmanagedRegion(const UnmanagedRegion&) = delete;86    UnmanagedRegion(UnmanagedRegion&&) = delete;87    UnmanagedRegion& operator=(const UnmanagedRegion&) = delete;88    UnmanagedRegion& operator=(UnmanagedRegion&&) = delete;89 90    virtual void* GetData() const = 0;91    virtual size_t GetSize() const = 0;92    virtual uint16_t GetId() const = 0;93    virtual void SetLinger(uint32_t linger) = 0;94    virtual uint32_t GetLinger() const = 0;95 96    virtual Transport GetType() const = 0;97    TransportFactory* GetTransport() { return fTransport; }98    void SetTransport(TransportFactory* transport) { fTransport = transport; }99 100    virtual ~UnmanagedRegion() = default;101 102  private:103    TransportFactory* fTransport{nullptr};104};105 106using UnmanagedRegionPtr = std::unique_ptr<UnmanagedRegion>;107 108inline std::ostream& operator<<(std::ostream& os, const RegionEvent& event)109{110    switch (event) {111        case RegionEvent::created:112            return os << "created";113        case RegionEvent::destroyed:114            return os << "destroyed";115        case RegionEvent::local_only:116            return os << "local_only";117        default:118            return os << "unrecognized event";119    }120}121 122struct RegionConfig123{124    RegionConfig() = default;125 126    RegionConfig(bool _lock, bool _zero)127        : lock(_lock)128        , zero(_zero)129    {}130 131    bool lock = false; /// mlock region after creation132    bool zero = false; /// zero region content after creation133    bool removeOnDestruction = true; /// remove the region on object destruction134    int creationFlags = 0; /// flags passed to the underlying transport on region creation135    int64_t userFlags = 0; /// custom flags that have no effect on the transport, but can be retrieved from the region by the user136    uint64_t size = 0; /// region size137    uint64_t rcSegmentSize = 100000000; /// size of the segment that stores reference counts when "soft"-copying the messages138    std::string path;                   /// file path, if the region is backed by a file139    std::optional<uint16_t> id = std::nullopt; /// region id140    uint32_t linger = 100; /// delay in ms before region destruction to collect outstanding events141};142 143}   // namespace fair::mq144 145using FairMQRegionEvent [[deprecated("Use fair::mq::RegionEvent")]] = fair::mq::RegionEvent;146using FairMQRegionInfo [[deprecated("Use fair::mq::RegionInfo")]] = fair::mq::RegionInfo;147using FairMQRegionBlock [[deprecated("Use fair::mq::RegionBlock")]] = fair::mq::RegionBlock;148using FairMQRegionCallback [[deprecated("Use fair::mq::RegionCallback")]] = fair::mq::RegionCallback;149using FairMQRegionBulkCallback [[deprecated("Use fair::mq::RegionBulkCallback")]] = fair::mq::RegionBulkCallback;150using FairMQRegionEventCallback [[deprecated("Use fair::mq::RegionEventCallback")]] = fair::mq::RegionEventCallback;151using FairMQUnmanagedRegion [[deprecated("Use fair::mq::UnmanagedRegion")]] = fair::mq::UnmanagedRegion;152using FairMQUnmanagedRegionPtr [[deprecated("Use fair::mq::UnmanagedRegionPtr")]] = fair::mq::UnmanagedRegionPtr;153using FairMQRegionConfig [[deprecated("Use fair::mq::RegionConfig")]] = fair::mq::RegionConfig;154 155#endif   // FAIR_MQ_UNMANAGEDREGION_H