mesh: split mesh_network_run per queue, call as long as work is done

This commit is contained in:
Matthias Ringwald 2019-10-24 17:32:13 +02:00
parent d425804b40
commit 2b13513864

View File

@ -683,12 +683,17 @@ static void process_network_pdu(void){
process_network_pdu_validate();
}
static void mesh_network_run(void){
if (!btstack_linked_list_empty(&network_pdus_outgoing_gatt)){
// returns true if done
static bool mesh_network_run_gatt(void){
if (btstack_linked_list_empty(&network_pdus_outgoing_gatt)){
return true;
}
#ifdef ENABLE_MESH_GATT_BEARER
if (gatt_bearer_network_pdu == NULL){
if (gatt_bearer_network_pdu != NULL){
return true;
}
// move to 'gatt bearer queue'
mesh_network_pdu_t * network_pdu = (mesh_network_pdu_t *) btstack_linked_list_pop(&network_pdus_outgoing_gatt);
@ -720,22 +725,29 @@ static void mesh_network_run(void){
mesh_network_dump_network_pdus("network_pdus_outgoing_adv (1)", &network_pdus_outgoing_adv);
#endif
}
}
#else
// directly move to 'outgoing adv bearer queue'
mesh_network_pdu_t * network_pdu = (mesh_network_pdu_t *) btstack_linked_list_pop(&network_pdus_outgoing_gatt);
btstack_linked_list_add_tail(&network_pdus_outgoing_adv, (btstack_linked_item_t *) network_pdu);
#endif
return false;
}
// returns true if done
static bool mesh_network_run_adv(void){
if (btstack_linked_list_empty(&network_pdus_outgoing_adv)){
return true;
}
if (!btstack_linked_list_empty(&network_pdus_outgoing_adv)){
#ifdef ENABLE_MESH_ADV_BEARER
if (adv_bearer_network_pdu == NULL){
if (adv_bearer_network_pdu != NULL){
return true;
}
// move to 'adv bearer queue'
#ifdef LOG_NETWORK
mesh_network_dump_network_pdus("network_pdus_outgoing_adv (2)", &network_pdus_outgoing_adv);
#endif
mesh_network_pdu_t * network_pdu = (mesh_network_pdu_t *) btstack_linked_list_pop(&network_pdus_outgoing_adv);
#ifdef LOG_NETWORK
printf("network run 4: pop %p from network_pdus_outgoing_adv\n", network_pdu);
mesh_network_dump_network_pdus("network_pdus_outgoing_adv (3)", &network_pdus_outgoing_adv);
@ -763,39 +775,64 @@ static void mesh_network_run(void){
// directly notify upper layer
mesh_network_send_complete(network_pdu);
}
}
#else
// done
mesh_network_pdu_t * network_pdu = (mesh_network_pdu_t *) btstack_linked_list_pop(&network_pdus_outgoing_adv);
// directly notify upper layer
mesh_network_send_complete(network_pdu);
#endif
return false;
}
if (mesh_crypto_active) return;
// returns true if done
static bool mesh_network_run_received(void){
if (mesh_crypto_active) {
return true;
}
if (btstack_linked_list_empty(&network_pdus_received)) {
return true;
}
if (!btstack_linked_list_empty(&network_pdus_received)){
incoming_pdu_decoded = mesh_network_pdu_get();
if (!incoming_pdu_decoded) return;
if (incoming_pdu_decoded == NULL) return true;
// get encoded network pdu and start processing
mesh_crypto_active = 1;
incoming_pdu_raw = (mesh_network_pdu_t *) btstack_linked_list_pop(&network_pdus_received);
process_network_pdu();
return;
return true;
}
// returns true if done
static bool mesh_network_run_queued(void){
if (mesh_crypto_active) {
return true;
}
if (btstack_linked_list_empty(&network_pdus_queued)){
return true;
}
if (!btstack_linked_list_empty(&network_pdus_queued)){
// get queued network pdu and start processing
#ifdef LOG_NETWORK
mesh_network_dump_network_pdus("network_pdus_queued (1)", &network_pdus_queued);
#endif
outgoing_pdu = (mesh_network_pdu_t *) btstack_linked_list_pop(&network_pdus_queued);
#ifdef LOG_NETWORK
printf("network run 5: pop %p from network_pdus_queued\n", outgoing_pdu);
mesh_network_dump_network_pdus("network_pdus_queued (2)", &network_pdus_queued);
#endif
mesh_network_send_a();
return;
return true;
}
static void mesh_network_run(void){
while (true){
bool done = true;
done &= mesh_network_run_gatt();
done &= mesh_network_run_adv();
done &= mesh_network_run_received();
done &= mesh_network_run_queued();
if (done) break;
}
}