mirror of
https://github.com/espressif/openthread.git
synced 2026-08-06 18:57:47 +00:00
[message] remove MessagePool from the Message::Metadata (#11616)
This commit simplifies the `Message::Metadata` so that it no longer tracks the `MessagePool`. Instead the `Message` now tracks the `ot::Instance` it is associated with and acts as a `GetProvider`, allowing access to any component within `Instance`, including the `MessagePool`.
This commit is contained in:
@@ -57,6 +57,15 @@ extern uint64_t gInstanceRaw[];
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||
/**
|
||||
* Gets the single OpenThread instance.
|
||||
*
|
||||
* @returns The single OpenThread instance.
|
||||
*/
|
||||
inline Instance &GetSingleInstance(void) { return *reinterpret_cast<Instance *>(&gInstanceRaw); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Implements `Get<Type>()` method for different `Type` objects belonging to the OpenThread
|
||||
* instance.
|
||||
@@ -110,7 +119,7 @@ public:
|
||||
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||
Instance &GetInstance(void) const { return *mInstance; }
|
||||
#else
|
||||
Instance &GetInstance(void) const { return *reinterpret_cast<Instance *>(&gInstanceRaw); }
|
||||
Instance &GetInstance(void) const { return GetSingleInstance(); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -66,7 +66,10 @@ Message *MessagePool::Allocate(Message::Type aType, uint16_t aReserveHeader, con
|
||||
VerifyOrExit((message = static_cast<Message *>(NewBuffer(aSettings.GetPriority()))) != nullptr);
|
||||
|
||||
ClearAllBytes(*message);
|
||||
message->SetMessagePool(this);
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||
message->GetMetadata().mInstance = &GetInstance();
|
||||
#endif
|
||||
message->SetType(aType);
|
||||
message->SetReserved(aReserveHeader);
|
||||
message->SetLinkSecurityEnabled(aSettings.IsLinkSecurityEnabled());
|
||||
@@ -229,7 +232,7 @@ Error Message::ResizeMessage(uint16_t aLength)
|
||||
{
|
||||
if (curBuffer->GetNextBuffer() == nullptr)
|
||||
{
|
||||
curBuffer->SetNextBuffer(GetMessagePool()->NewBuffer(GetPriority()));
|
||||
curBuffer->SetNextBuffer(Get<MessagePool>().NewBuffer(GetPriority()));
|
||||
VerifyOrExit(curBuffer->GetNextBuffer() != nullptr, error = kErrorNoBufs);
|
||||
}
|
||||
|
||||
@@ -241,13 +244,13 @@ Error Message::ResizeMessage(uint16_t aLength)
|
||||
curBuffer = curBuffer->GetNextBuffer();
|
||||
lastBuffer->SetNextBuffer(nullptr);
|
||||
|
||||
GetMessagePool()->FreeBuffers(curBuffer);
|
||||
Get<MessagePool>().FreeBuffers(curBuffer);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Message::Free(void) { GetMessagePool()->Free(this); }
|
||||
void Message::Free(void) { Get<MessagePool>().Free(this); }
|
||||
|
||||
Message *Message::GetNext(void) const
|
||||
{
|
||||
@@ -421,7 +424,7 @@ Error Message::PrependBytes(const void *aBuf, uint16_t aLength)
|
||||
|
||||
while (aLength > GetReserved())
|
||||
{
|
||||
VerifyOrExit((newBuffer = GetMessagePool()->NewBuffer(GetPriority())) != nullptr, error = kErrorNoBufs);
|
||||
VerifyOrExit((newBuffer = Get<MessagePool>().NewBuffer(GetPriority())) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
newBuffer->SetNextBuffer(GetNextBuffer());
|
||||
SetNextBuffer(newBuffer);
|
||||
@@ -769,7 +772,7 @@ Message *Message::Clone(uint16_t aLength) const
|
||||
uint16_t offset;
|
||||
|
||||
aLength = Min(GetLength(), aLength);
|
||||
messageCopy = GetMessagePool()->Allocate(GetType(), GetReserved(), settings);
|
||||
messageCopy = Get<MessagePool>().Allocate(GetType(), GetReserved(), settings);
|
||||
VerifyOrExit(messageCopy != nullptr, error = kErrorNoBufs);
|
||||
SuccessOrExit(error = messageCopy->AppendBytesFromMessage(*this, 0, aLength));
|
||||
|
||||
|
||||
+14
-13
@@ -190,6 +190,9 @@ public:
|
||||
protected:
|
||||
struct Metadata
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||
Instance *mInstance;
|
||||
#endif
|
||||
bool mDirectTx : 1; // Whether a direct transmission is required.
|
||||
bool mLinkSecurity : 1; // Whether link security is enabled.
|
||||
bool mInPriorityQ : 1; // Whether the message is queued in normal or priority queue.
|
||||
@@ -227,13 +230,12 @@ protected:
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
int64_t mNetworkTimeOffset; // The time offset to the Thread network time, in microseconds.
|
||||
#endif
|
||||
TimeMilli mTimestamp; // The message timestamp.
|
||||
Message *mNext; // Next message in a doubly linked list.
|
||||
Message *mPrev; // Previous message in a doubly linked list.
|
||||
MessagePool *mMessagePool; // Message pool for this message.
|
||||
void *mQueue; // The queue where message is queued (if any). Queue type from `mInPriorityQ`.
|
||||
RssAverager mRssAverager; // The averager maintaining the received signal strength (RSS) average.
|
||||
LqiAverager mLqiAverager; // The averager maintaining the Link quality indicator (LQI) average.
|
||||
TimeMilli mTimestamp; // The message timestamp.
|
||||
Message *mNext; // Next message in a doubly linked list.
|
||||
Message *mPrev; // Previous message in a doubly linked list.
|
||||
void *mQueue; // The queue where message is queued (if any). Queue type from `mInPriorityQ`.
|
||||
RssAverager mRssAverager; // The averager maintaining the received signal strength (RSS) average.
|
||||
LqiAverager mLqiAverager; // The averager maintaining the Link quality indicator (LQI) average.
|
||||
#if OPENTHREAD_FTD
|
||||
ChildMask mChildMask; // ChildMask to indicate which sleepy children need to receive this.
|
||||
#endif
|
||||
@@ -479,7 +481,11 @@ public:
|
||||
*
|
||||
* @returns A reference to the `Instance`.
|
||||
*/
|
||||
Instance &GetInstance(void) const;
|
||||
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||
Instance &GetInstance(void) const { return *GetMetadata().mInstance; }
|
||||
#else
|
||||
Instance &GetInstance(void) const { return GetSingleInstance(); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Frees this message buffer.
|
||||
@@ -1546,9 +1552,6 @@ private:
|
||||
AsConst(this)->GetNextChunk(aLength, static_cast<Chunk &>(aChunk));
|
||||
}
|
||||
|
||||
MessagePool *GetMessagePool(void) const { return GetMetadata().mMessagePool; }
|
||||
void SetMessagePool(MessagePool *aMessagePool) { GetMetadata().mMessagePool = aMessagePool; }
|
||||
|
||||
bool IsInAQueue(void) const { return (GetMetadata().mQueue != nullptr); }
|
||||
void SetMessageQueue(MessageQueue *aMessageQueue);
|
||||
void SetPriorityQueue(PriorityQueue *aPriorityQueue);
|
||||
@@ -1916,8 +1919,6 @@ private:
|
||||
uint16_t mMaxAllocated;
|
||||
};
|
||||
|
||||
inline Instance &Message::GetInstance(void) const { return GetMessagePool()->GetInstance(); }
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user