The POSIX.1b standard defines a new set of I/O operations which can
significantly reduce the time an application spends waiting at I/O. The
new functions allow a program to initiate one or more I/O operations and
then immediately resume normal work while the I/O operations are
executed in parallel. This functionality is available if the
`unistd.h' file defines the symbol _POSIX_ASYNCHRONOUS_IO
.
These functions are part of the library with realtime functions named `librt'. They are not actually part of the `libc' binary. The implementation of these functions can be done using support in the kernel (if available) or using an implementation based on threads at userlevel. In the latter case it might be necessary to link applications with the thread library `libpthread' in addition to `librt'.
All AIO operations operate on files which were opened previously. There
might be arbitrarily many operations running for one file. The
asynchronous I/O operations are controlled using a data structure named
struct aiocb
(AIO control block). It is defined in
`aio.h' as follows.
struct aiocb
structure
contains at least the members described in the following table. There
might be more elements which are used by the implementation, but
depending on these elements is not portable and is highly deprecated.
int aio_fildes
lseek
call would lead to an error.
off_t aio_offset
volatile void *aio_buf
size_t aio_nbytes
aio_buf
.
int aio_reqprio
_POSIX_PRIORITIZED_IO
and
_POSIX_PRIORITY_SCHEDULING
the AIO requests are
processed based on the current scheduling priority. The
aio_reqprio
element can then be used to lower the priority of the
AIO operation.
struct sigevent aio_sigevent
sigev_notify
element is
SIGEV_NONE
no notification is send. If it is SIGEV_SIGNAL
the signal determined by sigev_signo
is send. Otherwise
sigev_notify
must be SIGEV_THREAD
. In this case a thread
is created which starts executing the function pointed to by
sigev_notify_function
.
int aio_lio_opcode
lio_listio
and
lio_listio64
functions. Since these functions allow an
arbitrary number of operations to start at once, and each operation can be
input or output (or nothing), the information must be stored in the
control block. The possible values are:
LIO_READ
aio_offset
and store the next aio_nbytes
bytes in the
buffer pointed to by aio_buf
.
LIO_WRITE
aio_nbytes
bytes starting at
aio_buf
into the file starting at position aio_offset
.
LIO_NOP
struct aiocb
values contains holes, i.e., some of the
values must not be handled although the whole array is presented to the
lio_listio
function.
When the sources are compiled using _FILE_OFFSET_BITS == 64
on a
32 bit machine this type is in fact struct aiocb64
since the LFS
interface transparently replaces the struct aiocb
definition.
For use with the AIO functions defined in the LFS there is a similar type
defined which replaces the types of the appropriate members with larger
types but otherwise is equivalent to struct aiocb
. Particularly,
all member names are the same.
int aio_fildes
lseek
call would lead to an error.
off64_t aio_offset
volatile void *aio_buf
size_t aio_nbytes
aio_buf
.
int aio_reqprio
_POSIX_PRIORITIZED_IO
and
_POSIX_PRIORITY_SCHEDULING
are defined the AIO requests are
processed based on the current scheduling priority. The
aio_reqprio
element can then be used to lower the priority of the
AIO operation.
struct sigevent aio_sigevent
sigev_notify
element is
SIGEV_NONE
no notification is sent. If it is SIGEV_SIGNAL
the signal determined by sigev_signo
is sent. Otherwise
sigev_notify
must be SIGEV_THREAD
in which case a thread
which starts executing the function pointed to by
sigev_notify_function
.
int aio_lio_opcode
lio_listio
and
[lio_listio64
functions. Since these functions allow an
arbitrary number of operations to start at once, and since each operation can be
input or output (or nothing), the information must be stored in the
control block. See the description of struct aiocb
for a description
of the possible values.
When the sources are compiled using _FILE_OFFSET_BITS == 64
on a
32 bit machine this type is available under the name struct
aiocb64
since the LFS replaces transparently the old interface.
Go to the first, previous, next, last section, table of contents.