logic: Show message box informing about shared memory problems before indexing (issue #508)

This commit is contained in:
Eberhard Graether
2017-11-07 17:49:21 +01:00
parent a2d412ccfa
commit 17a1f7eac9
5 changed files with 57 additions and 8 deletions
+19 -3
View File
@@ -57,6 +57,23 @@ std::string SharedMemory::checkName(const std::string& name)
return name.size() > 18 ? name.substr(0, 18) : name;
}
std::string SharedMemory::checkSharedMemory(const std::string& name)
{
std::string error;
try
{
SharedMemory memory("test_" + name, 65536 /* 64 kB */, CREATE_AND_DELETE);
}
catch (boost::interprocess::interprocess_exception& e)
{
LOG_ERROR_STREAM(<< "boost exception thrown at shared memory check: " << e.what());
error = e.what();
}
return error;
}
void SharedMemory::deleteSharedMemory(const std::string& name)
{
boost::interprocess::shared_memory_object::remove((s_memoryNamePrefix + name).c_str());
@@ -116,11 +133,10 @@ SharedMemory::SharedMemory(const std::string& name, size_t initialMemorySize, Ac
boost::interprocess::named_mutex mutex(boost::interprocess::open_only, getMutexName().c_str());
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> lock(mutex, boost::interprocess::try_to_lock);
}
}
catch (boost::interprocess::interprocess_exception& e)
{
LOG_ERROR_STREAM(<< "boost exception thrown at shared momory creation - " << getMemoryName() << ": " << e.what());
LOG_ERROR_STREAM(<< "boost exception thrown at shared memory creation - " << getMemoryName() << ": " << e.what());
throw e;
}
}
@@ -142,7 +158,7 @@ SharedMemory::~SharedMemory()
}
catch (boost::interprocess::interprocess_exception& e)
{
LOG_ERROR_STREAM(<< "boost exception thrown at shared momory destruction - " << getMemoryName() << ": " << e.what());
LOG_ERROR_STREAM(<< "boost exception thrown at shared memory destruction - " << getMemoryName() << ": " << e.what());
throw e;
}
}
@@ -42,6 +42,7 @@ public:
// Names addressing shared memory objects longer than 29 characters can throw and exception
static std::string checkName(const std::string& name);
static std::string checkSharedMemory(const std::string& name);
static void deleteSharedMemory(const std::string& name);
SharedMemory(const std::string& name, size_t initialMemorySize, AccessMode mode);
@@ -17,9 +17,15 @@ std::shared_ptr<SharedMemoryGarbageCollector> SharedMemoryGarbageCollector::s_in
SharedMemoryGarbageCollector* SharedMemoryGarbageCollector::createInstance()
{
if (!s_instance)
try
{
if (!s_instance)
{
s_instance = std::shared_ptr<SharedMemoryGarbageCollector>(new SharedMemoryGarbageCollector());
}
}
catch (boost::interprocess::interprocess_exception& e)
{
s_instance = std::shared_ptr<SharedMemoryGarbageCollector>(new SharedMemoryGarbageCollector());
}
return s_instance.get();