mirror of
https://github.com/espressif/openthread.git
synced 2026-09-23 09:27:40 +00:00
[heap] move static heap construction to singleton accessor (#8242)
Move static heap construction to singleton accessor to avoid non-trivial construction at global scope, which has an unpredictable ordering.
This commit is contained in:
@@ -50,7 +50,8 @@ OT_DEFINE_ALIGNED_VAR(gInstanceRaw, sizeof(Instance), uint64_t);
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
#if !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
Utils::Heap Instance::sHeap;
|
||||
OT_DEFINE_ALIGNED_VAR(sHeapRaw, sizeof(Utils::Heap), uint64_t);
|
||||
Utils::Heap *Instance::sHeap{nullptr};
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
bool Instance::sDnsNameCompressionEnabled = true;
|
||||
@@ -240,6 +241,18 @@ Instance::Instance(void)
|
||||
{
|
||||
}
|
||||
|
||||
#if (OPENTHREAD_MTD || OPENTHREAD_FTD) && !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
Utils::Heap &Instance::GetHeap(void)
|
||||
{
|
||||
if (nullptr == sHeap)
|
||||
{
|
||||
sHeap = new (&sHeapRaw) Utils::Heap();
|
||||
}
|
||||
|
||||
return *sHeap;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||
|
||||
Instance &Instance::InitSingle(void)
|
||||
|
||||
@@ -290,7 +290,7 @@ public:
|
||||
* @returns A reference to the Heap object.
|
||||
*
|
||||
*/
|
||||
static Utils::Heap &GetHeap(void) { return sHeap; }
|
||||
static Utils::Heap &GetHeap(void);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_API_ENABLE
|
||||
@@ -381,7 +381,7 @@ private:
|
||||
// Random::Manager is initialized before other objects. Note that it
|
||||
// requires MbedTls which itself may use Heap.
|
||||
#if !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
static Utils::Heap sHeap;
|
||||
static Utils::Heap *sHeap;
|
||||
#endif
|
||||
Crypto::MbedTls mMbedTls;
|
||||
#endif // OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
|
||||
Reference in New Issue
Block a user