VirtualBox

Changeset 25908 in vbox for trunk/src/VBox/Runtime/generic


Ignore:
Timestamp:
Jan 18, 2010 10:07:28 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56726
Message:

RTSemRWIsReadOwner: For assertion in main.

Location:
trunk/src/VBox/Runtime/generic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/generic/RTFileReadAll-generic.cpp

    r21337 r25908  
    3939RTDECL(int) RTFileReadAll(const char *pszFilename, void **ppvFile, size_t *pcbFile)
    4040{
    41     return RTFileReadAllEx(pszFilename, 0, RTFOFF_MAX, 0, ppvFile, pcbFile);
     41    return RTFileReadAllEx(pszFilename, 0, RTFOFF_MAX, RTFILE_RDALL_O_DENY_WRITE, ppvFile, pcbFile);
    4242}
    4343RT_EXPORT_SYMBOL(RTFileReadAll);
  • trunk/src/VBox/Runtime/generic/semrw-generic.cpp

    r25831 r25908  
    869869RTDECL(bool) RTSemRWIsWriteOwner(RTSEMRW hRWSem)
    870870{
     871    /*
     872     * Validate handle.
     873     */
    871874    struct RTSEMRWINTERNAL *pThis = hRWSem;
    872 
    873     /*
    874      * Validate handle.
    875      */
    876875    AssertPtrReturn(pThis, false);
    877876    AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, false);
     
    886885}
    887886RT_EXPORT_SYMBOL(RTSemRWIsWriteOwner);
     887
     888
     889RTDECL(bool)  RTSemRWIsReadOwner(RTSEMRW hRWSem, bool fWannaHear)
     890{
     891    /*
     892     * Validate handle.
     893     */
     894    struct RTSEMRWINTERNAL *pThis = hRWSem;
     895    AssertPtrReturn(pThis, false);
     896    AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, false);
     897
     898    /*
     899     * Check write ownership.  The writer is also a valid reader.
     900     */
     901    RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf();
     902    RTNATIVETHREAD hWriter;
     903    ASMAtomicUoReadHandle(&pThis->hWriter, &hWriter);
     904    if (hWriter == hNativeSelf)
     905        return true;
     906    if (hWriter != NIL_RTNATIVETHREAD)
     907        return false;
     908
     909#ifdef RTSEMRW_STRICT
     910    /*
     911     * Ask the lock validator.
     912     */
     913    return RTLockValidatorRecSharedIsOwner(&pThis->ValidatorRead, NIL_RTTHREAD);
     914#else
     915    /*
     916     * If there are no reads we cannot be one of them... But if there are we
     917     * cannot know and can only return what the caller want to hear.
     918     */
     919    if (pThis->cReads == 0)
     920        return false;
     921    return fWannaHear;
     922#endif
     923}
     924RT_EXPORT_SYMBOL(RTSemRWIsReadOwner);
    888925
    889926
  • trunk/src/VBox/Runtime/generic/semrw-lockless-generic.cpp

    r25831 r25908  
    876876
    877877
     878RTDECL(bool)  RTSemRWIsReadOwner(RTSEMRW hRWSem, bool fWannaHear)
     879{
     880    /*
     881     * Validate handle.
     882     */
     883    struct RTSEMRWINTERNAL *pThis = hRWSem;
     884    AssertPtrReturn(pThis, false);
     885    AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, false);
     886
     887    /*
     888     * Inspect the state.
     889     */
     890    uint64_t u64State = ASMAtomicReadU64(&pThis->u64State);
     891    if ((u64State & RTSEMRW_DIR_MASK) == (RTSEMRW_DIR_WRITE << RTSEMRW_DIR_SHIFT))
     892    {
     893        /*
     894         * It's in write mode, so we can only be a reader if we're also the
     895         * current writer.
     896         */
     897        RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf();
     898        RTNATIVETHREAD hWriter;
     899        ASMAtomicUoReadHandle(&pThis->hWriter, &hWriter);
     900        return hWriter == hNativeSelf;
     901    }
     902
     903    /*
     904     * Read mode.  If there are no current readers, then we cannot be a reader.
     905     */
     906    if (!(u64State & RTSEMRW_CNT_RD_MASK))
     907        return false;
     908
     909#ifdef RTSEMRW_STRICT
     910    /*
     911     * Ask the lock validator.
     912     */
     913    return RTLockValidatorRecSharedIsOwner(&pThis->ValidatorRead, NIL_RTTHREAD);
     914#else
     915    /*
     916     * Ok, we don't know, just tell the caller what he want to hear.
     917     */
     918    return fWannaHear;
     919#endif
     920}
     921RT_EXPORT_SYMBOL(RTSemRWIsReadOwner);
     922
     923
    878924RTDECL(uint32_t) RTSemRWGetWriteRecursion(RTSEMRW hRWSem)
    879925{
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