mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
region example: fix race between segment reset & presence check
This commit is contained in:
parent
75e68e3e4d
commit
fdfde95dec
|
@ -19,6 +19,7 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
@ -113,6 +114,7 @@ struct ShmManager
|
||||||
|
|
||||||
bool CheckPresence()
|
bool CheckPresence()
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(localMtx);
|
||||||
for (const auto& sc : segmentCfgs) {
|
for (const auto& sc : segmentCfgs) {
|
||||||
if (!(fair::mq::shmem::Monitor::SegmentIsPresent(fair::mq::shmem::ShmId{shmId}, sc.id))) {
|
if (!(fair::mq::shmem::Monitor::SegmentIsPresent(fair::mq::shmem::ShmId{shmId}, sc.id))) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -128,6 +130,7 @@ struct ShmManager
|
||||||
|
|
||||||
void ResetContent()
|
void ResetContent()
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(localMtx);
|
||||||
fair::mq::shmem::Monitor::ResetContent(fair::mq::shmem::ShmId{shmId}, segmentCfgs, regionCfgs);
|
fair::mq::shmem::Monitor::ResetContent(fair::mq::shmem::ShmId{shmId}, segmentCfgs, regionCfgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,6 +148,7 @@ struct ShmManager
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string shmId;
|
std::string shmId;
|
||||||
|
std::mutex localMtx;
|
||||||
map<uint16_t, fair::mq::shmem::Segment> segments;
|
map<uint16_t, fair::mq::shmem::Segment> segments;
|
||||||
map<uint16_t, unique_ptr<fair::mq::shmem::UnmanagedRegion>> regions;
|
map<uint16_t, unique_ptr<fair::mq::shmem::UnmanagedRegion>> regions;
|
||||||
std::vector<fair::mq::shmem::SegmentConfig> segmentCfgs;
|
std::vector<fair::mq::shmem::SegmentConfig> segmentCfgs;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user