static void aio_read_worker(FAR void *arg) { FAR struct aio_container_s *aioc = (FAR struct aio_container_s *)arg; FAR struct aiocb *aiocbp; pid_t pid; #ifdef CONFIG_PRIORITY_INHERITANCE uint8_t prio; #endif ssize_t nread = 0; /* Get the information from the container, decant the AIO control block, * and free the container before starting any I/O. That will minimize * the delays by any other threads waiting for a pre-allocated container. */ DEBUGASSERT(aioc && aioc->aioc_aiocbp); pid = aioc->aioc_pid; #ifdef CONFIG_PRIORITY_INHERITANCE prio = aioc->aioc_prio; #endif aiocbp = aioc_decant(aioc); #ifdef AIO_HAVE_FILEP { /* Perform the file read using: * * u.aioc_filep - File structure pointer * aio_buf - Location of buffer * aio_nbytes - Length of transfer * aio_offset - File offset */ nread = file_pread(aioc->u.aioc_filep, (FAR void *)aiocbp->aio_buf, aiocbp->aio_nbytes, aiocbp->aio_offset); } #endif /* Set the result of the read */ if (nread < 0) { int errcode = get_errno(); fdbg("ERROR: pread failed: %d\n", errcode); DEBUGASSERT(errcode > 0); aiocbp->aio_result = -errcode; } else { aiocbp->aio_result = nread; } /* Signal the client */ (void)aio_signal(pid, aiocbp); #ifdef CONFIG_PRIORITY_INHERITANCE /* Restore the low priority worker thread default priority */ lpwork_restorepriority(prio); #endif }
static void aio_fsync_worker(FAR void *arg) { FAR struct aio_container_s *aioc = (FAR struct aio_container_s *)arg; FAR struct aiocb *aiocbp; pid_t pid; #ifdef CONFIG_PRIORITY_INHERITANCE uint8_t prio; #endif int ret; /* Get the information from the container, decant the AIO control block, * and free the container before starting any I/O. That will minimize * the delays by any other threads waiting for a pre-allocated container. */ DEBUGASSERT(aioc && aioc->aioc_aiocbp); pid = aioc->aioc_pid; #ifdef CONFIG_PRIORITY_INHERITANCE prio = aioc->aioc_prio; #endif aiocbp = aioc_decant(aioc); /* Perform the fsync using u.aioc_filep */ ret = file_fsync(aioc->u.aioc_filep); if (ret < 0) { int errcode = get_errno(); ferr("ERROR: fsync failed: %d\n", errcode); DEBUGASSERT(errcode > 0); aiocbp->aio_result = -errcode; } else { aiocbp->aio_result = OK; } /* Signal the client */ (void)aio_signal(pid, aiocbp); #ifdef CONFIG_PRIORITY_INHERITANCE /* Restore the low priority worker thread default priority */ lpwork_restorepriority(prio); #endif }
static void aio_write_worker(FAR void *arg) { FAR struct aio_container_s *aioc = (FAR struct aio_container_s *)arg; FAR struct aiocb *aiocbp; pid_t pid; #ifdef CONFIG_PRIORITY_INHERITANCE uint8_t prio; #endif ssize_t nwritten = 0; #ifdef AIO_HAVE_FILEP int oflags; #endif /* Get the information from the container, decant the AIO control block, * and free the container before starting any I/O. That will minimize * the delays by any other threads waiting for a pre-allocated container. */ DEBUGASSERT(aioc && aioc->aioc_aiocbp); pid = aioc->aioc_pid; #ifdef CONFIG_PRIORITY_INHERITANCE prio = aioc->aioc_prio; #endif aiocbp = aioc_decant(aioc); #if defined(AIO_HAVE_FILEP) && defined(AIO_HAVE_PSOCK) if (aiocbp->aio_fildes < CONFIG_NFILE_DESCRIPTORS) #endif #ifdef AIO_HAVE_FILEP { /* Call fcntl(F_GETFL) to get the file open mode. */ oflags = file_fcntl(aioc->u.aioc_filep, F_GETFL); if (oflags < 0) { int errcode = get_errno(); fdbg("ERROR: fcntl failed: %d\n", errcode); aiocbp->aio_result = -errcode; goto errout; } /* Perform the write using: * * u.aioc_filep - File structure pointer * aio_buf - Location of buffer * aio_nbytes - Length of transfer * aio_offset - File offset */ /* Check if O_APPEND is set in the file open flags */ if ((oflags & O_APPEND) != 0) { /* Append to the current file position */ nwritten = file_write(aioc->u.aioc_filep, (FAR const void *)aiocbp->aio_buf, aiocbp->aio_nbytes); } else { nwritten = file_pwrite(aioc->u.aioc_filep, (FAR const void *)aiocbp->aio_buf, aiocbp->aio_nbytes, aiocbp->aio_offset); } } #endif #if defined(AIO_HAVE_FILEP) && defined(AIO_HAVE_PSOCK) else #endif #ifdef AIO_HAVE_PSOCK { /* Perform the send using: * * u.aioc_psock - Socket structure pointer * aio_buf - Location of buffer * aio_nbytes - Length of transfer */ nwritten = psock_send(aioc->u.aioc_psock, (FAR const void *)aiocbp->aio_buf, aiocbp->aio_nbytes, 0); } #endif /* Check the result of the write */ if (nwritten < 0) { int errcode = get_errno(); fdbg("ERROR: write/pwrite failed: %d\n", errcode); DEBUGASSERT(errcode > 0); aiocbp->aio_result = -errcode; } else { aiocbp->aio_result = nwritten; } #ifdef AIO_HAVE_FILEP errout: #endif /* Signal the client */ (void)aio_signal(pid, aiocbp); #ifdef CONFIG_PRIORITY_INHERITANCE /* Restore the low priority worker thread default priority */ lpwork_restorepriority(prio); #endif }