Skip to content

Commit

Permalink
Merge pull request #40422 from Dr15Jones/moreInfoSharedMemory
Browse files Browse the repository at this point in the history
Additional info when exception thrown in SharedMemory
  • Loading branch information
cmsbuild authored Jan 4, 2023
2 parents 9eb6ddb + 361fca7 commit 950f428
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion FWCore/SharedMemory/src/WriteBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ WriteBuffer::~WriteBuffer() {
//
void WriteBuffer::growBuffer(std::size_t iLength) {
int newBuffer = (bufferInfo_->index_ + 1) % 2;
bool destroyedBuffer = false;
auto oldIndex = bufferInfo_->index_;
if (sm_) {
destroyedBuffer = true;
try {
sm_->destroy<char>(buffer_names::kBuffer);
} catch (boost::interprocess::interprocess_exception const& iExcept) {
Expand Down Expand Up @@ -71,7 +74,24 @@ void WriteBuffer::growBuffer(std::size_t iLength) {
bufferSize_ = iLength;
bufferInfo_->index_ = newBuffer;
bufferInfo_->identifier_ = bufferInfo_->identifier_ + 1;
buffer_ = sm_->construct<char>(buffer_names::kBuffer)[iLength](0);
try {
buffer_ = sm_->construct<char>(buffer_names::kBuffer)[iLength](0);
} catch (boost::interprocess::interprocess_exception const& iExcept) {
cms::Exception except("SharedMemory");
except << "boost::interprocess exception caught: " << iExcept.what();
{
std::ostringstream os;
os << "in growBuffer while creating the buffer within the shared memory object '" << bufferNames_[newBuffer]
<< "' with index " << newBuffer << " where the buffer is of length " << iLength;

if (destroyedBuffer) {
os << " after destroying the previous shared memory object '" << bufferNames_[oldIndex] << "' with index "
<< oldIndex;
}
except.addContext(os.str());
}
throw except;
}
assert(buffer_);
}

Expand Down

0 comments on commit 950f428

Please sign in to comment.