fileaio-solaris.cpp revision 10d739d22a5d5a13803f7e34de34de010099270c
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/* $Id$ */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/** @file
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * IPRT - File async I/O, native implementation for the Solaris host platform.
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/*
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * Copyright (C) 2006-2012 Oracle Corporation
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane *
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * This file is part of VirtualBox Open Source Edition (OSE), as
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * available from http://www.virtualbox.org. This file is free software;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * you can redistribute it and/or modify it under the terms of the GNU
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * General Public License (GPL) as published by the Free Software
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * Foundation, in version 2 as it comes in the "COPYING" file of the
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane *
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * The contents of this file may alternatively be used under the terms
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * of the Common Development and Distribution License Version 1.0
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * VirtualBox OSE distribution, in which case the provisions of the
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * CDDL are applicable instead of those of the GPL.
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane *
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * You may elect to license modified versions of this file under the
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * terms and conditions of either the GPL or the CDDL or both.
fb22a3d183d0fbde920275e3e14138a27151e734Jean-Noel Rouvignac */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/*******************************************************************************
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane* Header Files *
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane*******************************************************************************/
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#define LOG_GROUP RTLOGGROUP_FILE
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <iprt/asm.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <iprt/file.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <iprt/mem.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <iprt/assert.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <iprt/string.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <iprt/err.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <iprt/log.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include "internal/fileaio.h"
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <port.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <aio.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <errno.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#include <unistd.h>
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/*******************************************************************************
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane* Structures and Typedefs *
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane*******************************************************************************/
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/**
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * Async I/O completion context state.
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montanetypedef struct RTFILEAIOCTXINTERNAL
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** Handle to the port. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane int iPort;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** Current number of requests active on this context. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane volatile int32_t cRequests;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** Flags given during creation. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane uint32_t fFlags;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** Magic value (RTFILEAIOCTX_MAGIC). */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane uint32_t u32Magic;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane} RTFILEAIOCTXINTERNAL;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/** Pointer to an internal context structure. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montanetypedef RTFILEAIOCTXINTERNAL *PRTFILEAIOCTXINTERNAL;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/**
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * Async I/O request state.
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montanetypedef struct RTFILEAIOREQINTERNAL
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** The aio control block. Must be the FIRST
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * element. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane struct aiocb AioCB;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** Current state the request is in. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQSTATE enmState;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** Flag whether this is a flush request. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane bool fFlush;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** Port notifier object to associate a request to a port. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane port_notify_t PortNotifier;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** Opaque user data. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane void *pvUser;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** Completion context we are assigned to. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane PRTFILEAIOCTXINTERNAL pCtxInt;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /** Magic value (RTFILEAIOREQ_MAGIC). */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane uint32_t u32Magic;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane} RTFILEAIOREQINTERNAL;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/** Pointer to an internal request structure. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montanetypedef RTFILEAIOREQINTERNAL *PRTFILEAIOREQINTERNAL;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/*******************************************************************************
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane* Defined Constants And Macros *
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane*******************************************************************************/
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/** The max number of events to get in one call. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#define AIO_MAXIMUM_REQUESTS_PER_CONTEXT 64
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane/** Id for the wakeup event. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane#define AIO_CONTEXT_WAKEUP_EVENT 1
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTR3DECL(int) RTFileAioGetLimits(PRTFILEAIOLIMITS pAioLimits)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane int rcBSD = 0;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane AssertPtrReturn(pAioLimits, VERR_INVALID_POINTER);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /* No limits known. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pAioLimits->cReqsOutstandingMax = RTFILEAIO_UNLIMITED_REQS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pAioLimits->cbBufferAlignment = 0;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VINF_SUCCESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTR3DECL(int) RTFileAioReqCreate(PRTFILEAIOREQ phReq)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane AssertPtrReturn(phReq, VERR_INVALID_POINTER);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane PRTFILEAIOREQINTERNAL pReqInt = (PRTFILEAIOREQINTERNAL)RTMemAllocZ(sizeof(RTFILEAIOREQINTERNAL));
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane if (RT_UNLIKELY(!pReqInt))
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VERR_NO_MEMORY;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /* Ininitialize static parts. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_sigevent.sigev_notify = SIGEV_PORT;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_sigevent.sigev_value.sival_ptr = &pReqInt->PortNotifier;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->PortNotifier.portnfy_user = pReqInt;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->pCtxInt = NULL;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->u32Magic = RTFILEAIOREQ_MAGIC;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane *phReq = (RTFILEAIOREQ)pReqInt;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VINF_SUCCESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTDECL(int) RTFileAioReqDestroy(RTFILEAIOREQ hReq)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /*
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * Validate the handle and ignore nil.
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane if (hReq == NIL_RTFILEAIOREQ)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VINF_SUCCESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane PRTFILEAIOREQINTERNAL pReqInt = hReq;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_VALID_RETURN(pReqInt);
fb22a3d183d0fbde920275e3e14138a27151e734Jean-Noel Rouvignac RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
fb22a3d183d0fbde920275e3e14138a27151e734Jean-Noel Rouvignac /*
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * Trash the magic and free it.
fb22a3d183d0fbde920275e3e14138a27151e734Jean-Noel Rouvignac */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane ASMAtomicUoWriteU32(&pReqInt->u32Magic, ~RTFILEAIOREQ_MAGIC);
fb22a3d183d0fbde920275e3e14138a27151e734Jean-Noel Rouvignac RTMemFree(pReqInt);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VINF_SUCCESS;
6771bc57f190a8275922290077de1f6d6b374a6fJean-Noel Rouvignac}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
fb22a3d183d0fbde920275e3e14138a27151e734Jean-Noel Rouvignac/**
fb22a3d183d0fbde920275e3e14138a27151e734Jean-Noel Rouvignac * Worker setting up the request.
fb22a3d183d0fbde920275e3e14138a27151e734Jean-Noel Rouvignac */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneDECLINLINE(int) rtFileAioReqPrepareTransfer(RTFILEAIOREQ hReq, RTFILE hFile,
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane unsigned uTransferDirection,
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFOFF off, void *pvBuf, size_t cbTransfer,
fb22a3d183d0fbde920275e3e14138a27151e734Jean-Noel Rouvignac void *pvUser)
fb22a3d183d0fbde920275e3e14138a27151e734Jean-Noel Rouvignac{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /*
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * Validate the input.
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane PRTFILEAIOREQINTERNAL pReqInt = hReq;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_VALID_RETURN(pReqInt);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane Assert(hFile != NIL_RTFILE);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane AssertPtr(pvBuf);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane Assert(off >= 0);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane Assert(cbTransfer > 0);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_lio_opcode = uTransferDirection;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_fildes = RTFileToNative(hFile);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_offset = off;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_nbytes = cbTransfer;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_buf = pvBuf;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->fFlush = false;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->pvUser = pvUser;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->pCtxInt = NULL;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VINF_SUCCESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTDECL(int) RTFileAioReqPrepareRead(RTFILEAIOREQ hReq, RTFILE hFile, RTFOFF off,
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane void *pvBuf, size_t cbRead, void *pvUser)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return rtFileAioReqPrepareTransfer(hReq, hFile, LIO_READ,
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane off, pvBuf, cbRead, pvUser);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTDECL(int) RTFileAioReqPrepareWrite(RTFILEAIOREQ hReq, RTFILE hFile, RTFOFF off,
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane void const *pvBuf, size_t cbWrite, void *pvUser)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return rtFileAioReqPrepareTransfer(hReq, hFile, LIO_WRITE,
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane off, (void *)pvBuf, cbWrite, pvUser);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTDECL(int) RTFileAioReqPrepareFlush(RTFILEAIOREQ hReq, RTFILE hFile, void *pvUser)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane PRTFILEAIOREQINTERNAL pReqInt = (PRTFILEAIOREQINTERNAL)hReq;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_VALID_RETURN(pReqInt);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane Assert(hFile != NIL_RTFILE);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->fFlush = true;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_fildes = RTFileToNative(hFile);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_offset = 0;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_nbytes = 0;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->AioCB.aio_buf = NULL;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pReqInt->pvUser = pvUser;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VINF_SUCCESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTDECL(void *) RTFileAioReqGetUser(RTFILEAIOREQ hReq)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane PRTFILEAIOREQINTERNAL pReqInt = hReq;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_VALID_RETURN_RC(pReqInt, NULL);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return pReqInt->pvUser;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTDECL(int) RTFileAioReqCancel(RTFILEAIOREQ hReq)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane PRTFILEAIOREQINTERNAL pReqInt = hReq;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_VALID_RETURN(pReqInt);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_NOT_SUBMITTED);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane int rcSolaris = aio_cancel(pReqInt->AioCB.aio_fildes, &pReqInt->AioCB);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane if (rcSolaris == AIO_CANCELED)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane {
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /*
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * Decrement request count because the request will never arrive at the
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane * completion port.
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane AssertMsg(VALID_PTR(pReqInt->pCtxInt),
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane ("Invalid state. Request was canceled but wasn't submitted\n"));
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane ASMAtomicDecS32(&pReqInt->pCtxInt->cRequests);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VINF_SUCCESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane }
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane else if (rcSolaris == AIO_ALLDONE)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VERR_FILE_AIO_COMPLETED;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane else if (rcSolaris == AIO_NOTCANCELED)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VERR_FILE_AIO_IN_PROGRESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane else
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return RTErrConvertFromErrno(errno);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTDECL(int) RTFileAioReqGetRC(RTFILEAIOREQ hReq, size_t *pcbTransfered)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane PRTFILEAIOREQINTERNAL pReqInt = hReq;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_VALID_RETURN(pReqInt);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, PREPARED, VERR_FILE_AIO_NOT_SUBMITTED);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane AssertPtrNull(pcbTransfered);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane int rcSol = aio_error(&pReqInt->AioCB);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane Assert(rcSol != EINPROGRESS); /* Handled by our own state handling. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane if (rcSol == 0)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane {
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane if (pcbTransfered)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane *pcbTransfered = aio_return(&pReqInt->AioCB);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VINF_SUCCESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane }
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /* An error occurred. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return RTErrConvertFromErrno(rcSol);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTDECL(int) RTFileAioCtxCreate(PRTFILEAIOCTX phAioCtx, uint32_t cAioReqsMax,
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane uint32_t fFlags)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane int rc = VINF_SUCCESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane PRTFILEAIOCTXINTERNAL pCtxInt;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane AssertPtrReturn(phAioCtx, VERR_INVALID_POINTER);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane AssertReturn(!(fFlags & ~RTFILEAIOCTX_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pCtxInt = (PRTFILEAIOCTXINTERNAL)RTMemAllocZ(sizeof(RTFILEAIOCTXINTERNAL));
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane if (RT_UNLIKELY(!pCtxInt))
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VERR_NO_MEMORY;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /* Init the event handle. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pCtxInt->iPort = port_create();
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane if (RT_LIKELY(pCtxInt->iPort > 0))
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane {
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pCtxInt->fFlags = fFlags;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane pCtxInt->u32Magic = RTFILEAIOCTX_MAGIC;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane *phAioCtx = (RTFILEAIOCTX)pCtxInt;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane }
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane else
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane {
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTMemFree(pCtxInt);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane rc = RTErrConvertFromErrno(errno);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane }
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return rc;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTDECL(int) RTFileAioCtxDestroy(RTFILEAIOCTX hAioCtx)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /* Validate the handle and ignore nil. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane if (hAioCtx == NIL_RTFILEAIOCTX)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VINF_SUCCESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTFILEAIOCTX_VALID_RETURN(pCtxInt);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane /* Cannot destroy a busy context. */
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane if (RT_UNLIKELY(pCtxInt->cRequests))
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VERR_FILE_AIO_BUSY;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane close(pCtxInt->iPort);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane ASMAtomicUoWriteU32(&pCtxInt->u32Magic, RTFILEAIOCTX_MAGIC_DEAD);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane RTMemFree(pCtxInt);
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return VINF_SUCCESS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-MontaneRTDECL(uint32_t) RTFileAioCtxGetMaxReqCount(RTFILEAIOCTX hAioCtx)
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane{
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane return RTFILEAIO_UNLIMITED_REQS;
a3b0441c12b207c0fdfce0566dba2db5ecd3816cViolette Roche-Montane}
RTDECL(int) RTFileAioCtxAssociateWithFile(RTFILEAIOCTX hAioCtx, RTFILE hFile)
{
return VINF_SUCCESS;
}
RTDECL(int) RTFileAioCtxSubmit(RTFILEAIOCTX hAioCtx, PRTFILEAIOREQ pahReqs, size_t cReqs)
{
/*
* Parameter validation.
*/
int rc = VINF_SUCCESS;
PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
RTFILEAIOCTX_VALID_RETURN(pCtxInt);
AssertReturn(cReqs > 0, VERR_INVALID_PARAMETER);
AssertPtrReturn(pahReqs, VERR_INVALID_POINTER);
size_t i = cReqs;
do
{
int rcSol = 0;
size_t cReqsSubmit = 0;
PRTFILEAIOREQINTERNAL pReqInt;
while(i-- > 0)
{
pReqInt = pahReqs[i];
if (RTFILEAIOREQ_IS_NOT_VALID(pReqInt))
{
/* Undo everything and stop submitting. */
for (size_t iUndo = 0; iUndo < i; iUndo++)
{
pReqInt = pahReqs[iUndo];
RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
pReqInt->pCtxInt = NULL;
}
rc = VERR_INVALID_HANDLE;
break;
}
pReqInt->PortNotifier.portnfy_port = pCtxInt->iPort;
pReqInt->pCtxInt = pCtxInt;
RTFILEAIOREQ_SET_STATE(pReqInt, SUBMITTED);
if (pReqInt->fFlush)
break;
cReqsSubmit++;
}
if (cReqsSubmit)
{
rcSol = lio_listio(LIO_NOWAIT, (struct aiocb **)pahReqs, cReqsSubmit, NULL);
if (RT_UNLIKELY(rcSol < 0))
{
if (rcSol == EAGAIN)
rc = VERR_FILE_AIO_INSUFFICIENT_RESSOURCES;
else
rc = RTErrConvertFromErrno(errno);
/* Check which requests got actually submitted and which not. */
for (i = 0; i < cReqs; i++)
{
pReqInt = pahReqs[i];
rcSol = aio_error(&pReqInt->AioCB);
if (rcSol == EINVAL)
{
/* Was not submitted. */
RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
pReqInt->pCtxInt = NULL;
}
else if (rcSol != EINPROGRESS)
{
/* The request encountered an error. */
RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
}
}
break;
}
ASMAtomicAddS32(&pCtxInt->cRequests, cReqsSubmit);
cReqs -= cReqsSubmit;
pahReqs += cReqsSubmit;
}
if (cReqs)
{
pReqInt = pahReqs[0];
RTFILEAIOREQ_VALID_RETURN(pReqInt);
/*
* If there are still requests left we have a flush request.
* lio_listio does not work with this requests so
* we have to use aio_fsync directly.
*/
rcSol = aio_fsync(O_SYNC, &pReqInt->AioCB);
if (RT_UNLIKELY(rcSol < 0))
{
RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
rc = RTErrConvertFromErrno(errno);
break;
}
ASMAtomicIncS32(&pCtxInt->cRequests);
cReqs--;
pahReqs++;
}
} while (cReqs);
return rc;
}
RTDECL(int) RTFileAioCtxWait(RTFILEAIOCTX hAioCtx, size_t cMinReqs, RTMSINTERVAL cMillies,
PRTFILEAIOREQ pahReqs, size_t cReqs, uint32_t *pcReqs)
{
int rc = VINF_SUCCESS;
int cRequestsCompleted = 0;
/*
* Validate the parameters, making sure to always set pcReqs.
*/
AssertPtrReturn(pcReqs, VERR_INVALID_POINTER);
*pcReqs = 0; /* always set */
PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
RTFILEAIOCTX_VALID_RETURN(pCtxInt);
AssertPtrReturn(pahReqs, VERR_INVALID_POINTER);
AssertReturn(cReqs != 0, VERR_INVALID_PARAMETER);
AssertReturn(cReqs >= cMinReqs, VERR_OUT_OF_RANGE);
if ( RT_UNLIKELY(ASMAtomicReadS32(&pCtxInt->cRequests) == 0)
&& !(pCtxInt->fFlags & RTFILEAIOCTX_FLAGS_WAIT_WITHOUT_PENDING_REQUESTS))
return VERR_FILE_AIO_NO_REQUEST;
/*
* Convert the timeout if specified.
*/
struct timespec *pTimeout = NULL;
struct timespec Timeout = {0,0};
uint64_t StartNanoTS = 0;
if (cMillies != RT_INDEFINITE_WAIT)
{
Timeout.tv_sec = cMillies / 1000;
Timeout.tv_nsec = cMillies % 1000 * 1000000;
pTimeout = &Timeout;
StartNanoTS = RTTimeNanoTS();
}
/* Wait for at least one. */
if (!cMinReqs)
cMinReqs = 1;
while ( cMinReqs
&& RT_SUCCESS_NP(rc))
{
port_event_t aPortEvents[AIO_MAXIMUM_REQUESTS_PER_CONTEXT];
uint_t cRequests = cMinReqs;
int cRequestsToWait = RT_MIN(cReqs, AIO_MAXIMUM_REQUESTS_PER_CONTEXT);
int rcSol;
uint64_t StartTime;
rcSol = port_getn(pCtxInt->iPort, &aPortEvents[0], cRequestsToWait, &cRequests, pTimeout);
if (RT_UNLIKELY(rcSol < 0))
rc = RTErrConvertFromErrno(errno);
/* Process received events. */
for (uint_t i = 0; i < cRequests; i++)
{
if (aPortEvents[i].portev_source == PORT_SOURCE_ALERT)
{
Assert(aPortEvents[i].portev_events == AIO_CONTEXT_WAKEUP_EVENT);
rc = VERR_INTERRUPTED; /* We've got interrupted. */
/* Reset the port. */
port_alert(pCtxInt->iPort, PORT_ALERT_SET, 0, NULL);
}
else
{
PRTFILEAIOREQINTERNAL pReqInt = (PRTFILEAIOREQINTERNAL)aPortEvents[i].portev_user;
AssertPtr(pReqInt);
Assert(pReqInt->u32Magic == RTFILEAIOREQ_MAGIC);
/* A request has finished. */
pahReqs[cRequestsCompleted++] = pReqInt;
/* Mark the request as finished. */
RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
}
}
/*
* Done Yet? If not advance and try again.
*/
if (cRequests >= cMinReqs)
break;
cMinReqs -= cRequests;
cReqs -= cRequests;
if (cMillies != RT_INDEFINITE_WAIT)
{
uint64_t NanoTS = RTTimeNanoTS();
uint64_t cMilliesElapsed = (NanoTS - StartNanoTS) / 1000000;
/* The syscall supposedly updates it, but we're paranoid. :-) */
if (cMilliesElapsed < cMillies)
{
Timeout.tv_sec = (cMillies - (RTMSINTERVAL)cMilliesElapsed) / 1000;
Timeout.tv_nsec = (cMillies - (RTMSINTERVAL)cMilliesElapsed) % 1000 * 1000000;
}
else
{
Timeout.tv_sec = 0;
Timeout.tv_nsec = 0;
}
}
}
/*
* Update the context state and set the return value.
*/
*pcReqs = cRequestsCompleted;
ASMAtomicSubS32(&pCtxInt->cRequests, cRequestsCompleted);
return rc;
}
RTDECL(int) RTFileAioCtxWakeup(RTFILEAIOCTX hAioCtx)
{
int rc = VINF_SUCCESS;
PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
RTFILEAIOCTX_VALID_RETURN(pCtxInt);
rc = port_alert(pCtxInt->iPort, PORT_ALERT_UPDATE, AIO_CONTEXT_WAKEUP_EVENT, NULL);
if (RT_UNLIKELY((rc < 0) && (errno != EBUSY)))
return RTErrConvertFromErrno(errno);
return VINF_SUCCESS;
}