Fix shmem::Message::SetUsedSize(0)

This commit is contained in:
Alexey Rybalchenko 2021-01-25 12:40:25 +01:00
parent c5487a11ed
commit c6b13cd3a1
2 changed files with 50 additions and 27 deletions

View File

@ -206,6 +206,9 @@ class Message final : public fair::mq::Message
{
if (newSize == fMeta.fSize) {
return true;
} else if (newSize == 0) {
Deallocate();
return true;
} else if (newSize <= fMeta.fSize) {
try {
fLocalPtr = fManager.ShrinkInPlace(newSize, fLocalPtr, fMeta.fSegmentId);
@ -268,7 +271,7 @@ class Message final : public fair::mq::Message
return fLocalPtr;
}
void CloseMessage()
void Deallocate()
{
if (fMeta.fHandle >= 0 && !fQueued) {
if (fMeta.fRegionId == 0) {
@ -289,6 +292,11 @@ class Message final : public fair::mq::Message
}
fLocalPtr = nullptr;
fMeta.fSize = 0;
}
void CloseMessage()
{
Deallocate();
fAlignment = 0;
fManager.DecrementMsgCounter(); // TODO: put this to debug mode

View File

@ -39,6 +39,7 @@ void RunPushPullWithMsgResize(const string& transport, const string& _address)
FairMQChannel pull{"Pull", "pull", factory};
pull.Connect(address);
{
FairMQMessagePtr outMsg(push.NewMessage(1000));
ASSERT_EQ(outMsg->GetSize(), 1000);
memcpy(outMsg->GetData(), "ABC", 3);
@ -67,6 +68,20 @@ void RunPushPullWithMsgResize(const string& transport, const string& _address)
ASSERT_EQ(static_cast<char*>(inMsg->GetData())[0], 'A');
ASSERT_EQ(static_cast<char*>(inMsg->GetData())[1], 'B');
ASSERT_EQ(static_cast<char*>(inMsg->GetData())[2], 'C');
}
{
FairMQMessagePtr outMsg(push.NewMessage(1000));
ASSERT_EQ(outMsg->SetUsedSize(0), true);
ASSERT_EQ(outMsg->GetSize(), 0);
FairMQMessagePtr msgCopy(push.NewMessage());
msgCopy->Copy(*outMsg);
ASSERT_EQ(msgCopy->GetSize(), 0);
ASSERT_EQ(push.Send(outMsg), 0);
FairMQMessagePtr inMsg(pull.NewMessage());
ASSERT_EQ(pull.Receive(inMsg), 0);
ASSERT_EQ(inMsg->GetSize(), 0);
}
}
void RunMsgRebuild(const string& transport)