|
31 | 31 |
|
32 | 32 | #define TRACE_GROUP "mClt"
|
33 | 33 |
|
| 34 | +#ifdef MBED_CONF_MBED_CLIENT_EVENT_LOOP_SIZE |
| 35 | +#define MBED_CLIENT_EVENT_LOOP_SIZE MBED_CONF_MBED_CLIENT_EVENT_LOOP_SIZE |
| 36 | +#else |
| 37 | +#define MBED_CLIENT_EVENT_LOOP_SIZE 1024 |
| 38 | +#endif |
| 39 | + |
34 | 40 | int8_t M2MConnectionHandlerPimpl::_tasklet_id = -1;
|
35 | 41 |
|
| 42 | +static MemoryPool<M2MConnectionHandlerPimpl::TaskIdentifier, MBED_CLIENT_EVENT_LOOP_SIZE/64> memory_pool; |
| 43 | + |
36 | 44 | extern "C" void connection_tasklet_event_handler(arm_event_s *event)
|
37 | 45 | {
|
38 | 46 | tr_debug("M2MConnectionHandlerPimpl::connection_tasklet_event_handler");
|
@@ -74,7 +82,7 @@ extern "C" void connection_tasklet_event_handler(arm_event_s *event)
|
74 | 82 | break;
|
75 | 83 | }
|
76 | 84 | if (task_id) {
|
77 |
| - free(task_id); |
| 85 | + memory_pool.free(task_id); |
78 | 86 | }
|
79 | 87 | }
|
80 | 88 |
|
@@ -145,7 +153,7 @@ bool M2MConnectionHandlerPimpl::resolve_server_address(const String& server_addr
|
145 | 153 | _server_port = server_port;
|
146 | 154 | _server_type = server_type;
|
147 | 155 | _server_address = server_address;
|
148 |
| - TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier)); |
| 156 | + TaskIdentifier* task = memory_pool.alloc(); |
149 | 157 | if (!task) {
|
150 | 158 | return false;
|
151 | 159 | }
|
@@ -248,7 +256,7 @@ bool M2MConnectionHandlerPimpl::send_data(uint8_t *data,
|
248 | 256 | return false;
|
249 | 257 | }
|
250 | 258 |
|
251 |
| - TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier)); |
| 259 | + TaskIdentifier* task = memory_pool.alloc(); |
252 | 260 | if (!task) {
|
253 | 261 | free(buffer);
|
254 | 262 | return false;
|
@@ -310,9 +318,7 @@ int8_t M2MConnectionHandlerPimpl::connection_tasklet_handler()
|
310 | 318 |
|
311 | 319 | void M2MConnectionHandlerPimpl::socket_event()
|
312 | 320 | {
|
313 |
| - tr_debug("M2MConnectionHandlerPimpl::socket_event()"); |
314 |
| - |
315 |
| - TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier)); |
| 321 | + TaskIdentifier* task = memory_pool.alloc(); |
316 | 322 | if (!task) {
|
317 | 323 | _observer.socket_error(M2MConnectionHandler::SOCKET_READ_ERROR, true);
|
318 | 324 | return;
|
|
0 commit comments