2018-09-09 16:32:37 +02:00
|
|
|
/****************************************************************************
|
2018-09-09 23:01:44 +02:00
|
|
|
* sched/wqueue/kwork_notifier.c
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
2018-09-09 23:01:44 +02:00
|
|
|
#include <string.h>
|
2018-09-09 16:32:37 +02:00
|
|
|
#include <sched.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
2018-09-09 16:32:37 +02:00
|
|
|
#include <nuttx/semaphore.h>
|
2018-09-09 23:01:44 +02:00
|
|
|
#include <nuttx/wqueue.h>
|
2018-09-09 16:32:37 +02:00
|
|
|
|
|
|
|
#include "signal/signal.h"
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
#ifdef CONFIG_WQUEUE_NOTIFIER
|
2018-09-09 16:32:37 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
/* The full allocated notification will hold additional information. The
|
|
|
|
* allocated notification information persist until the work is executed
|
|
|
|
* and must be freed using kmm_free() by the work.
|
|
|
|
*/
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
struct work_notifier_alloc_s
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
struct work_notifier_s info; /* The notification info */
|
|
|
|
struct work_s work; /* Used for scheduling the work */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This structure describes one notification list entry */
|
|
|
|
|
|
|
|
struct work_notifier_entry_s
|
|
|
|
{
|
|
|
|
FAR struct work_notifier_entry_s *flink;
|
|
|
|
FAR struct work_notifier_alloc_s *alloc; /* Allocated notification info copy */
|
|
|
|
int16_t key; /* Unique ID for the notification */
|
2018-09-09 16:32:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This is a statically allocated pool of notification structures */
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
static struct work_notifier_entry_s
|
|
|
|
g_notifier_pool[CONFIG_WQUEUE_NOTIFIER_NWAITERS];
|
2018-09-09 16:32:37 +02:00
|
|
|
|
|
|
|
/* This is a list of free notification structures */
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
static FAR struct work_notifier_entry_s *g_notifier_free;
|
2018-09-09 16:32:37 +02:00
|
|
|
|
|
|
|
/* This is a singly linked list of pending notifications. When an event
|
|
|
|
* occurs available, *all* of the waiters for that event in this list will
|
|
|
|
* be signaled and the entry will be freed. If there are multiple waiters
|
|
|
|
* for some resource, then only the highest priority thread will get the
|
2018-09-09 23:01:44 +02:00
|
|
|
* resource. Lower priority threads will need to call work_notifier_setup()
|
2018-09-09 16:32:37 +02:00
|
|
|
* once again.
|
|
|
|
*/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
static FAR struct work_notifier_entry_s *g_notifier_pending;
|
2018-09-09 16:32:37 +02:00
|
|
|
|
|
|
|
/* This semaphore is used as mutex to enforce mutually exclusive access to
|
|
|
|
* the notification data structures.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static sem_t g_notifier_sem;
|
|
|
|
|
|
|
|
/* Used for lookup key generation */
|
|
|
|
|
|
|
|
static uint16_t g_notifier_key;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-09-09 23:01:44 +02:00
|
|
|
* Name: work_notifier_alloc
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Allocate a notification structure by removing it from the free list.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
static FAR struct work_notifier_entry_s *work_notifier_alloc(void)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
FAR struct work_notifier_entry_s *notifier;
|
2018-09-09 16:32:37 +02:00
|
|
|
|
|
|
|
notifier = g_notifier_free;
|
|
|
|
if (notifier != NULL)
|
|
|
|
{
|
|
|
|
g_notifier_free = notifier->flink;
|
|
|
|
notifier->flink = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return notifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-09-09 23:01:44 +02:00
|
|
|
* Name: work_notifier_free
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Free a notification structure by returning it to the head of the free
|
|
|
|
* list.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
static inline void
|
|
|
|
work_notifier_free(FAR struct work_notifier_entry_s *notifier)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
|
|
|
notifier->flink = g_notifier_free;
|
|
|
|
g_notifier_free = notifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-09-09 23:01:44 +02:00
|
|
|
* Name: work_notifier_find
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Given a unique key for notification, find the corresponding notification
|
|
|
|
* structure in the pending notification list.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
static FAR struct work_notifier_entry_s *
|
|
|
|
work_notifier_find(int16_t key, FAR struct work_notifier_entry_s **pprev)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
FAR struct work_notifier_entry_s *notifier;
|
|
|
|
FAR struct work_notifier_entry_s *prev;
|
2018-09-09 16:32:37 +02:00
|
|
|
|
|
|
|
/* Find the entry matching this key in the g_notifier_pending list. */
|
|
|
|
|
|
|
|
for (prev = NULL, notifier = g_notifier_pending;
|
|
|
|
notifier != NULL;
|
|
|
|
prev = notifier, notifier = notifier->flink)
|
|
|
|
{
|
|
|
|
/* Is this the one we were looking for? */
|
|
|
|
|
|
|
|
if (notifier->key == key)
|
|
|
|
{
|
|
|
|
/* Return the previous entry if so requested */
|
|
|
|
|
|
|
|
if (pprev != NULL)
|
|
|
|
{
|
|
|
|
*pprev = prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
return notifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-09-09 23:01:44 +02:00
|
|
|
* Name: work_notifier_key
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Generate a unique key for this notification.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
static int16_t work_notifier_key(void)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
|
|
|
int16_t key;
|
|
|
|
|
|
|
|
/* Loop until a unique key is generated */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (g_notifier_key >= INT16_MAX)
|
|
|
|
{
|
|
|
|
g_notifier_key = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = (int16_t)++g_notifier_key;
|
|
|
|
}
|
2018-09-09 23:01:44 +02:00
|
|
|
while (work_notifier_find(key, NULL) != NULL);
|
2018-09-09 16:32:37 +02:00
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-09-09 23:01:44 +02:00
|
|
|
* Name: work_notifier_initialize
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-09-09 23:01:44 +02:00
|
|
|
* Set up the notification data structures for normal operation.
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
void work_notifier_initialize(void)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Add each notification structure to the free list */
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
for (i = 0; i < CONFIG_WQUEUE_NOTIFIER_NWAITERS; i++)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
FAR struct work_notifier_entry_s *notifier = &g_notifier_pool[i];
|
2018-09-09 16:32:37 +02:00
|
|
|
|
|
|
|
/* Add the pre-allocated notification to the head of the free list */
|
|
|
|
|
|
|
|
notifier->flink = g_notifier_free;
|
|
|
|
g_notifier_free = notifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the semaphore that enforces mutually exclusive access to the
|
|
|
|
* notification data structures.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nxsem_init(&g_notifier_sem, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-09-09 23:01:44 +02:00
|
|
|
* Name: work_notifier_setup
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-09-09 23:01:44 +02:00
|
|
|
* Set up to provide a notification when event is signaled.
|
2018-09-09 19:57:25 +02:00
|
|
|
*
|
2018-09-09 16:32:37 +02:00
|
|
|
* Input Parameters:
|
2018-09-09 23:01:44 +02:00
|
|
|
* info - Describes the work notification.
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* > 0 - The key which may be used later in a call to
|
2018-09-09 23:01:44 +02:00
|
|
|
* work_notifier_teardown().
|
2018-09-09 16:32:37 +02:00
|
|
|
* == 0 - Not used (reserved for wrapper functions).
|
|
|
|
* < 0 - An unexpected error occurred and no signal will be sent. The
|
|
|
|
* returned value is a negated errno value that indicates the
|
|
|
|
* nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
int work_notifier_setup(FAR struct work_notifier_s *info)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Get exclusive access to the notifier data structures */
|
|
|
|
|
|
|
|
ret = nxsem_wait(&g_notifier_sem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a new notification */
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
FAR struct work_notifier_entry_s *notifier = work_notifier_alloc();
|
2018-09-09 16:32:37 +02:00
|
|
|
if (notifier == NULL)
|
|
|
|
{
|
|
|
|
ret = -ENOSPC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
FAR struct work_notifier_alloc_s *alloc;
|
|
|
|
int16_t key;
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
/* Duplicate the notification info */
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
alloc = kmm_malloc(sizeof(struct work_notifier_alloc_s));
|
|
|
|
if (alloc == NULL)
|
|
|
|
{
|
|
|
|
work_notifier_free(notifier);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
memcpy(&alloc->info, info, sizeof(struct work_notifier_s));
|
|
|
|
|
|
|
|
/* Generate a unique key for this notification */
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
key = work_notifier_key();
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
/* Add the notification to the head of the pending list */
|
|
|
|
|
|
|
|
notifier->flink = g_notifier_pending;
|
|
|
|
notifier->alloc = alloc;
|
|
|
|
notifier->key = key;
|
|
|
|
|
|
|
|
g_notifier_pending = notifier;
|
|
|
|
ret = key;
|
2018-09-09 16:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
(void)nxsem_post(&g_notifier_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-09-09 23:01:44 +02:00
|
|
|
* Name: work_notifier_teardown
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-09-09 23:01:44 +02:00
|
|
|
* Eliminate a notification previously setup by work_notifier_setup().
|
2018-09-09 16:32:37 +02:00
|
|
|
* This function should only be called if the notification should be
|
|
|
|
* aborted prior to the notification. The notification will automatically
|
|
|
|
* be torn down after the signal is sent.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* key - The key value returned from a previous call to
|
2018-09-09 23:01:44 +02:00
|
|
|
* work_notifier_setup().
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
int work_notifier_teardown(int key)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
FAR struct work_notifier_entry_s *notifier;
|
|
|
|
FAR struct work_notifier_entry_s *prev;
|
2018-09-09 16:32:37 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Get exclusive access to the notifier data structures */
|
|
|
|
|
|
|
|
ret = nxsem_wait(&g_notifier_sem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the entry matching this PID in the g_notifier_pending list. We
|
|
|
|
* assume that there is only one.
|
|
|
|
*/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
notifier = work_notifier_find(key, &prev);
|
2018-09-09 16:32:37 +02:00
|
|
|
if (notifier == NULL)
|
|
|
|
{
|
|
|
|
/* There is no notification with this key in the pending list */
|
|
|
|
|
|
|
|
ret = -ENOENT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Found it! Remove the notification from the pending list */
|
|
|
|
|
|
|
|
if (prev == NULL)
|
|
|
|
{
|
|
|
|
g_notifier_pending = notifier->flink;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev->flink = notifier->flink;
|
|
|
|
}
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
/* Free the contained information */
|
|
|
|
|
|
|
|
DEBUGASSERT(notifier->alloc != NULL);
|
|
|
|
kmm_free(notifier->alloc);
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
/* And return the notification to the free list */
|
|
|
|
|
|
|
|
work_notifier_free(notifier);
|
2018-09-09 16:32:37 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)nxsem_post(&g_notifier_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-09-09 23:01:44 +02:00
|
|
|
* Name: work_notifier_signal
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An event has just occurred. Signal all threads waiting for that event.
|
|
|
|
*
|
2018-09-09 23:01:44 +02:00
|
|
|
* When an event of interest occurs, *all* of the workers waiting for this
|
|
|
|
* event will be executed. If there are multiple workers for a resource
|
|
|
|
* then only the first to execute will get the resource. Others will
|
|
|
|
* need to call work_notifier_setup() once again.
|
2018-09-09 19:57:25 +02:00
|
|
|
*
|
2018-09-09 16:32:37 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* evtype - The type of the event that just occurred.
|
|
|
|
* qualifier - Event qualifier to distinguish different cases of the
|
|
|
|
* generic event type.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
void work_notifier_signal(enum work_evtype_e evtype,
|
2018-09-09 16:32:37 +02:00
|
|
|
FAR void *qualifier)
|
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
FAR struct work_notifier_entry_s *notifier;
|
|
|
|
FAR struct work_notifier_entry_s *prev;
|
|
|
|
FAR struct work_notifier_entry_s *next;
|
2018-09-09 16:32:37 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Get exclusive access to the notifier data structure */
|
|
|
|
|
|
|
|
ret = nxsem_wait(&g_notifier_sem);
|
|
|
|
while (ret < 0)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't let any newly started threads block this thread until all of
|
|
|
|
* the notifications and been sent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
|
|
|
|
/* Process the notification at the head of the pending list until the
|
|
|
|
* pending list is empty */
|
|
|
|
|
|
|
|
/* Find the entry matching this key in the g_notifier_pending list. */
|
|
|
|
|
|
|
|
for (prev = NULL, notifier = g_notifier_pending;
|
2018-09-09 23:01:44 +02:00
|
|
|
notifier != NULL;
|
2018-09-09 16:32:37 +02:00
|
|
|
notifier = next)
|
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
FAR struct work_notifier_alloc_s *alloc;
|
|
|
|
FAR struct work_notifier_s *info;
|
2018-09-09 19:57:25 +02:00
|
|
|
|
2018-09-09 16:32:37 +02:00
|
|
|
/* Set up for the next time through the loop (in case the entry is
|
|
|
|
* removed from the list).
|
|
|
|
*/
|
|
|
|
|
|
|
|
next = notifier->flink;
|
|
|
|
|
|
|
|
/* Check if this is the a notification request for the event that
|
|
|
|
* just occurred.
|
|
|
|
*/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
alloc = notifier->alloc;
|
|
|
|
DEBUGASSERT(alloc != NULL);
|
|
|
|
info = &alloc->info;
|
|
|
|
|
|
|
|
if (info->evtype == evtype && info->qualifier == qualifier)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
|
2018-09-09 16:32:37 +02:00
|
|
|
/* Yes.. Remove the notification from the pending list */
|
|
|
|
|
|
|
|
if (prev == NULL)
|
|
|
|
{
|
|
|
|
g_notifier_pending = next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev->flink = next;
|
|
|
|
}
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
/* Schedule the work */
|
|
|
|
|
|
|
|
(void)work_queue(HPWORK, &alloc->work, info->worker, info, 0);
|
2018-09-09 16:32:37 +02:00
|
|
|
|
|
|
|
/* Free the notification by returning it to the free list */
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
work_notifier_free(notifier);
|
2018-09-09 16:32:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The entry was not removed, the current entry will be the
|
|
|
|
* next previous entry.
|
|
|
|
*/
|
|
|
|
|
|
|
|
prev = notifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sched_unlock();
|
|
|
|
(void)nxsem_post(&g_notifier_sem);
|
|
|
|
}
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
#endif /* CONFIG_WQUEUE_NOTIFIER */
|