Skip to content

Commit ffea311

Browse files
committed
review changes
1 parent 42ff12f commit ffea311

File tree

2 files changed

+12
-53
lines changed

2 files changed

+12
-53
lines changed

config/esp32/args.gni

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ lwip_platform = "external"
2929
chip_inet_config_enable_tcp_endpoint = false
3030
chip_inet_config_enable_udp_endpoint = true
3131

32-
#Use platform memory management
3332
chip_config_memory_management = "platform"
3433

3534
custom_toolchain = "//third_party/connectedhomeip/config/esp32/toolchain:esp32"

src/platform/ESP32/CHIPMem-Platform.cpp

+12-52
Original file line numberDiff line numberDiff line change
@@ -26,106 +26,66 @@
2626
#include <lib/support/CHIPMem.h>
2727
#include <platform/CHIPDeviceLayer.h>
2828

29-
#include <atomic>
30-
#include <cstdio>
31-
#include <cstring>
3229
#include <esp_heap_caps.h>
3330
#include <stdlib.h>
3431

3532
namespace chip {
3633
namespace Platform {
3734

38-
#define VERIFY_INITIALIZED() VerifyInitialized(__func__)
39-
40-
static std::atomic_int memoryInitialized{ 0 };
41-
42-
static void VerifyInitialized(const char * func)
43-
{
44-
if (!memoryInitialized)
45-
{
46-
ChipLogError(DeviceLayer, "ABORT: chip::Platform::%s() called before chip::Platform::MemoryInit()", func);
47-
abort();
48-
}
49-
}
50-
5135
CHIP_ERROR MemoryAllocatorInit(void * buf, size_t bufSize)
5236
{
53-
if (memoryInitialized++ > 0)
54-
{
55-
ChipLogError(DeviceLayer, "ABORT: chip::Platform::MemoryInit() called twice.");
56-
abort();
57-
}
58-
5937
return CHIP_NO_ERROR;
6038
}
6139

62-
void MemoryAllocatorShutdown()
63-
{
64-
if (--memoryInitialized < 0)
65-
{
66-
ChipLogError(DeviceLayer, "ABORT: chip::Platform::MemoryShutdown() called twice.");
67-
abort();
68-
}
69-
}
40+
void MemoryAllocatorShutdown() {}
7041

7142
void * MemoryAlloc(size_t size)
7243
{
73-
void * ptr;
74-
VERIFY_INITIALIZED();
7544
#ifdef CONFIG_CHIP_MEM_ALLOC_MODE_INTERNAL
76-
ptr = heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
45+
return heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
7746
#elif defined(CONFIG_CHIP_MEM_ALLOC_MODE_EXTERNAL)
78-
ptr = heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
47+
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
7948
#else
80-
ptr = malloc(size);
49+
return malloc(size);
8150
#endif
82-
return ptr;
8351
}
8452

8553
void * MemoryAlloc(size_t size, bool isLongTermAlloc)
8654
{
87-
void * ptr;
88-
VERIFY_INITIALIZED();
8955
#ifdef CONFIG_CHIP_MEM_ALLOC_MODE_INTERNAL
90-
ptr = heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
56+
return heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
9157
#elif defined(CONFIG_CHIP_MEM_ALLOC_MODE_EXTERNAL)
92-
ptr = heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
58+
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
9359
#else
94-
ptr = malloc(size);
60+
return malloc(size);
9561
#endif
96-
return ptr;
9762
}
9863

9964
void * MemoryCalloc(size_t num, size_t size)
10065
{
101-
void * ptr;
102-
VERIFY_INITIALIZED();
10366
#ifdef CONFIG_CHIP_MEM_ALLOC_MODE_INTERNAL
104-
ptr = heap_caps_calloc(num, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
67+
return heap_caps_calloc(num, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
10568
#elif defined(CONFIG_CHIP_MEM_ALLOC_MODE_EXTERNAL)
106-
ptr = heap_caps_calloc(num, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
69+
return heap_caps_calloc(num, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
10770
#else
108-
ptr = calloc(num, size);
71+
return calloc(num, size);
10972
#endif
110-
return ptr;
11173
}
11274

11375
void * MemoryRealloc(void * p, size_t size)
11476
{
115-
VERIFY_INITIALIZED();
11677
#ifdef CONFIG_CHIP_MEM_ALLOC_MODE_INTERNAL
11778
p = heap_caps_realloc(p, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
11879
#elif defined(CONFIG_CHIP_MEM_ALLOC_MODE_EXTERNAL)
119-
p = heap_caps_realloc(p, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
80+
p = heap_caps_realloc(p, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
12081
#else
121-
p = realloc(p, size);
82+
p = realloc(p, size);
12283
#endif
12384
return p;
12485
}
12586

12687
void MemoryFree(void * p)
12788
{
128-
VERIFY_INITIALIZED();
12989
#ifdef CONFIG_MATTER_MEM_ALLOC_MODE_DEFAULT
13090
free(p);
13191
#else

0 commit comments

Comments
 (0)