// init void btstack_memory_init(void){ #ifdef MAX_NO_HCI_CONNECTIONS memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t)); #endif #ifdef MAX_NO_L2CAP_SERVICES memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t)); #endif #ifdef MAX_NO_L2CAP_CHANNELS memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); #endif #ifdef MAX_NO_RFCOMM_MULTIPLEXERS memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); #endif #ifdef MAX_NO_RFCOMM_SERVICES memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); #endif #ifdef MAX_NO_RFCOMM_CHANNELS memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); #endif #ifdef MAX_NO_DB_MEM_DEVICE_NAMES memory_pool_create(&db_mem_device_name_pool, db_mem_device_name_storage, MAX_NO_DB_MEM_DEVICE_NAMES, sizeof(db_mem_device_name_t)); #endif #ifdef MAX_NO_DB_MEM_DEVICE_LINK_KEYS memory_pool_create(&db_mem_device_link_key_pool, db_mem_device_link_key_storage, MAX_NO_DB_MEM_DEVICE_LINK_KEYS, sizeof(db_mem_device_link_key_t)); #endif #ifdef MAX_NO_DB_MEM_SERVICES memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t)); #endif }
TEST(MemoryPoolTest, CreateRelease) { status_t err = NO_ERROR; memory_pool_handle_t pool = NULL; err = memory_pool_create( 32, 16, 32, 1024 * 1024, 1000, &pool); ASSERT_EQ(NO_ERROR, err); ASSERT_TRUE(NULL != pool); err = memory_pool_release(pool); ASSERT_EQ(NO_ERROR, err); }
TEST(MemoryPoolTest, ClaimUnclaim) { status_t err = NO_ERROR; memory_pool_handle_t pool = NULL; size_t counter = 0; void* data = NULL; void* first_data = NULL; err = memory_pool_create( 1024, 24, 32, 256 * 1024, 10, &pool); ASSERT_EQ(NO_ERROR, err); ASSERT_TRUE(NULL != pool); while (NO_ERROR == err) { err = memory_pool_claim(pool, &data); ASSERT_TRUE(NULL != data); if (NULL == first_data) { first_data = data; } counter++; usleep(100); } ASSERT_NE(NO_ERROR, err); ASSERT_EQ(counter, (size_t)257); err = memory_pool_unclaim(pool, first_data); ASSERT_EQ(NO_ERROR, err); data = NULL; err = memory_pool_claim(pool, &data); ASSERT_EQ(NO_ERROR, err); ASSERT_TRUE(NULL != data); EXPECT_TRUE(data == first_data); err = memory_pool_release(pool); ASSERT_EQ(NO_ERROR, err); }
static void do_runtime_init(void) { static struct runtime_t rt; /* Set default runtime to current */ __current_runtime = &rt; /* Initial the default runtime */ memset(&rt, 0, sizeof(struct runtime_t)); rt.__pool = memory_pool_create((void *)heap, sizeof(heap)); rt.__errno = 0; rt.__seed[0] = 1; rt.__seed[1] = 1; rt.__seed[2] = 1; rt.__environ.content = ""; rt.__environ.next = &(rt.__environ); rt.__environ.prev = &(rt.__environ); }
// init void le_btstack_memory_init(void){ #if MAX_NO_HCI_CONNECTIONS > 0 memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t)); #endif #if MAX_NO_L2CAP_SERVICES > 0 memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t)); #endif #if MAX_NO_L2CAP_CHANNELS > 0 memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); #endif #if MAX_NO_GATT_CLIENTS > 0 memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NO_GATT_CLIENTS, sizeof(gatt_client_t)); #endif #if MAX_NO_GATT_SUBCLIENTS > 0 memory_pool_create(&gatt_subclient_pool, gatt_subclient_storage, MAX_NO_GATT_SUBCLIENTS, sizeof(gatt_subclient_t)); #endif #if MAX_NO_WHITELIST_ENTRIES > 0 memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NO_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); #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 }