From bbfe468774adeb8b702f7e878e8de6306a512ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Rymanowski?= Date: Wed, 24 Oct 2018 14:24:52 +0200 Subject: [PATCH] nimble/sched: Add way to remove given type of scheduled element --- .../include/controller/ble_ll_sched.h | 4 ++- nimble/controller/src/ble_ll_sched.c | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/nimble/controller/include/controller/ble_ll_sched.h b/nimble/controller/include/controller/ble_ll_sched.h index 15f750077..6c7d8a07b 100644 --- a/nimble/controller/include/controller/ble_ll_sched.h +++ b/nimble/controller/include/controller/ble_ll_sched.h @@ -82,7 +82,7 @@ extern uint8_t g_ble_ll_sched_offset_ticks; /* Callback function */ struct ble_ll_sched_item; typedef int (*sched_cb_func)(struct ble_ll_sched_item *sch); - +typedef void (*sched_remove_cb_func)(struct ble_ll_sched_item *sch); /* * Strict connection scheduling (for the master) is different than how * connections are normally scheduled. With strict connection scheduling we @@ -143,6 +143,8 @@ int ble_ll_sched_init(void); /* Remove item(s) from schedule */ void ble_ll_sched_rmv_elem(struct ble_ll_sched_item *sch); +void ble_ll_sched_rmv_elem_type(uint8_t type, sched_remove_cb_func remove_cb); + /* Schedule a new master connection */ struct ble_ll_conn_sm; int ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, diff --git a/nimble/controller/src/ble_ll_sched.c b/nimble/controller/src/ble_ll_sched.c index bb2a7f1d5..3e341ff18 100644 --- a/nimble/controller/src/ble_ll_sched.c +++ b/nimble/controller/src/ble_ll_sched.c @@ -1098,6 +1098,37 @@ ble_ll_sched_rmv_elem(struct ble_ll_sched_item *sch) OS_EXIT_CRITICAL(sr); } +void +ble_ll_sched_rmv_elem_type(uint8_t type, sched_remove_cb_func remove_cb) +{ + os_sr_t sr; + struct ble_ll_sched_item *entry; + struct ble_ll_sched_item *first; + + OS_ENTER_CRITICAL(sr); + first = TAILQ_FIRST(&g_ble_ll_sched_q); + + TAILQ_FOREACH(entry, &g_ble_ll_sched_q, link) { + if (entry->sched_type == type) { + if (first == entry) { + os_cputime_timer_stop(&g_ble_ll_sched_timer); + first = NULL; + } + + TAILQ_REMOVE(&g_ble_ll_sched_q, entry, link); + remove_cb(entry); + entry->enqueued = 0; + } + } + + if (!first) { + first = TAILQ_FIRST(&g_ble_ll_sched_q); + os_cputime_timer_start(&g_ble_ll_sched_timer, first->start_time); + } + + OS_EXIT_CRITICAL(sr); +} + /** * Executes a schedule item by calling the schedule callback function. *