Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bp5: make RecMap an static anon namespaced var #3881

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions source/adios2/toolkit/format/bp5/BP5Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,37 @@ namespace adios2
namespace format
{

namespace
{
// To keep ABI compatibility with ADIOS 2.9.0
static std::map<BP5Serializer *, BP5Serializer::RecMap> GlobalRecMap;
}

BP5Serializer::RecMap &BP5Serializer::GetRecMap(BP5Serializer *ptr)
{
auto it = GlobalRecMap.find(ptr);
if (it == GlobalRecMap.end())
{
it = GlobalRecMap.insert({ptr, {}}).first;
}
return it->second;
}

BP5Serializer::BP5Serializer() { Init(); }
BP5Serializer::~BP5Serializer()
{
if (!Info.RecMap.empty())
auto &rec_map = BP5Serializer::GetRecMap(this);
if (!rec_map.empty())
{
for (auto &rec : Info.RecMap)
for (auto &rec : rec_map)
{
if (rec.second.OperatorType)
free(rec.second.OperatorType);
}
Info.RecMap.clear();
rec_map.clear();
}
GlobalRecMap.erase(this);

if (Info.MetaFieldCount)
free_FMfield_list(Info.MetaFields);
if (Info.LocalFMContext)
Expand Down Expand Up @@ -79,8 +98,9 @@ void BP5Serializer::Init()
}
BP5Serializer::BP5WriterRec BP5Serializer::LookupWriterRec(void *Key)
{
auto it = Info.RecMap.find(Key);
if (it != Info.RecMap.end())
auto &rec_map = BP5Serializer::GetRecMap(this);
auto it = rec_map.find(Key);
if (it != rec_map.end())
{
return const_cast<BP5WriterRec>(&(it->second));
}
Expand Down Expand Up @@ -438,7 +458,8 @@ BP5Serializer::CreateWriterRec(void *Variable, const char *Name, DataType Type,
size_t ElemSize, size_t DimCount)
{
core::VariableBase *VB = static_cast<core::VariableBase *>(Variable);
auto obj = Info.RecMap.insert(std::make_pair(Variable, _BP5WriterRec()));
auto obj = BP5Serializer::GetRecMap(this).insert(
std::make_pair(Variable, _BP5WriterRec()));
BP5WriterRec Rec = &obj.first->second;
if (Type == DataType::String)
ElemSize = sizeof(char *);
Expand Down Expand Up @@ -1129,7 +1150,7 @@ BufferV *BP5Serializer::ReinitStepData(BufferV *DataBuffer,

void BP5Serializer::CollectFinalShapeValues()
{
for (auto it : Info.RecMap)
for (auto it : BP5Serializer::GetRecMap(this))
{
BP5WriterRec Rec = &it.second;
if (Rec->Shape == ShapeID::GlobalArray)
Expand Down
12 changes: 6 additions & 6 deletions source/adios2/toolkit/format/bp5/BP5Serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#pragma warning(disable : 4250)
#endif

#include <unordered_map>

namespace adios2
{
namespace format
Expand All @@ -42,9 +40,7 @@ class BP5Serializer : virtual public BP5Base
Buffer *AttributeEncodeBuffer;
BufferV *DataBuffer;

~TimestepInfo()
{
}
~TimestepInfo() {}
};

typedef struct _MetadataInfo
Expand Down Expand Up @@ -162,6 +158,7 @@ class BP5Serializer : virtual public BP5Base
struct FFSWriterMarshalBase
{
int RecCount = 0;
BP5WriterRec RecList = NULL;
FMContext LocalFMContext = {0};
int MetaFieldCount = 0;
FMFieldList MetaFields = NULL;
Expand All @@ -171,7 +168,6 @@ class BP5Serializer : virtual public BP5Base
FMFormat AttributeFormat = NULL;
void *AttributeData = NULL;
int AttributeSize = 0;
std::unordered_map<void *, _BP5WriterRec> RecMap;
};

FMFormat GenericAttributeFormat = NULL;
Expand Down Expand Up @@ -255,6 +251,10 @@ class BP5Serializer : virtual public BP5Base
size_t ElemCount;
void *Array;
} ArrayRec;

public:
using RecMap = std::unordered_map<void *, BP5Serializer::_BP5WriterRec>;
static RecMap &GetRecMap(BP5Serializer *ptr);
};

} // end namespace format
Expand Down