-
Notifications
You must be signed in to change notification settings - Fork 3k
BLE: replace malloc with cordio buffer allocation #8269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -73,8 +73,8 @@ struct SimpleEventQueue : EventQueue { | |||
if (_ble_base == NULL) { | |||
return false; | |||
} | |||
|
|||
EventNode* next = new (std::nothrow) EventNode(event); | |||
uint8_t* event_buf = (uint8_t*)WsfBufAlloc(sizeof(EventNode)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The
NULL
check should be made afterWsfBufAlloc
. - placement new accepts a
void*
. The cast touint8_t
is not required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move SimpleEventQueue
into TARGET_CORDIO
as this is a cordio implementation ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the process of moving the basic event queue implementation, could you change its namespace as well: ble::vendor::cordio
.
@@ -22,7 +22,7 @@ | |||
#include "ble/BLEInstanceBase.h" | |||
#include "ble/generic/GenericGattClient.h" | |||
#include "ble/generic/GenericSecurityManager.h" | |||
#include "ble/pal/SimpleEventQueue.h" | |||
#include "SimpleEventQueue.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not used by nordic. We can remove that include.
@@ -22,7 +22,7 @@ | |||
#include "ble/BLEInstanceBase.h" | |||
#include "ble/generic/GenericGattClient.h" | |||
#include "ble/generic/GenericSecurityManager.h" | |||
#include "ble/pal/SimpleEventQueue.h" | |||
#include "SimpleEventQueue.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not used by nordic. We can remove that include.
@pan- Looks like it's ready for another speed-review. |
is now |
EventNode* next = new (std::nothrow) EventNode(event); | ||
void* event_buf = WsfBufAlloc(sizeof(EventNode)); | ||
if (event_buf == NULL) { | ||
error("\r\n%s:%d Cordio WsfBufAlloc out of memory\r\n", __FILE__, __LINE__); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a leftover for tracing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a unrecoverable error, what do you want to do?
@cmonr looks good now. |
/morph build |
Build : SUCCESSBuild number : 3250 Triggering tests/morph test |
/morph export-build |
Exporter Build : FAILUREBuild number : 2837 |
License issue |
/morph export-build |
Exporter Build : SUCCESSBuild number : 2843 |
Test : SUCCESSBuild number : 3057 |
Description
Event queue used in BLE was using allocating message on the queue from the heap. This causes an error when called from an interrupt context. This replaces the new (which calls malloc) with placement new which uses the provided memory. Memory is provided from a pool belonging to cordio which is where the queue is only used (hence not pulling in any new dependency).
Error discovered using the BLE_GAP example which was used to validate the fix.
Pull request type