CMS 3D CMS Logo

ReadBuffer.h
Go to the documentation of this file.
1 #ifndef FWCore_SharedMemory_ReadBuffer_h
2 #define FWCore_SharedMemory_ReadBuffer_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/SharedMemory
6 // Class : ReadBuffer
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: 21/01/2020
19 //
20 
21 // system include files
22 #include <array>
23 #include <memory>
24 #include <string>
25 #include "boost/interprocess/managed_shared_memory.hpp"
26 
27 // user include files
30 
31 // forward declarations
32 
33 namespace edm::shared_memory {
34  class ReadBuffer {
35  public:
39  ReadBuffer(std::string const& iUniqueName, BufferInfo* iBufferInfo)
40  : buffer_{nullptr, 0}, bufferInfo_{iBufferInfo}, bufferOldIndex_{3} {
41  *bufferInfo_ = {0, 0};
42  bufferNames_[0] = iUniqueName + buffer_names::kBuffer0;
43  bufferNames_[1] = iUniqueName + buffer_names::kBuffer1;
44  }
45  ReadBuffer(const ReadBuffer&) = delete;
46  const ReadBuffer& operator=(const ReadBuffer&) = delete;
47  ReadBuffer(ReadBuffer&&) = delete;
48  const ReadBuffer& operator=(ReadBuffer&&) = delete;
49 
50  // ---------- const member functions ---------------------
51  int bufferIdentifier() const { return bufferInfo_->identifier_; }
52 
53  // ---------- member functions ---------------------------
54  std::pair<char*, std::size_t> buffer() {
55  if (mustGetBufferAgain()) {
56  using namespace boost::interprocess;
57  sm_ = std::make_unique<managed_shared_memory>(open_only, bufferNames_[bufferInfo_->index_].c_str());
58  buffer_ = sm_->find<char>(buffer_names::kBuffer);
60  }
61  return buffer_;
62  }
63 
64  private:
66  // ---------- member data --------------------------------
67  std::pair<char*, std::size_t> buffer_;
70  std::array<std::string, 2> bufferNames_;
71  std::unique_ptr<boost::interprocess::managed_shared_memory> sm_;
72  };
73 } // namespace edm::shared_memory
74 
75 #endif
edm::shared_memory::BufferInfo::identifier_
int identifier_
Definition: BufferInfo.h:28
BufferInfo.h
edm::shared_memory::ReadBuffer::sm_
std::unique_ptr< boost::interprocess::managed_shared_memory > sm_
Definition: ReadBuffer.h:71
edm::shared_memory::buffer_names::kBuffer0
constexpr char const *const kBuffer0
Definition: buffer_names.h:30
edm::shared_memory::ReadBuffer::mustGetBufferAgain
bool mustGetBufferAgain() const
Definition: ReadBuffer.h:65
edm::shared_memory::BufferInfo::index_
char index_
Definition: BufferInfo.h:29
edm::shared_memory::ReadBuffer::ReadBuffer
ReadBuffer(std::string const &iUniqueName, BufferInfo *iBufferInfo)
Definition: ReadBuffer.h:39
edm::shared_memory::BufferInfo
Definition: BufferInfo.h:27
edm::shared_memory::ReadBuffer::bufferNames_
std::array< std::string, 2 > bufferNames_
Definition: ReadBuffer.h:70
edm::shared_memory::ReadBuffer::bufferOldIndex_
char bufferOldIndex_
Definition: ReadBuffer.h:69
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::shared_memory::buffer_names::kBuffer
constexpr char const *const kBuffer
Definition: buffer_names.h:29
edm::shared_memory::ReadBuffer::bufferIdentifier
int bufferIdentifier() const
Definition: ReadBuffer.h:51
buffer_names.h
edm::shared_memory
Definition: buffer_names.h:27
edm::shared_memory::ReadBuffer::operator=
const ReadBuffer & operator=(const ReadBuffer &)=delete
edm::shared_memory::buffer_names::kBuffer1
constexpr char const *const kBuffer1
Definition: buffer_names.h:31
edm::shared_memory::ReadBuffer
Definition: ReadBuffer.h:34
ReadBuffer
edm::shared_memory::ReadBuffer::buffer_
std::pair< char *, std::size_t > buffer_
Definition: ReadBuffer.h:67
edm::shared_memory::ReadBuffer::bufferInfo_
BufferInfo * bufferInfo_
Definition: ReadBuffer.h:68
edm::shared_memory::ReadBuffer::buffer
std::pair< char *, std::size_t > buffer()
Definition: ReadBuffer.h:54