Shm: throw on bad_alloc, option to disable

This commit is contained in:
Alexey Rybalchenko
2020-05-17 14:46:15 +02:00
parent 2916a491b9
commit 0d03c76a75
7 changed files with 42 additions and 29 deletions

View File

@@ -59,11 +59,13 @@ class TransportFactory final : public fair::mq::TransportFactory
std::string sessionName = "default";
size_t segmentSize = 2000000000;
bool autolaunchMonitor = false;
bool throwOnBadAlloc = true;
if (config) {
numIoThreads = config->GetProperty<int>("io-threads", numIoThreads);
sessionName = config->GetProperty<std::string>("session", sessionName);
segmentSize = config->GetProperty<size_t>("shm-segment-size", segmentSize);
autolaunchMonitor = config->GetProperty<bool>("shm-monitor", autolaunchMonitor);
throwOnBadAlloc = config->GetProperty<bool>("shm-throw-bad-alloc", throwOnBadAlloc);
} else {
LOG(debug) << "ProgOptions not available! Using defaults.";
}
@@ -84,8 +86,7 @@ class TransportFactory final : public fair::mq::TransportFactory
Manager::StartMonitor(fShmId);
}
fManager = tools::make_unique<Manager>(fShmId, fDeviceId, segmentSize);
fManager = tools::make_unique<Manager>(fShmId, fDeviceId, segmentSize, throwOnBadAlloc);
} catch (boost::interprocess::interprocess_exception& e) {
LOG(error) << "Could not initialize shared memory transport: " << e.what();
throw std::runtime_error(tools::ToString("Could not initialize shared memory transport: ", e.what()));