Merge pull request #8269 from paul-szczepanek-arm/fix-event-malloc

BLE: replace malloc with cordio buffer allocation
pull/8337/head
Martin Kojtal 2018-10-06 07:44:39 +02:00 committed by GitHub
commit 5faac0e4ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 14 deletions

View File

@ -30,7 +30,7 @@
#include "CordioPalGenericAccessService.h"
#include "ble/generic/GenericGap.h"
#include "ble/generic/GenericSecurityManager.h"
#include "ble/pal/SimpleEventQueue.h"
#include "SimpleEventQueue.h"
namespace ble {
namespace vendor {
@ -152,7 +152,7 @@ private:
} initialization_status;
::BLE::InstanceID_t instanceID;
mutable pal::SimpleEventQueue _event_queue;
mutable SimpleEventQueue _event_queue;
class SigningEventMonitorProxy : public pal::SigningEventMonitor {
public:

View File

@ -23,12 +23,13 @@
#include "ble/BLE.h"
namespace ble {
namespace pal {
namespace vendor {
namespace cordio {
/**
* Simple implementation of the pal::EventQueue.
*/
struct SimpleEventQueue : EventQueue {
struct SimpleEventQueue : pal::EventQueue {
typedef mbed::Callback<void()> event_t;
@ -51,7 +52,7 @@ struct SimpleEventQueue : EventQueue {
*
* @param ble_id Id of the BLE instance using that event queue.
*/
void initialize(BLEInstanceBase* ble_base, BLE::InstanceID_t ble_id)
void initialize(BLEInstanceBase* ble_base, ::BLE::InstanceID_t ble_id)
{
_ble_base = ble_base;
_ble_instance_id = ble_id;
@ -73,8 +74,12 @@ struct SimpleEventQueue : EventQueue {
if (_ble_base == NULL) {
return false;
}
EventNode* next = new (std::nothrow) EventNode(event);
void* event_buf = WsfBufAlloc(sizeof(EventNode));
MBED_ASSERT(event_buf != NULL);
if (event_buf == NULL) {
return false;
}
EventNode* next = new(event_buf) EventNode(event);
if (next == NULL) {
return false;
}
@ -102,7 +107,8 @@ struct SimpleEventQueue : EventQueue {
{
while (_events) {
EventNode* next = _events->next;
delete _events;
_events->~EventNode();
WsfBufFree(_events);
_events = next;
}
}
@ -115,7 +121,8 @@ struct SimpleEventQueue : EventQueue {
while (_events) {
EventNode* next = _events->next;
_events->event();
delete _events;
_events->~EventNode();
WsfBufFree(_events);
_events = next;
}
}
@ -133,11 +140,12 @@ private:
}
BLEInstanceBase* _ble_base;
BLE::InstanceID_t _ble_instance_id;
::BLE::InstanceID_t _ble_instance_id;
EventNode* _events;
};
} // namespace pal
} // namespace cordio
} // namespace vendor
} // namespace ble
#endif /* BLE_PAL_SIMPLE_EVENT_QUEUE_H_ */

View File

@ -22,10 +22,8 @@
#include "ble/BLEInstanceBase.h"
#include "ble/generic/GenericGattClient.h"
#include "ble/generic/GenericSecurityManager.h"
#include "ble/pal/SimpleEventQueue.h"
#include "nRF5xPalSecurityManager.h"
#include "nRF5xGap.h"
#include "nRF5xGattServer.h"

View File

@ -22,7 +22,6 @@
#include "ble/BLEInstanceBase.h"
#include "ble/generic/GenericGattClient.h"
#include "ble/generic/GenericSecurityManager.h"
#include "ble/pal/SimpleEventQueue.h"
#include "nRF5xPalSecurityManager.h"
#include "nRF5xGap.h"