return if removal of shmem segment was successful

This commit is contained in:
Dennis Luxen 2013-10-29 18:43:11 +01:00
parent 67d6efed21
commit faaf97ef62

View File

@ -68,7 +68,9 @@ class SharedMemory : boost::noncopyable {
if(m_initialized) { if(m_initialized) {
SimpleLogger().Write(logDEBUG) << SimpleLogger().Write(logDEBUG) <<
"automatic memory deallocation"; "automatic memory deallocation";
boost::interprocess::xsi_shared_memory::remove(m_shmid); if(!boost::interprocess::xsi_shared_memory::remove(m_shmid)) {
SimpleLogger().Write(logDEBUG) << "could not deallocate id " << m_shmid;
}
} }
} }
}; };
@ -139,12 +141,12 @@ public:
} }
template<typename IdentifierT > template<typename IdentifierT >
static void Remove( static bool Remove(
const IdentifierT id const IdentifierT id
) { ) {
OSRMLockFile lock_file; OSRMLockFile lock_file;
boost::interprocess::xsi_key key( lock_file().string().c_str(), id ); boost::interprocess::xsi_key key( lock_file().string().c_str(), id );
Remove(key); return Remove(key);
} }
private: private:
@ -161,21 +163,23 @@ private:
return result; return result;
} }
static void Remove( static bool Remove(
const boost::interprocess::xsi_key &key const boost::interprocess::xsi_key &key
) { ) {
bool ret = false;
try{ try{
SimpleLogger().Write(logDEBUG) << "deallocating prev memory"; SimpleLogger().Write(logDEBUG) << "deallocating prev memory";
boost::interprocess::xsi_shared_memory xsi( boost::interprocess::xsi_shared_memory xsi(
boost::interprocess::open_only, boost::interprocess::open_only,
key key
); );
boost::interprocess::xsi_shared_memory::remove(xsi.get_shmid()); ret = boost::interprocess::xsi_shared_memory::remove(xsi.get_shmid());
} catch(boost::interprocess::interprocess_exception &e){ } catch(const boost::interprocess::interprocess_exception &e){
if(e.get_error_code() != boost::interprocess::not_found_error) { if(e.get_error_code() != boost::interprocess::not_found_error) {
throw; throw;
} }
} }
return ret;
} }
boost::interprocess::xsi_key key; boost::interprocess::xsi_key key;