FairMQ  1.4.14
C++ Message Queuing Library and Framework
Region.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 ********************************************************************************/
15 #ifndef FAIR_MQ_SHMEM_REGION_H_
16 #define FAIR_MQ_SHMEM_REGION_H_
17 
18 #include "Common.h"
19 
20 #include <FairMQLogger.h>
21 #include <FairMQUnmanagedRegion.h>
22 
23 #include <boost/interprocess/managed_shared_memory.hpp>
24 #include <boost/interprocess/file_mapping.hpp>
25 #include <boost/interprocess/ipc/message_queue.hpp>
26 
27 #include <thread>
28 #include <mutex>
29 #include <condition_variable>
30 #include <unordered_map>
31 
32 namespace fair
33 {
34 namespace mq
35 {
36 namespace shmem
37 {
38 
39 class Manager;
40 
41 struct Region
42 {
43  Region(Manager& manager, uint64_t id, uint64_t size, bool remote, RegionCallback callback = nullptr, const std::string& path = "", int flags = 0);
44 
45  Region() = delete;
46 
47  Region(const Region&) = delete;
48  Region(Region&&) = delete;
49 
50  void InitializeQueues();
51 
52  void StartSendingAcks();
53  void SendAcks();
54  void StartReceivingAcks();
55  void ReceiveAcks();
56  void ReleaseBlock(const RegionBlock &);
57 
58  ~Region();
59 
60  Manager& fManager;
61  bool fRemote;
62  bool fStop;
63  std::string fName;
64  std::string fQueueName;
65  boost::interprocess::shared_memory_object fShmemObject;
66  FILE* fFile;
67  boost::interprocess::file_mapping fFileMapping;
68  boost::interprocess::mapped_region fRegion;
69 
70  std::mutex fBlockMtx;
71  std::condition_variable fBlockSendCV;
72  std::vector<RegionBlock> fBlocksToFree;
73  const std::size_t fAckBunchSize = 256;
74  std::unique_ptr<boost::interprocess::message_queue> fQueue;
75 
76  std::thread fReceiveAcksWorker;
77  std::thread fSendAcksWorker;
78  RegionCallback fCallback;
79 };
80 
81 } // namespace shmem
82 } // namespace mq
83 } // namespace fair
84 
85 #endif /* FAIR_MQ_SHMEM_REGION_H_ */
Definition: Manager.h:46
Definition: Region.h:41
Definition: Common.h:90
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy