2018-09-09 16:32:37 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* mm/iob/iob_notifier.c
|
|
|
|
*
|
2024-09-12 16:44:55 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2018-09-09 23:01:44 +02:00
|
|
|
#include <assert.h>
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
#include <nuttx/wqueue.h>
|
2018-09-09 16:32:37 +02:00
|
|
|
#include <nuttx/mm/iob.h>
|
|
|
|
|
|
|
|
#include "iob.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_IOB_NOTIFIER
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: iob_notifier_setup
|
|
|
|
*
|
|
|
|
* Description:
|
2018-09-09 23:01:44 +02:00
|
|
|
* Set up to perform a callback to the worker function when an IOB is
|
2018-09-11 16:49:39 +02:00
|
|
|
* available. The worker function will execute on the selected priority
|
2018-09-09 23:01:44 +02:00
|
|
|
* worker thread.
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-09-11 16:49:39 +02:00
|
|
|
* qid - Selects work queue. Must be HPWORK or LPWORK.
|
2018-09-09 23:01:44 +02:00
|
|
|
* worker - The worker function to execute on the high priority work queue
|
|
|
|
* when the event occurs.
|
|
|
|
* arg - A user-defined argument that will be available to the worker
|
|
|
|
* function when it runs.
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-09-11 15:22:23 +02:00
|
|
|
* > 0 - The notification is in place. The returned value is a key that
|
|
|
|
* may be used later in a call to iob_notifier_teardown().
|
|
|
|
* == 0 - There are already free IOBs. No notification will be provided.
|
|
|
|
* < 0 - An unexpected error occurred and notification will occur. The
|
2018-09-09 16:32:37 +02:00
|
|
|
* returned value is a negated errno value that indicates the
|
|
|
|
* nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-11 16:49:39 +02:00
|
|
|
int iob_notifier_setup(int qid, worker_t worker, FAR void *arg)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
struct work_notifier_s info;
|
|
|
|
|
|
|
|
DEBUGASSERT(worker != NULL);
|
|
|
|
|
|
|
|
info.evtype = WORK_IOB_AVAIL;
|
2018-09-11 16:49:39 +02:00
|
|
|
info.qid = qid;
|
2018-09-09 23:01:44 +02:00
|
|
|
info.qualifier = NULL;
|
|
|
|
info.arg = arg;
|
|
|
|
info.worker = worker;
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
return work_notifier_setup(&info);
|
2018-09-09 16:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: iob_notifier_teardown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Eliminate an IOB notification previously setup by iob_notifier_setup().
|
|
|
|
* This function should only be called if the notification should be
|
|
|
|
* aborted prior to the notification. The notification will automatically
|
2018-09-11 15:22:23 +02:00
|
|
|
* be torn down after the notification.
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* key - The key value returned from a previous call to
|
|
|
|
* iob_notifier_setup().
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2022-05-13 12:26:42 +02:00
|
|
|
* None.
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-05-13 12:26:42 +02:00
|
|
|
void iob_notifier_teardown(int key)
|
2018-09-09 16:32:37 +02:00
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
/* This is just a simple wrapper around work_notifier_teardown(). */
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2022-05-13 12:26:42 +02:00
|
|
|
work_notifier_teardown(key);
|
2018-09-09 16:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: iob_notifier_signal
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An IOB has become available. Signal all threads waiting for an IOB
|
|
|
|
* that an IOB is available.
|
|
|
|
*
|
2018-09-09 23:01:44 +02:00
|
|
|
* When an IOB becomes available, *all* of the workers waiting for an
|
|
|
|
* IOB will be executed. If there are multiple workers waiting for an IOB
|
|
|
|
* then only the first to execute will get the IOB. Others will
|
|
|
|
* need to call iob_notify_setup() once again.
|
2018-09-09 16:32:37 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void iob_notifier_signal(void)
|
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
/* This is just a simple wrapper around work_notifier_signal(). */
|
2018-09-09 16:32:37 +02:00
|
|
|
|
2020-01-19 10:44:27 +01:00
|
|
|
work_notifier_signal(WORK_IOB_AVAIL, NULL);
|
2018-09-09 16:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_IOB_NOTIFIER */
|