First round of changes fo AIO integration

This commit is contained in:
Gregory Nutt 2014-10-05 13:57:55 -06:00
parent a86d459eb6
commit f34127823a
8 changed files with 42 additions and 31 deletions

View File

@ -40,12 +40,15 @@
#include <nuttx/config.h>
#include <aio.h>
#include <sched.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/wqueue.h>
#ifndef CONFIG_LIBC_AIO
#include "aio/aio.h"
#ifdef CONFIG_LIBC_AIO
/****************************************************************************
* Pre-processor Definitions
@ -138,7 +141,7 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp)
/* Check if the I/O has completed */
if (aiocbp == -EINPROGRESS)
if (aiocbp->aio_result == -EINPROGRESS)
{
/* No ... attempt to cancel the I/O. There are two possibilities: (1)
* the work has already been started and is no longer queued, or (2)
@ -154,7 +157,7 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp)
{
/* The I/O has already completed */
ret = AIO_ALLDONE
ret = AIO_ALLDONE;
}
sched_unlock();

View File

@ -43,7 +43,7 @@
#include <assert.h>
#include <errno.h>
#ifndef CONFIG_LIBC_AIO
#ifdef CONFIG_LIBC_AIO
/****************************************************************************
* Pre-processor Definitions

View File

@ -49,7 +49,7 @@
#include "lib_internal.h"
#include "aio/aio.h"
#ifndef CONFIG_LIBC_AIO
#ifdef CONFIG_LIBC_AIO
/****************************************************************************
* Pre-processor Definitions
@ -91,7 +91,7 @@
static void aio_fsync_worker(FAR void *arg)
{
FAR struct aiocb *aiocbp = (FAR struct aiocb *)arg;
DEBASSERT(arg);
DEBUGASSERT(arg);
int ret;
/* Perform the fsync using aio_fildes */
@ -102,11 +102,11 @@ static void aio_fsync_worker(FAR void *arg)
int errcode = get_errno();
fdbg("ERROR: fsync failed: %d\n", errode);
DEBUGASSERT(errcode > 0);
aicbp->result = -errcode;
aiocbp->aio_result = -errcode;
}
else
{
aicbp->result = OK;
aiocbp->aio_result = OK;
}
/* Signal the client */
@ -217,7 +217,7 @@ int aio_fsync(int op, FAR struct aiocb *aiocbp)
ret = work_queue(AIO_QUEUE, &aiocbp->aio_work, aio_fsync_worker, aiocbp, 0);
if (ret < 0)
{
aio->aio_result = ret;
aiocbp->aio_result = ret;
set_errno(ret);
return ERROR;
}

View File

@ -50,7 +50,7 @@
#include "lib_internal.h"
#include "aio/aio.h"
#ifndef CONFIG_LIBC_AIO
#ifdef CONFIG_LIBC_AIO
/****************************************************************************
* Pre-processor Definitions
@ -92,7 +92,7 @@
static void aio_read_worker(FAR void *arg)
{
FAR struct aiocb *aiocbp = (FAR struct aiocb *)arg;
DEBASSERT(arg);
DEBUGASSERT(arg);
ssize_t nread;
/* Perform the read using:
@ -103,8 +103,8 @@ static void aio_read_worker(FAR void *arg)
* aio_offset - File offset
*/
nread = pread(aiocbp->aio_fildes, aiocbp->aio_buf, aiocbp->aio_nbytes,
aiocbp->aio_offset);
nread = pread(aiocbp->aio_fildes, (FAR void *)aiocbp->aio_buf,
aiocbp->aio_nbytes, aiocbp->aio_offset);
/* Set the result of the read */
@ -113,11 +113,11 @@ static void aio_read_worker(FAR void *arg)
int errcode = get_errno();
fdbg("ERROR: pread failed: %d\n", errode);
DEBUGASSERT(errcode > 0);
aicbp->result = -errcode;
aiocbp->aio_result = -errcode;
}
else
{
aicbp->result = nread;
aiocbp->aio_result = nread;
}
/* Signal the client */
@ -265,7 +265,7 @@ int aio_read(FAR struct aiocb *aiocbp)
ret = work_queue(AIO_QUEUE, &aiocbp->aio_work, aio_read_worker, aiocbp, 0);
if (ret < 0)
{
aio->aio_result = ret;
aiocbp->aio_result = ret;
set_errno(ret);
return ERROR;
}

