From 5cf794e42b9d6777ce96a264e2c98c6967a3d479 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Fri, 29 Jan 2021 17:23:43 +0800 Subject: [PATCH] sched/notifier: replace the unique key to freerun counter replace the unique key to freerun counter to avoid traverse of the notifier list. Signed-off-by: chao.an --- sched/wqueue/kwork_notifier.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/sched/wqueue/kwork_notifier.c b/sched/wqueue/kwork_notifier.c index 27e1b0396c..012e3bbe0f 100644 --- a/sched/wqueue/kwork_notifier.c +++ b/sched/wqueue/kwork_notifier.c @@ -65,7 +65,7 @@ struct work_notifier_entry_s /* Additional payload needed to manage the notification */ - int16_t key; /* Unique ID for the notification */ + uint32_t key; /* Unique ID for the notification */ }; /**************************************************************************** @@ -86,10 +86,6 @@ static dq_queue_t g_notifier_free; static dq_queue_t g_notifier_pending; -/* Used for lookup key generation */ - -static uint16_t g_notifier_key; - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -103,7 +99,7 @@ static uint16_t g_notifier_key; * ****************************************************************************/ -static FAR struct work_notifier_entry_s *work_notifier_find(int16_t key) +static FAR struct work_notifier_entry_s *work_notifier_find(uint32_t key) { FAR struct work_notifier_entry_s *notifier; FAR dq_entry_t *entry; @@ -118,7 +114,7 @@ static FAR struct work_notifier_entry_s *work_notifier_find(int16_t key) /* Is this the one we were looking for? */ - if (notifier->key == key) + if (notifier->key == key) { /* Yes.. return a reference to it */ @@ -137,24 +133,16 @@ static FAR struct work_notifier_entry_s *work_notifier_find(int16_t key) * ****************************************************************************/ -static int16_t work_notifier_key(void) +static uint32_t work_notifier_key(void) { - int16_t key; + static uint32_t notifier_key; - /* Loop until a unique key is generated. Range 1-INT16_MAX. */ - - do + if (++notifier_key == 0) { - if (g_notifier_key >= INT16_MAX) - { - g_notifier_key = 0; - } - - key = (int16_t)++g_notifier_key; + notifier_key = 1; } - while (work_notifier_find(key) != NULL); - return key; + return notifier_key; } /**************************************************************************** @@ -300,8 +288,6 @@ int work_notifier_teardown(int key) irqstate_t flags; int ret = OK; - DEBUGASSERT(key > 0 && key <= INT16_MAX); - /* Disable interrupts very briefly. */ flags = enter_critical_section();