shmmonitor: enable read only access

This commit is contained in:
Alexey Rybalchenko 2021-03-27 23:19:53 +01:00
parent 5228407932
commit efd42075a9

View File

@ -248,7 +248,7 @@ void Monitor::CheckSegment()
using namespace boost::interprocess; using namespace boost::interprocess;
try { try {
managed_shared_memory managementSegment(open_only, fManagementSegmentName.c_str()); managed_shared_memory managementSegment(open_read_only, fManagementSegmentName.c_str());
VoidAlloc allocInstance(managementSegment.get_segment_manager()); VoidAlloc allocInstance(managementSegment.get_segment_manager());
Uint16SegmentInfoHashMap* segmentInfos = managementSegment.find<Uint16SegmentInfoHashMap>(unique_instance).first; Uint16SegmentInfoHashMap* segmentInfos = managementSegment.find<Uint16SegmentInfoHashMap>(unique_instance).first;
@ -261,9 +261,9 @@ void Monitor::CheckSegment()
for (const auto& s : *segmentInfos) { for (const auto& s : *segmentInfos) {
if (s.second.fAllocationAlgorithm == AllocationAlgorithm::rbtree_best_fit) { if (s.second.fAllocationAlgorithm == AllocationAlgorithm::rbtree_best_fit) {
segments.emplace(s.first, RBTreeBestFitSegment(open_only, std::string("fmq_" + fShmId + "_m_" + to_string(s.first)).c_str())); segments.emplace(s.first, RBTreeBestFitSegment(open_read_only, std::string("fmq_" + fShmId + "_m_" + to_string(s.first)).c_str()));
} else { } else {
segments.emplace(s.first, SimpleSeqFitSegment(open_only, std::string("fmq_" + fShmId + "_m_" + to_string(s.first)).c_str())); segments.emplace(s.first, SimpleSeqFitSegment(open_read_only, std::string("fmq_" + fShmId + "_m_" + to_string(s.first)).c_str()));
} }
} }
@ -280,7 +280,7 @@ void Monitor::CheckSegment()
numDevices = dc->fCount; numDevices = dc->fCount;
} }
#ifdef FAIRMQ_DEBUG_MODE #ifdef FAIRMQ_DEBUG_MODE
msgCounters = managementSegment.find_or_construct<Uint16MsgCounterHashMap>(unique_instance)(allocInstance); msgCounters = managementSegment.find<Uint16MsgCounterHashMap>(unique_instance).first;
#endif #endif
} }
@ -313,7 +313,7 @@ void Monitor::CheckSegment()
ss << " [" << s.first ss << " [" << s.first
<< "]: total: " << total << "]: total: " << total
#ifdef FAIRMQ_DEBUG_MODE #ifdef FAIRMQ_DEBUG_MODE
<< ", msgs: " << (*msgCounters)[s.first].fCount << ", msgs: " << ( (msgCounters != nullptr) ? to_string((*msgCounters)[s.first].fCount) : "unknown")
#else #else
<< ", msgs: NODEBUG" << ", msgs: NODEBUG"
#endif #endif