changes
This commit is contained in:
+62
@@ -327,4 +327,66 @@ bool SharedMemory::ensureCapacityForInsert(MappingInfo& mapping)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return resizeMapping(mapping, capacity * 2);
|
return resizeMapping(mapping, capacity * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: ensureLatestMapping
|
||||||
|
Description: Remaps the file if another process has resized it.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
Returns:
|
||||||
|
- bool: True if the mapping is valid and up to date, otherwise false
|
||||||
|
*/
|
||||||
|
bool SharedMemory::ensureLatestMapping(MappingInfo& mapping)
|
||||||
|
{
|
||||||
|
FileHeader* header = getHeader(mapping);
|
||||||
|
if (header == nullptr)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (header->capacity == mapping.mappedCapacity)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!UnmapViewOfFile(mapping.mappedView))
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mapping.mappedView = nullptr;
|
||||||
|
CloseHandle(mapping.mappingHandle);
|
||||||
|
mapping.mappingHandle = NULL;
|
||||||
|
mapping.mappingHandle =
|
||||||
|
CreateFileMappingA(
|
||||||
|
mapping.fileHandle,
|
||||||
|
NULL,
|
||||||
|
PAGE_READWRITE,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
if (mapping.mappingHandle == NULL)
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mapping.mappedView =
|
||||||
|
MapViewOfFile(
|
||||||
|
mapping.mappingHandle,
|
||||||
|
FILE_MAP_ALL_ACCESS,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
if (mapping.mappedView == nullptr)
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
header = getHeader(mapping);
|
||||||
|
if (header == nullptr)
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mapping.mappedCapacity = header->capacity;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user