View File

@ -43,7 +43,7 @@
#include <assert.h>
#include <errno.h>
#ifndef CONFIG_LIBC_AIO
#ifdef CONFIG_LIBC_AIO
/****************************************************************************
* Pre-processor Definitions
@ -109,7 +109,7 @@ ssize_t aio_return(FAR struct aiocb *aiocbp)
if (aiocbp->aio_result < 0)
{
set_errno((int)-aiocbp->aio_result);
return (ssize_t)ERROR
return (ssize_t)ERROR;
}
return aiocbp->aio_result;

View File

@ -39,13 +39,16 @@
#include <nuttx/config.h>
#include <sched.h>
#include <signal.h>
#include <aio.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include "aio/aio.h"
#ifndef CONFIG_LIBC_AIO
#ifdef CONFIG_LIBC_AIO
/****************************************************************************
* Pre-processor Definitions

View File

@ -39,12 +39,13 @@
#include <nuttx/config.h>
#include <sched.h>
#include <signal.h>
#include <aio.h>
#include <assert.h>
#include <errno.h>
#ifndef CONFIG_LIBC_AIO
#ifdef CONFIG_LIBC_AIO
/****************************************************************************
* Pre-processor Definitions
@ -160,7 +161,7 @@ int aio_suspend(FAR const struct aiocb *const list[], int nent,
sigemptyset(&set);
sigaddset(&set, SIGPOLL);
ret = sigtimedwait(&set, NULL, &timeout)
ret = sigtimedwait(&set, NULL, timeout);
sched_unlock();
return ret >= 0 ? OK : ERROR;
}

View File

@ -40,6 +40,7 @@
#include <nuttx/config.h>
#include <unistd.h>
#include <fcntl.h>
#include <sched.h>
#include <aio.h>
#include <assert.h>
@ -50,7 +51,7 @@
#include "lib_internal.h"
#include "aio/aio.h"
#ifndef CONFIG_LIBC_AIO
#ifdef CONFIG_LIBC_AIO
/****************************************************************************
* Pre-processor Definitions
@ -92,7 +93,7 @@
static void aio_write_worker(FAR void *arg)
{
FAR struct aiocb *aiocbp = (FAR struct aiocb *)arg;
DEBASSERT(arg);
DEBUGASSERT(arg);
ssize_t nwritten;
int oflags;
@ -104,12 +105,12 @@ static void aio_write_worker(FAR void *arg)
* were a system call, then only one would be required.
*/
oflags = fcntl((aiocbp->aio_fildes, F_GETFL, ...)
oflags = fcntl(aiocbp->aio_fildes, F_GETFL);
if (oflags < 0)
{
int errcode = get_errno();
fdbg("ERROR: fcntl failed: %d\n", errode);
aicbp->result = -errcode;
aiocbp->aio_result = -errcode;
}
else
{
@ -127,13 +128,16 @@ static void aio_write_worker(FAR void *arg)
{
/* Append to the current file position */
nwritten = write(aiocbp->aio_fildes, aiocbp->aio_buf,
nwritten = write(aiocbp->aio_fildes,
(FAR const void *)aiocbp->aio_buf,
aiocbp->aio_nbytes);
}
else
{
nwritten = pwrite(aiocbp->aio_fildes, aiocbp->aio_buf,
aiocbp->aio_nbytes, aiocbp->aio_offset);
nwritten = pwrite(aiocbp->aio_fildes,
(FAR const void *)aiocbp->aio_buf,
aiocbp->aio_nbytes,
aiocbp->aio_offset);
}
/* Set the result of the write */
@ -143,11 +147,11 @@ static void aio_write_worker(FAR void *arg)
int errcode = get_errno();
fdbg("ERROR: write/pwrite failed: %d\n", errode);
DEBUGASSERT(errcode > 0);
aicbp->result = -errcode;
aiocbp->aio_result = -errcode;
}
else
{
aicbp->result = nwritten;
aiocbp->aio_result = nwritten;
}
}
@ -298,7 +302,7 @@ int aio_write(FAR struct aiocb *aiocbp)
ret = work_queue(AIO_QUEUE, &aiocbp->aio_work, aio_write_worker, aiocbp, 0);
if (ret < 0)
{
aio->aio_result = ret;
aiocbp->aio_result = ret;
set_errno(ret);
return ERROR;
}