VirtualBox

Changeset 45127 in vbox


Ignore:
Timestamp:
Mar 21, 2013 2:42:22 PM (12 years ago)
Author:
vboxsync
Message:

AutoLock.cpp: Try the new read/write critical section.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/AutoLock.cpp

    r41528 r45127  
     1/* $Id$ */
    12/** @file
    2  *
    3  * Automatic locks, implementation
     3 * Automatic locks, implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
     18
     19/*******************************************************************************
     20*   Defined Constants And Macros                                               *
     21*******************************************************************************/
     22#define GLUE_USE_CRITSECTRW
     23
     24
     25/*******************************************************************************
     26*   Header Files                                                               *
     27*******************************************************************************/
    1828#include <iprt/cdefs.h>
    1929#include <iprt/critsect.h>
     
    3848#include <list>
    3949#include <map>
     50
    4051
    4152namespace util
     
    134145    { }
    135146
    136     RTSEMRW                     sem;
    137     VBoxLockingClass   lockClass;
    138 
    139 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    140     com::Utf8Str                strDescription;
     147#ifdef GLUE_USE_CRITSECTRW
     148    mutable RTCRITSECTRW    CritSect;
     149#else
     150    RTSEMRW                 sem;
     151#endif
     152    VBoxLockingClass        lockClass;
     153
     154#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     155    com::Utf8Str            strDescription;
    141156#endif
    142157};
     
    147162
    148163    m->lockClass = lockClass;
    149 
    150164#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    151165    m->strDescription = com::Utf8StrFmt("r/w %RCv", this);
     166#endif
     167
     168#ifdef GLUE_USE_CRITSECTRW
     169# ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     170    int vrc = RTCritSectRwInitEx(&m->CritSect, 0 /*fFlags*/, g_mapLockValidationClasses[lockClass], RTLOCKVAL_SUB_CLASS_ANY, NULL);
     171# else
     172    int vrc = RTCritSectRwInitEx(&m->CritSect, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, NULL);
     173# endif
     174#else
     175# ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    152176    int vrc = RTSemRWCreateEx(&m->sem, 0 /*fFlags*/, g_mapLockValidationClasses[lockClass], RTLOCKVAL_SUB_CLASS_ANY, NULL);
    153 #else
     177# else
    154178    int vrc = RTSemRWCreateEx(&m->sem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, NULL);
     179# endif
    155180#endif
    156181    AssertRC(vrc);
     
    159184/*virtual*/ RWLockHandle::~RWLockHandle()
    160185{
     186#ifdef GLUE_USE_CRITSECTRW
     187    RTCritSectRwDelete(&m->CritSect);
     188#else
    161189    RTSemRWDestroy(m->sem);
     190#endif
    162191    delete m;
    163192}
     
    165194/*virtual*/ bool RWLockHandle::isWriteLockOnCurrentThread() const
    166195{
     196#ifdef GLUE_USE_CRITSECTRW
     197    return RTCritSectRwIsWriteOwner(&m->CritSect);
     198#else
    167199    return RTSemRWIsWriteOwner(m->sem);
     200#endif
    168201}
    169202
    170203/*virtual*/ void RWLockHandle::lockWrite(LOCKVAL_SRC_POS_DECL)
    171204{
    172 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     205#ifdef GLUE_USE_CRITSECTRW
     206# ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     207    int vrc = RTCritSectRwEnterExclDebug(&m->CritSect, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS);
     208# else
     209    int vrc = RTCritSectRwEnterExcl(&m->CritSect);
     210# endif
     211#else
     212# ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    173213    int vrc = RTSemRWRequestWriteDebug(m->sem, RT_INDEFINITE_WAIT, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS);
    174 #else
     214# else
    175215    int vrc = RTSemRWRequestWrite(m->sem, RT_INDEFINITE_WAIT);
     216# endif
    176217#endif
    177218    AssertRC(vrc);
     
    180221/*virtual*/ void RWLockHandle::unlockWrite()
    181222{
     223#ifdef GLUE_USE_CRITSECTRW
     224    int vrc = RTCritSectRwLeaveExcl(&m->CritSect);
     225#else
    182226    int vrc = RTSemRWReleaseWrite(m->sem);
     227#endif
    183228    AssertRC(vrc);
    184229
     
    187232/*virtual*/ void RWLockHandle::lockRead(LOCKVAL_SRC_POS_DECL)
    188233{
    189 #ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     234#ifdef GLUE_USE_CRITSECTRW
     235# ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     236    int vrc = RTCritSectRwEnterSharedDebug(&m->CritSect, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS);
     237# else
     238    int vrc = RTCritSectRwEnterShared(&m->CritSect);
     239# endif
     240#else
     241# ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    190242    int vrc = RTSemRWRequestReadDebug(m->sem, RT_INDEFINITE_WAIT, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS);
    191 #else
     243# else
    192244    int vrc = RTSemRWRequestRead(m->sem, RT_INDEFINITE_WAIT);
     245# endif
    193246#endif
    194247    AssertRC(vrc);
     
    197250/*virtual*/ void RWLockHandle::unlockRead()
    198251{
     252#ifdef GLUE_USE_CRITSECTRW
     253    int vrc = RTCritSectRwLeaveShared(&m->CritSect);
     254#else
    199255    int vrc = RTSemRWReleaseRead(m->sem);
     256#endif
    200257    AssertRC(vrc);
    201258}
     
    204261{
    205262    /* Note! This does not include read recursions done by the writer! */
     263#ifdef GLUE_USE_CRITSECTRW
     264    return RTCritSectRwGetWriteRecursion(&m->CritSect);
     265#else
    206266    return RTSemRWGetWriteRecursion(m->sem);
     267#endif
    207268}
    208269
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