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 <anchao@xiaomi.com>
This commit is contained in:
chao.an 2021-01-29 17:23:43 +08:00 committed by David Sidrane
parent 003b360d12
commit 5cf794e42b

View File

@ -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();