summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-10-05 13:57:55 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-10-05 13:57:55 -0600
commitcb1b0f39a06f94ef1c52996b742179ab125a4338 (patch)
treea2667d171ebc62d5904a490a6741bec330280547
parent7effc6f22568ccf7adc0add4eb150698e49fd5d4 (diff)
downloadnuttx-cb1b0f39a06f94ef1c52996b742179ab125a4338.tar.gz
nuttx-cb1b0f39a06f94ef1c52996b742179ab125a4338.tar.bz2
nuttx-cb1b0f39a06f94ef1c52996b742179ab125a4338.zip
First round of changes fo AIO integration
-rw-r--r--apps/examples/ostest/Kconfig2
-rw-r--r--apps/examples/ostest/aio.c26
-rw-r--r--apps/examples/ostest/ostest.h6
-rw-r--r--nuttx/libc/aio/aio_cancel.c9
-rw-r--r--nuttx/libc/aio/aio_error.c2
-rw-r--r--nuttx/libc/aio/aio_fsync.c10
-rw-r--r--nuttx/libc/aio/aio_read.c14
-rw-r--r--nuttx/libc/aio/aio_return.c4
-rw-r--r--nuttx/libc/aio/aio_signal.c5
-rw-r--r--nuttx/libc/aio/aio_suspend.c5
-rw-r--r--nuttx/libc/aio/aio_write.c24
11 files changed, 65 insertions, 42 deletions
diff --git a/apps/examples/ostest/Kconfig b/apps/examples/ostest/Kconfig
index d19650bd3..b40ee3311 100644
--- a/apps/examples/ostest/Kconfig
+++ b/apps/examples/ostest/Kconfig
@@ -43,7 +43,7 @@ config EXAMPLES_OSTEST_AIO
if EXAMPLES_OSTEST_AIO
config EXAMPLES_OSTEST_AIOPATH
- bool "Scratch file path"
+ string "Scratch file path"
default "/tmp"
---help---
This is the location of a directory in a mounted file system that
diff --git a/apps/examples/ostest/aio.c b/apps/examples/ostest/aio.c
index 9fb16c098..b98480840 100644
--- a/apps/examples/ostest/aio.c
+++ b/apps/examples/ostest/aio.c
@@ -42,8 +42,11 @@
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
+#include <signal.h>
+#include <string.h>
#include <fcntl.h>
#include <aio.h>
+#include <errno.h>
#include "ostest.h"
@@ -77,9 +80,9 @@ static struct aiocb g_aiocbs[AIO_NCTRLBLKS-1];
static struct aiocb *g_aiocb[AIO_NCTRLBLKS] =
{
&g_aiocbs[0], &g_aiocbs[1], &g_aiocbs[2], NULL, &g_aiocbs[3]
-}
+};
-static const FAR void *g_buffers[AIO_NCTRLBLKS] =
+static FAR void * const g_buffers[AIO_NCTRLBLKS] =
{
(FAR void *)g_wrbuffer1,
(FAR void *)NULL,
@@ -123,11 +126,13 @@ static void init_aiocb(bool signal)
for (i = 0; i < AIO_NCTRLBLKS; i++)
{
- aiocbp = &g_aiocbp[i];
+ aiocbp = g_aiocb[i];
if (aiocbp)
{
- aiocbp->sigev_notify = signal ? SIGEV_SIGNAL : SIGEV_NONE;
- aiocbp->aio_buf = g_buffer[i];
+ aiocbp->aio_sigevent.sigev_notify = signal ? SIGEV_SIGNAL : SIGEV_NONE;
+ aiocbp->aio_sigevent.sigev_signo = SIGUSR1;
+
+ aiocbp->aio_buf = g_buffers[i];
aiocbp->aio_offset = (off_t)g_offsets[i];
aiocbp->aio_nbytes = (size_t)g_nbytes[i];
aiocbp->aio_fildes = g_fildes;
@@ -185,7 +190,7 @@ static int check_done(void)
* Public Functions
****************************************************************************/
-int aio_test(void)
+void aio_test(void)
{
int ret;
@@ -195,16 +200,16 @@ int aio_test(void)
g_fildes = open(AIO_FILEPATH, O_RDWR|O_CREAT|O_TRUNC);
if (g_fildes < 0)
{
- printf(aio_test: Failed to open %s: %d\n", AIO_FILEPATH, errno);
- return ERROR;
+ printf("aio_test: Failed to open %s: %d\n", AIO_FILEPATH, errno);
+ return;
}
init_aiocb(false);
ret = lio_listio(LIO_NOWAIT, g_aiocb, AIO_NCTRLBLKS, NULL);
if (ret < 0)
{
- printf(aio_test: lio_listio failed: %d\n", errno);
- return ERROR;
+ printf("aio_test: lio_listio failed: %d\n", errno);
+ return;
}
do
@@ -223,6 +228,7 @@ int aio_test(void)
/* Case 3: Use individual signals */
/* REVISIT: Not yet implemented */
+
}
#endif /* CONFIG_LIBC_AIO */
diff --git a/apps/examples/ostest/ostest.h b/apps/examples/ostest/ostest.h
index a14b4ff6e..b99bb15c7 100644
--- a/apps/examples/ostest/ostest.h
+++ b/apps/examples/ostest/ostest.h
@@ -111,6 +111,12 @@ int dev_null(void);
void fpu_test(void);
+/* aio.c ********************************************************************/
+
+#ifdef CONFIG_LIBC_AIO
+void aio_test(void);
+#endif
+
/* restart.c ****************************************************************/
void restart_test(void);
diff --git a/nuttx/libc/aio/aio_cancel.c b/nuttx/libc/aio/aio_cancel.c
index 41c2811ab..4e67354c8 100644
--- a/nuttx/libc/aio/aio_cancel.c
+++ b/nuttx/libc/aio/aio_cancel.c
@@ -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();
diff --git a/nuttx/libc/aio/aio_error.c b/nuttx/libc/aio/aio_error.c
index 70dd024b9..abdffbde7 100644
--- a/nuttx/libc/aio/aio_error.c
+++ b/nuttx/libc/aio/aio_error.c
@@ -43,7 +43,7 @@
#include <assert.h>
#include <errno.h>
-#ifndef CONFIG_LIBC_AIO
+#ifdef CONFIG_LIBC_AIO
/****************************************************************************
* Pre-processor Definitions
diff --git a/nuttx/libc/aio/aio_fsync.c b/nuttx/libc/aio/aio_fsync.c
index 8595f71b8..8c68618b3 100644
--- a/nuttx/libc/aio/aio_fsync.c
+++ b/nuttx/libc/aio/aio_fsync.c
@@ -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;
}
diff --git a/nuttx/libc/aio/aio_read.c b/nuttx/libc/aio/aio_read.c
index e356305ec..26a8f816b 100644
--- a/nuttx/libc/aio/aio_read.c
+++ b/nuttx/libc/aio/aio_read.c
@@ -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;
}
diff --git a/nuttx/libc/aio/aio_return.c b/nuttx/libc/aio/aio_return.c
index 3aab715fc..c33a07e53 100644
--- a/nuttx/libc/aio/aio_return.c
+++ b/nuttx/libc/aio/aio_return.c
@@ -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;
diff --git a/nuttx/libc/aio/aio_signal.c b/nuttx/libc/aio/aio_signal.c
index 75c1a3dd7..64dd7f75f 100644
--- a/nuttx/libc/aio/aio_signal.c
+++ b/nuttx/libc/aio/aio_signal.c
@@ -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
diff --git a/nuttx/libc/aio/aio_suspend.c b/nuttx/libc/aio/aio_suspend.c
index 51fdf7e4a..8e7083338 100644
--- a/nuttx/libc/aio/aio_suspend.c
+++ b/nuttx/libc/aio/aio_suspend.c
@@ -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;
}
diff --git a/nuttx/libc/aio/aio_write.c b/nuttx/libc/aio/aio_write.c
index 87ea00373..c46ddc9ae 100644
--- a/nuttx/libc/aio/aio_write.c
+++ b/nuttx/libc/aio/aio_write.c
@@ -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;
}