VirtualBox

Changeset 19562 in vbox for trunk/src/VBox/Runtime/r3/win


Ignore:
Timestamp:
May 10, 2009 9:44:16 PM (16 years ago)
Author:
vboxsync
Message:

Runtime/Aio: Change API again

  • pcReqs in RTFileAioCtxSubmit is useless because it does not specify which request fails. Removed it again and made it possible to get the state of a request through RTFileAioReqGetRC()
  • Introduce request states for the first point and to catch more errors using the API before a system dependent call is made to return the same error codes one every system for the same cause.
  • Add RTFileAioGetLimits to get global limits and indication for AIO support.
  • General cleanups and fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/fileaio-win.cpp

    r19186 r19562  
    9090    /** Overlapped structure. */
    9191    OVERLAPPED            Overlapped;
     92    /** Current state the request is in. */
     93    RTFILEAIOREQSTATE     enmState;
    9294    /** The file handle. */
    9395    HANDLE                hFile;
     
    122124#define OVERLAPPED_2_RTFILEAIOREQINTERNAL(pOverlapped) ( (PRTFILEAIOREQINTERNAL)((uintptr_t)(pOverlapped) - RT_OFFSETOF(RTFILEAIOREQINTERNAL, Overlapped)) )
    123125
     126RTR3DECL(int) RTFileAioGetLimits(PRTFILEAIOLIMITS pAioLimits)
     127{
     128    int rcBSD = 0;
     129    AssertPtrReturn(pAioLimits, VERR_INVALID_POINTER);
     130
     131    /* No limits known. */
     132    pAioLimits->cReqsOutstandingMax = RTFILEAIO_UNLIMITED_REQS;
     133    pAioLimits->cbBufferAlignment   = 0;
     134
     135    return VINF_SUCCESS;
     136}
     137
    124138RTR3DECL(int) RTFileAioReqCreate(PRTFILEAIOREQ phReq)
    125139{
     
    133147    pReqInt->fCompleted = false;
    134148    pReqInt->u32Magic   = RTFILEAIOREQ_MAGIC;
     149    RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
    135150
    136151    *phReq = (RTFILEAIOREQ)pReqInt;
     
    139154}
    140155
    141 RTDECL(void) RTFileAioReqDestroy(RTFILEAIOREQ hReq)
     156RTDECL(int) RTFileAioReqDestroy(RTFILEAIOREQ hReq)
    142157{
    143158    /*
     
    145160     */
    146161    if (hReq == NIL_RTFILEAIOREQ)
    147         return;
     162        return VINF_SUCCESS;
    148163    PRTFILEAIOREQINTERNAL pReqInt = hReq;
    149     RTFILEAIOREQ_VALID_RETURN_VOID(pReqInt);
     164    RTFILEAIOREQ_VALID_RETURN(pReqInt);
     165    RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
    150166
    151167    /*
     
    154170    ASMAtomicUoWriteU32(&pReqInt->u32Magic, ~RTFILEAIOREQ_MAGIC);
    155171    RTMemFree(pReqInt);
     172    return VINF_SUCCESS;
    156173}
    157174
     
    169186    PRTFILEAIOREQINTERNAL pReqInt = hReq;
    170187    RTFILEAIOREQ_VALID_RETURN(pReqInt);
     188    RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
    171189    Assert(hFile != NIL_RTFILE);
    172190    AssertPtr(pvBuf);
     
    204222    PRTFILEAIOREQINTERNAL pReqInt = hReq;
    205223    RTFILEAIOREQ_VALID_RETURN(pReqInt);
     224    RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
    206225    AssertReturn(hFile != NIL_RTFILE, VERR_INVALID_HANDLE);
    207226
     
    226245    PRTFILEAIOREQINTERNAL pReqInt = hReq;
    227246    RTFILEAIOREQ_VALID_RETURN(pReqInt);
     247    RTFILEAIOREQ_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_NOT_SUBMITTED);
    228248
    229249    /**
     
    234254     * is only available from Vista and up.
    235255     * The solution is to return VERR_FILE_AIO_IN_PROGRESS
    236      * if the request didn't completed yet.
     256     * if the request didn't completed yet (checked above).
    237257     * Shouldn't be a big issue because a request is normally
    238258     * only canceled if it exceeds a timeout which is quite huge.
    239259     */
    240     if (pReqInt->fCompleted)
    241         return VERR_FILE_AIO_COMPLETED;
    242     else
    243         return VERR_FILE_AIO_IN_PROGRESS;
     260    return VERR_FILE_AIO_COMPLETED;
    244261}
    245262
     
    249266    PRTFILEAIOREQINTERNAL pReqInt = hReq;
    250267    RTFILEAIOREQ_VALID_RETURN(pReqInt);
    251 
    252     if (pReqInt->fCompleted)
    253     {
    254         rc = pReqInt->Rc;
    255         if (*pcbTransfered)
    256             *pcbTransfered = pReqInt->cbTransfered;
    257     }
    258     else
    259         rc = VERR_FILE_AIO_IN_PROGRESS;
     268    RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
     269    RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, PREPARED, VERR_FILE_AIO_NOT_SUBMITTED);
     270
     271    rc = pReqInt->Rc;
     272    if (pcbTransfered && RT_SUCCESS(rc))
     273        *pcbTransfered = pReqInt->cbTransfered;
    260274
    261275    return rc;
     
    325339}
    326340
    327 RTDECL(int) RTFileAioCtxSubmit(RTFILEAIOCTX hAioCtx, PRTFILEAIOREQ pahReqs, size_t cReqs, size_t *pcReqs)
     341RTDECL(int) RTFileAioCtxSubmit(RTFILEAIOCTX hAioCtx, PRTFILEAIOREQ pahReqs, size_t cReqs)
    328342{
    329343    /*
    330344     * Parameter validation.
    331345     */
    332     AssertPtrReturn(pcReqs, VERR_INVALID_POINTER);
    333     *pcReqs = 0;
    334346    int rc = VINF_SUCCESS;
    335347    PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
     
    361373        if (RT_UNLIKELY(!fSucceeded && GetLastError() != ERROR_IO_PENDING))
    362374        {
     375            RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
    363376            rc = RTErrConvertFromWin32(GetLastError());
     377            pReqInt->Rc = rc;
    364378            break;
    365379        }
     380        RTFILEAIOREQ_SET_STATE(pReqInt, SUBMITTED);
    366381    }
    367382
    368     *pcReqs = i;
    369383    ASMAtomicAddS32(&pCtxInt->cRequests, i);
    370384
     
    440454
    441455            /* Mark the request as finished. */
    442             pReqInt->fCompleted = true;
     456            RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
    443457
    444458            /* completion status. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette