CMS 3D CMS Logo

WriteBuffer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/SharedMemory
4 // Class : WriteBuffer
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones
10 // Created: 21/01/2020
11 //
12 
13 // system include files
14 
15 // user include files
18 //
19 // constants, enums and typedefs
20 //
21 using namespace edm::shared_memory;
22 
23 //
24 // static data member definitions
25 //
26 
27 //
28 // constructors and destructor
29 //
30 
32  if (sm_) {
33  sm_->destroy<char>(buffer_names::kBuffer);
34  sm_.reset();
36  }
37 }
38 //
39 // member functions
40 //
41 void WriteBuffer::growBuffer(std::size_t iLength) {
42  int newBuffer = (bufferInfo_->index_ + 1) % 2;
43  if (sm_) {
44  try {
45  sm_->destroy<char>(buffer_names::kBuffer);
46  } catch (boost::interprocess::interprocess_exception const& iExcept) {
47  throw cms::Exception("SharedMemory")
48  << "in growBuffer while destroying the shared memory object the following exception was caught\n"
49  << iExcept.what();
50  }
51  sm_.reset();
52  try {
54  } catch (boost::interprocess::interprocess_exception const& iExcept) {
55  throw cms::Exception("SharedMemory")
56  << "in growBuffer while removing the shared memory object named '" << bufferNames_[bufferInfo_->index_]
57  << "' the following exception was caught\n"
58  << iExcept.what();
59  }
60  }
61  try {
62  sm_ = std::make_unique<boost::interprocess::managed_shared_memory>(
63  boost::interprocess::open_or_create, bufferNames_[newBuffer].c_str(), iLength + 1024);
64  } catch (boost::interprocess::interprocess_exception const& iExcept) {
65  throw cms::Exception("SharedMemory") << "in growBuffer while creating the shared memory object '"
66  << bufferNames_[newBuffer] << "' of length " << iLength + 1024
67  << " the following exception was caught\n"
68  << iExcept.what();
69  }
70  assert(sm_.get());
71  bufferSize_ = iLength;
72  bufferInfo_->index_ = newBuffer;
74  buffer_ = sm_->construct<char>(buffer_names::kBuffer)[iLength](0);
75  assert(buffer_);
76 }
77 
78 //
79 // const member functions
80 //
81 
82 //
83 // static member functions
84 //
constexpr char const *const kBuffer
Definition: buffer_names.h:29
assert(be >=bs)
void growBuffer(std::size_t iLength)
Definition: WriteBuffer.cc:41
std::array< std::string, 2 > bufferNames_
Definition: WriteBuffer.h:71
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:223
std::unique_ptr< boost::interprocess::managed_shared_memory > sm_
Definition: WriteBuffer.h:72