Skip to content

Commit

Permalink
sched/notifier: replace the unique key to freerun counter
Browse files Browse the repository at this point in the history
replace the unique key to freerun counter to avoid traverse
of the notifier list.

Signed-off-by: chao.an <anchao@xiaomi.com>
  • Loading branch information
anchao committed Jan 29, 2021
1 parent 0a8dd61 commit 2d711aa
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions sched/wqueue/kwork_notifier.c
Expand Up @@ -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 */
};

/****************************************************************************
Expand All @@ -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
****************************************************************************/
Expand All @@ -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;
Expand All @@ -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 */

Expand All @@ -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;

/* Loop until a unique key is generated. Range 1-INT16_MAX. */
static uint32_t notifier_key;

do
if (++notifier_key == 0)
{
if (g_notifier_key >= INT16_MAX)
{
g_notifier_key = 0;
}

key = (int16_t)++g_notifier_key;
++notifier_key;
}
while (work_notifier_find(key) != NULL);

return key;
return notifier_key;
}

/****************************************************************************
Expand Down

0 comments on commit 2d711aa

Please sign in to comment.