[heap] export heap API (#4143)

This commit is contained in:
Kamil Sroka
2019-10-24 22:28:51 -07:00
committed by Jonathan Hui
parent c3ca842658
commit 7fddb6c9db
4 changed files with 50 additions and 1 deletions
+8
View File
@@ -72,6 +72,14 @@ typedef void *(*otHeapCAllocFn)(size_t aCount, size_t aSize);
*/
typedef void (*otHeapFreeFn)(void *aPointer);
// This is a temporary API and would be removed after moving heap to platform.
// TODO: Remove after moving heap to platform.
void *otHeapCAlloc(size_t aCount, size_t aSize);
// This is a temporary API and would be removed after moving heap to platform.
// TODO: Remove after moving heap to platform.
void otHeapFree(void *aPointer);
/**
* This function sets the external heap CAlloc and Free
* functions to be used by the OpenThread stack.
+1
View File
@@ -241,6 +241,7 @@ EXTRA_DIST = \
libopenthread_radio_a_SOURCES = \
api/diags_api.cpp \
api/heap_api.cpp \
api/instance_api.cpp \
api/link_raw_api.cpp \
api/logging_api.cpp \
+40 -1
View File
@@ -37,7 +37,46 @@
#include "common/instance.hpp"
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE || OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
#if OPENTHREAD_RADIO
void *otHeapCAlloc(size_t aCount, size_t aSize)
{
OT_UNUSED_VARIABLE(aCount);
OT_UNUSED_VARIABLE(aSize);
// Should never get called!
assert(false);
return NULL;
}
void otHeapFree(void *aPointer)
{
OT_UNUSED_VARIABLE(aPointer);
// Should never get called!
assert(false);
}
#else // OPENTHREAD_RADIO
void *otHeapCAlloc(size_t aCount, size_t aSize)
{
return ot::Instance::Get().HeapCAlloc(aCount, aSize);
}
void otHeapFree(void *aPointer)
{
ot::Instance::Get().HeapFree(aPointer);
}
#endif // OPENTHREAD_RADIO
#endif // !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE || OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE && !OPENTHREAD_RADIO
void otHeapSetCAllocFree(otHeapCAllocFn aCAlloc, otHeapFreeFn aFree)
{
ot::Instance::HeapSetCAllocFree(aCAlloc, aFree);
+1
View File
@@ -272,6 +272,7 @@ public:
#elif !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
void HeapFree(void *aPointer) { mHeap.Free(aPointer); }
void *HeapCAlloc(size_t aCount, size_t aSize) { return mHeap.CAlloc(aCount, aSize); }
/**
* This method returns a reference to the Heap object.
*