2014-10-05 15:11:11 +02:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/aio/aio_suspend.c
|
2014-10-05 15:11:11 +02:00
|
|
|
*
|
2021-03-02 15:54:21 +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
|
2014-10-05 15:11:11 +02:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-10-05 15:11:11 +02:00
|
|
|
*
|
2021-03-02 15:54:21 +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.
|
2014-10-05 15:11:11 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2014-10-05 21:57:55 +02:00
|
|
|
#include <sched.h>
|
2014-10-05 15:11:11 +02:00
|
|
|
#include <signal.h>
|
|
|
|
#include <aio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2014-10-05 23:44:43 +02:00
|
|
|
#ifdef CONFIG_FS_AIO
|
2014-10-05 15:11:11 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-10-05 16:53:13 +02:00
|
|
|
* Name: aio_suspend
|
2014-10-05 15:11:11 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The aio_suspend() function suspends the calling thread until at least
|
|
|
|
* one of the asynchronous I/O operations referenced by the 'list' argument
|
|
|
|
* has completed, until a signal interrupts the function, or, if 'timeout'
|
|
|
|
* is not NULL, until the time interval specified by 'timeout' has passed.
|
|
|
|
* If any of the aiocb structures in the list correspond to completed
|
|
|
|
* asynchronous I/O operations (that is, the error status for the
|
|
|
|
* operation is not equal to EINPROGRESS) at the time of the call, the
|
|
|
|
* function returns without suspending the calling thread.
|
|
|
|
*
|
|
|
|
* Each aiocb structure pointed to must have been used in initiating an
|
|
|
|
* asynchronous I/O request via aio_read(), aio_write(), or lio_listio().
|
|
|
|
* This array may contain NULL pointers, which are ignored. If this
|
|
|
|
* array contains pointers that refer to aiocb structures that have not
|
2017-06-28 18:39:54 +02:00
|
|
|
* been used in submitting asynchronous I/O, the effect is undefined.
|
2014-10-05 15:11:11 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* list - An array of pointers to asynchronous I/O control blocks.
|
|
|
|
* nent - The number of elements in the array.
|
|
|
|
* aiocbp - A pointer to an array
|
|
|
|
* timeout - If not NULL, this parameter is pointer to a timespec
|
|
|
|
* structure that determines a timeout on the operation. If
|
|
|
|
* the time referred to timeout passes before any of the I/O
|
|
|
|
* operations referenced by list are completed, then
|
2017-06-28 18:39:54 +02:00
|
|
|
* aio_suspend() returns with an error.
|
2014-10-05 15:11:11 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* If the aio_suspend() function returns after one or more asynchronous
|
|
|
|
* I/O operations have completed, the function returns zero. Otherwise,
|
|
|
|
* the function returns a value of -1 and sets errno to indicate the
|
|
|
|
* error. The application may determine which asynchronous I/O completed
|
|
|
|
* by scanning the associated error and return status using aio_error()
|
2017-06-28 18:39:54 +02:00
|
|
|
* and aio_return(), respectively.
|
2014-10-05 15:11:11 +02:00
|
|
|
*
|
|
|
|
* The aio_suspend() function will fail if:
|
|
|
|
*
|
|
|
|
* EAGAIN - No asynchronous I/O indicated in the list referenced by
|
|
|
|
* list completed in the time interval indicated by timeout.
|
|
|
|
* EINTR - A signal interrupted the aio_suspend() function.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-06 11:24:42 +02:00
|
|
|
int aio_suspend(FAR const struct aiocb * const list[], int nent,
|
2014-10-05 15:11:11 +02:00
|
|
|
FAR const struct timespec *timeout)
|
|
|
|
{
|
|
|
|
sigset_t set;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
2014-10-06 20:28:37 +02:00
|
|
|
DEBUGASSERT(list);
|
2014-10-05 15:11:11 +02:00
|
|
|
|
|
|
|
/* Lock the scheduler so that no I/O events can complete on the worker
|
|
|
|
* thread until we set our wait set up. Pre-emption will, of course, be
|
|
|
|
* re-enabled while we are waiting for the signal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
|
|
|
|
/* Check each entry in the list. Break out of the loop if any entry
|
|
|
|
* has completed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < nent; i++)
|
|
|
|
{
|
|
|
|
/* Check if the I/O has completed */
|
|
|
|
|
|
|
|
if (list[i] && list[i]->aio_result != -EINPROGRESS)
|
|
|
|
{
|
|
|
|
/* Yes, return success */
|
|
|
|
|
|
|
|
sched_unlock();
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-05 19:43:42 +02:00
|
|
|
/* Then wait for SIGPOLL. On success sigtimedwait() will return the
|
|
|
|
* signal number that cause the error (SIGPOLL). It will set errno
|
|
|
|
* appropriately for this function on errors.
|
|
|
|
*
|
|
|
|
* NOTE: If completion of the I/O causes other signals to be generated
|
|
|
|
* first, then this will wake up and return EINTR instead of success.
|
2014-10-05 15:11:11 +02:00
|
|
|
*/
|
|
|
|
|
2014-10-05 19:43:42 +02:00
|
|
|
sigemptyset(&set);
|
|
|
|
sigaddset(&set, SIGPOLL);
|
|
|
|
|
2014-10-05 21:57:55 +02:00
|
|
|
ret = sigtimedwait(&set, NULL, timeout);
|
2014-10-05 15:11:11 +02:00
|
|
|
sched_unlock();
|
|
|
|
return ret >= 0 ? OK : ERROR;
|
|
|
|
}
|
|
|
|
|
2014-10-05 23:44:43 +02:00
|
|
|
#endif /* CONFIG_FS_AIO */
|