FairMQ  1.4.14
C++ Message Queuing Library and Framework
UnmanagedRegion.h
1 /********************************************************************************
2  * Copyright (C) 2014 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_SHMEM_UNMANAGEDREGION_H_
10 #define FAIR_MQ_SHMEM_UNMANAGEDREGION_H_
11 
12 #include "Manager.h"
13 
14 #include <FairMQUnmanagedRegion.h>
15 #include <FairMQLogger.h>
16 
17 #include <boost/interprocess/shared_memory_object.hpp>
18 #include <boost/interprocess/mapped_region.hpp>
19 
20 #include <cstddef> // size_t
21 #include <string>
22 
23 namespace fair
24 {
25 namespace mq
26 {
27 namespace shmem
28 {
29 
30 class Message;
31 class Socket;
32 
34 {
35  friend class Message;
36  friend class Socket;
37 
38  public:
39  UnmanagedRegion(Manager& manager, const size_t size, RegionCallback callback, const std::string& path = "", int flags = 0)
40  : UnmanagedRegion(manager, size, 0, callback, path, flags)
41  {}
42 
43  UnmanagedRegion(Manager& manager, const size_t size, const int64_t userFlags, RegionCallback callback, const std::string& path = "", int flags = 0)
44  : fManager(manager)
45  , fRegion(nullptr)
46  , fRegionId(0)
47  {
48  auto result = fManager.CreateRegion(size, userFlags, callback, path, flags);
49  fRegion = result.first;
50  fRegionId = result.second;
51  }
52 
53  void* GetData() const override { return fRegion->get_address(); }
54  size_t GetSize() const override { return fRegion->get_size(); }
55 
56  ~UnmanagedRegion() override { fManager.RemoveRegion(fRegionId); }
57 
58  private:
59  Manager& fManager;
60  boost::interprocess::mapped_region* fRegion;
61  uint64_t fRegionId;
62 };
63 
64 }
65 }
66 }
67 
68 #endif /* FAIR_MQ_SHMEM_UNMANAGEDREGION_H_ */
Definition: Manager.h:46
Definition: UnmanagedRegion.h:33
Definition: FairMQUnmanagedRegion.h:34
Definition: Socket.h:28
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23
Definition: Message.h:31

privacy