added sm_lookup_entry_t to memory pools

This commit is contained in:
Matthias Ringwald 2015-08-04 13:59:06 +02:00
parent d3862db066
commit cf49570bee
9 changed files with 49 additions and 5 deletions

View File

@ -33,6 +33,6 @@
#define MAX_ATT_DB_SIZE 200 #define MAX_ATT_DB_SIZE 200
#define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_HFP_CONNECTIONS 0
#define MAX_NO_WHITELIST_ENTRIES 1 #define MAX_NO_WHITELIST_ENTRIES 1
#define MAX_NO_SM_LOOKUP_ENTRIES 3
#endif #endif

View File

@ -36,6 +36,7 @@
#define MAX_NO_DB_MEM_SERVICES 1 #define MAX_NO_DB_MEM_SERVICES 1
#define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_HFP_CONNECTIONS 0
#define MAX_NO_WHITELIST_ENTRIES 1 #define MAX_NO_WHITELIST_ENTRIES 1
#define MAX_NO_SM_LOOKUP_ENTRIES 3
#endif #endif

View File

@ -36,6 +36,7 @@
#define MAX_NO_DB_MEM_SERVICES 1 #define MAX_NO_DB_MEM_SERVICES 1
#define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_HFP_CONNECTIONS 0
#define MAX_NO_WHITELIST_ENTRIES 1 #define MAX_NO_WHITELIST_ENTRIES 1
#define MAX_NO_SM_LOOKUP_ENTRIES 3
#endif #endif

View File

@ -36,6 +36,7 @@
#define MAX_NO_DB_MEM_SERVICES 1 #define MAX_NO_DB_MEM_SERVICES 1
#define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_HFP_CONNECTIONS 0
#define MAX_NO_WHITELIST_ENTRIES 1 #define MAX_NO_WHITELIST_ENTRIES 1
#define MAX_NO_SM_LOOKUP_ENTRIES 3
#endif #endif

View File

@ -33,5 +33,6 @@
#define MAX_NO_BNEP_CHANNELS 0 #define MAX_NO_BNEP_CHANNELS 0
#define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_HFP_CONNECTIONS 0
#define MAX_NO_WHITELIST_ENTRIES 1 #define MAX_NO_WHITELIST_ENTRIES 1
#define MAX_NO_SM_LOOKUP_ENTRIES 3
#endif #endif

View File

@ -33,5 +33,6 @@
#define MAX_NO_BNEP_CHANNELS 0 #define MAX_NO_BNEP_CHANNELS 0
#define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_HFP_CONNECTIONS 0
#define MAX_NO_WHITELIST_ENTRIES 1 #define MAX_NO_WHITELIST_ENTRIES 1
#define MAX_NO_SM_LOOKUP_ENTRIES 3
#endif #endif

View File

@ -539,6 +539,38 @@ void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
#endif #endif
// MARK: sm_lookup_entry_t
#ifdef MAX_NO_SM_LOOKUP_ENTRIES
#if MAX_NO_SM_LOOKUP_ENTRIES > 0
static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NO_SM_LOOKUP_ENTRIES];
static memory_pool_t sm_lookup_entry_pool;
sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
return (sm_lookup_entry_t *) memory_pool_get(&sm_lookup_entry_pool);
}
void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
}
#else
sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
return NULL;
}
void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
// silence compiler warning about unused parameter in a portable way
(void) sm_lookup_entry;
};
#endif
#elif defined(HAVE_MALLOC)
sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t));
}
void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
free(sm_lookup_entry);
}
#else
#error "Neither HAVE_MALLOC nor MAX_NO_SM_LOOKUP_ENTRIES for struct sm_lookup_entry is defined. Please, edit the config file."
#endif
#endif #endif
// init // init
void btstack_memory_init(void){ void btstack_memory_init(void){
@ -588,5 +620,8 @@ void btstack_memory_init(void){
#if MAX_NO_WHITELIST_ENTRIES > 0 #if MAX_NO_WHITELIST_ENTRIES > 0
memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NO_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NO_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
#endif #endif
#if MAX_NO_SM_LOOKUP_ENTRIES > 0
memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NO_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
#endif
#endif #endif
} }

View File

@ -38,7 +38,7 @@
/* /*
* btstsack_memory.h * btstack_memory.h
* *
* @brief BTstack memory management via configurable memory pools * @brief BTstack memory management via configurable memory pools
* *
@ -62,6 +62,7 @@ extern "C" {
#ifdef HAVE_BLE #ifdef HAVE_BLE
#include "gatt_client.h" #include "gatt_client.h"
#include "sm.h"
#endif #endif
/* API_START */ /* API_START */
@ -110,13 +111,15 @@ hfp_connection_t * btstack_memory_hfp_connection_get(void);
void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection); void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection);
#ifdef HAVE_BLE #ifdef HAVE_BLE
// gatt_client, gatt_subclient, whitelist_entry // gatt_client, gatt_subclient, whitelist_entry, sm_lookup_entry
gatt_client_t * btstack_memory_gatt_client_get(void); gatt_client_t * btstack_memory_gatt_client_get(void);
void btstack_memory_gatt_client_free(gatt_client_t *gatt_client); void btstack_memory_gatt_client_free(gatt_client_t *gatt_client);
gatt_subclient_t * btstack_memory_gatt_subclient_get(void); gatt_subclient_t * btstack_memory_gatt_subclient_get(void);
void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient); void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient);
whitelist_entry_t * btstack_memory_whitelist_entry_get(void); whitelist_entry_t * btstack_memory_whitelist_entry_get(void);
void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry); void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry);
sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void);
void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry);
#endif #endif
#if defined __cplusplus #if defined __cplusplus

View File

@ -41,7 +41,7 @@ copyright = """/*
hfile_header_begin = """ hfile_header_begin = """
/* /*
* btstsack_memory.h * btstack_memory.h
* *
* @brief BTstack memory management via configurable memory pools * @brief BTstack memory management via configurable memory pools
* *
@ -65,6 +65,7 @@ extern "C" {
#ifdef HAVE_BLE #ifdef HAVE_BLE
#include "gatt_client.h" #include "gatt_client.h"
#include "sm.h"
#endif #endif
/* API_START */ /* API_START */
@ -156,7 +157,7 @@ def replacePlaceholder(template, struct_name):
return snippet return snippet
list_of_structs = [ ["hci_connection"], ["l2cap_service", "l2cap_channel"], ["rfcomm_multiplexer", "rfcomm_service", "rfcomm_channel"], ["db_mem_device_name", "db_mem_device_link_key", "db_mem_service"], ["bnep_service", "bnep_channel"], ["hfp_connection"]] list_of_structs = [ ["hci_connection"], ["l2cap_service", "l2cap_channel"], ["rfcomm_multiplexer", "rfcomm_service", "rfcomm_channel"], ["db_mem_device_name", "db_mem_device_link_key", "db_mem_service"], ["bnep_service", "bnep_channel"], ["hfp_connection"]]
list_of_le_structs = [["gatt_client", "gatt_subclient","whitelist_entry"]] list_of_le_structs = [["gatt_client", "gatt_subclient", "whitelist_entry", "sm_lookup_entry"]]
file_name = "../src/btstack_memory" file_name = "../src/btstack_memory"