VirtualBox

Changeset 25409 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Dec 15, 2009 3:04:41 PM (15 years ago)
Author:
vboxsync
Message:

IPRT,PDMCritSect,Main: Moved code dealing with lock counting from RTThread to RTLockValidator. Fixed thread termination assertion on windows.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/log/log.cpp

    r24987 r25409  
    4646# include <iprt/env.h>
    4747# include <iprt/file.h>
     48# include <iprt/lockvalidator.h>
    4849# include <iprt/path.h>
    4950#endif
     
    412413                    if (Thread != NIL_RTTHREAD)
    413414                    {
    414                         int32_t c = RTThreadGetWriteLockCount(Thread);
     415                        int32_t c = RTLockValidatorWriteLockGetCount(Thread);
    415416                        RTSemSpinMutexRequest(pLogger->hSpinMtx);
    416                         c = RTThreadGetWriteLockCount(Thread) - c;
     417                        c = RTLockValidatorWriteLockGetCount(Thread) - c;
    417418                        RTSemSpinMutexRelease(pLogger->hSpinMtx);
    418419                        ASMAtomicWriteU32(&g_cLoggerLockCount, c);
     
    25252526                    if (Thread != NIL_RTTHREAD)
    25262527                    {
    2527                         uint32_t cReadLocks  = RTThreadGetReadLockCount(Thread);
    2528                         uint32_t cWriteLocks = RTThreadGetWriteLockCount(Thread) - g_cLoggerLockCount;
     2528                        uint32_t cReadLocks  = RTLockValidatorReadLockGetCount(Thread);
     2529                        uint32_t cWriteLocks = RTLockValidatorWriteLockGetCount(Thread) - g_cLoggerLockCount;
    25292530                        cReadLocks  = RT_MIN(0xfff, cReadLocks);
    25302531                        cWriteLocks = RT_MIN(0xfff, cWriteLocks);
  • trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp

    r25406 r25409  
    185185    return hThread;
    186186}
     187
     188
     189RTDECL(int32_t) RTLockValidatorWriteLockGetCount(RTTHREAD Thread)
     190{
     191    if (Thread == NIL_RTTHREAD)
     192        return 0;
     193
     194    PRTTHREADINT pThread = rtThreadGet(Thread);
     195    if (!pThread)
     196        return VERR_INVALID_HANDLE;
     197    int32_t cWriteLocks = ASMAtomicReadS32(&pThread->LockValidator.cWriteLocks);
     198    rtThreadRelease(pThread);
     199    return cWriteLocks;
     200}
     201RT_EXPORT_SYMBOL(RTLockValidatorWriteLockGetCount);
     202
     203
     204RTDECL(void) RTLockValidatorWriteLockInc(RTTHREAD Thread)
     205{
     206    PRTTHREADINT pThread = rtThreadGet(Thread);
     207    AssertReturnVoid(pThread);
     208    ASMAtomicIncS32(&pThread->LockValidator.cWriteLocks);
     209    rtThreadRelease(pThread);
     210}
     211RT_EXPORT_SYMBOL(RTLockValidatorWriteLockInc);
     212
     213
     214RTDECL(void) RTLockValidatorWriteLockDec(RTTHREAD Thread)
     215{
     216    PRTTHREADINT pThread = rtThreadGet(Thread);
     217    AssertReturnVoid(pThread);
     218    ASMAtomicDecS32(&pThread->LockValidator.cWriteLocks);
     219    rtThreadRelease(pThread);
     220}
     221RT_EXPORT_SYMBOL(RTLockValidatorWriteLockDec);
     222
     223
     224RTDECL(int32_t) RTLockValidatorReadLockGetCount(RTTHREAD Thread)
     225{
     226    if (Thread == NIL_RTTHREAD)
     227        return 0;
     228
     229    PRTTHREADINT pThread = rtThreadGet(Thread);
     230    if (!pThread)
     231        return VERR_INVALID_HANDLE;
     232    int32_t cReadLocks = ASMAtomicReadS32(&pThread->LockValidator.cReadLocks);
     233    rtThreadRelease(pThread);
     234    return cReadLocks;
     235}
     236RT_EXPORT_SYMBOL(RTLockValidatorReadLockGetCount);
     237
     238
     239RTDECL(void) RTLockValidatorReadLockInc(RTTHREAD Thread)
     240{
     241    PRTTHREADINT pThread = rtThreadGet(Thread);
     242    Assert(pThread);
     243    ASMAtomicIncS32(&pThread->LockValidator.cReadLocks);
     244    rtThreadRelease(pThread);
     245}
     246RT_EXPORT_SYMBOL(RTLockValidatorReadLockInc);
     247
     248
     249RTDECL(void) RTLockValidatorReadLockDec(RTTHREAD Thread)
     250{
     251    PRTTHREADINT pThread = rtThreadGet(Thread);
     252    Assert(pThread);
     253    ASMAtomicDecS32(&pThread->LockValidator.cReadLocks);
     254    rtThreadRelease(pThread);
     255}
     256RT_EXPORT_SYMBOL(RTLockValidatorReadLockDec);
     257
    187258
    188259
     
    308379    AssertPtrReturnVoid(pThread);
    309380    AssertReturnVoid(pThread->u32Magic == RTTHREADINT_MAGIC);
    310     AssertReturnVoid(rtThreadGetState(pThread) == RTTHREADSTATE_RUNNING);
     381    RTTHREADSTATE enmThreadState = rtThreadGetState(pThread);
     382    AssertReturnVoid(   enmThreadState == RTTHREADSTATE_RUNNING
     383                     || enmThreadState == RTTHREADSTATE_TERMINATED /* rtThreadRemove uses locks too */);
    311384
    312385    /*
  • trunk/src/VBox/Runtime/common/misc/thread.cpp

    r25406 r25409  
    12031203RT_EXPORT_SYMBOL(RTThreadGetType);
    12041204
    1205 
    12061205#ifdef IN_RING3
    1207 
    1208 /**
    1209  * Gets the number of write locks and critical sections the specified
    1210  * thread owns.
    1211  *
    1212  * This number does not include any nested lock/critect entries.
    1213  *
    1214  * Note that it probably will return 0 for non-strict builds since
    1215  * release builds doesn't do unnecessary diagnostic counting like this.
    1216  *
    1217  * @returns Number of locks on success (0+) and VERR_INVALID_HANDLER on failure
    1218  * @param   Thread          The thread we're inquiring about.
    1219  *
    1220  * @todo Move this.
    1221  */
    1222 RTDECL(int32_t) RTThreadGetWriteLockCount(RTTHREAD Thread)
    1223 {
    1224     if (Thread == NIL_RTTHREAD)
    1225         return 0;
    1226 
    1227     PRTTHREADINT pThread = rtThreadGet(Thread);
    1228     if (!pThread)
    1229         return VERR_INVALID_HANDLE;
    1230     int32_t cWriteLocks = ASMAtomicReadS32(&pThread->LockValidator.cWriteLocks);
    1231     rtThreadRelease(pThread);
    1232     return cWriteLocks;
    1233 }
    1234 RT_EXPORT_SYMBOL(RTThreadGetWriteLockCount);
    1235 
    1236 
    1237 /**
    1238  * Works the THREADINT::cWriteLocks member, mostly internal.
    1239  *
    1240  * @param   Thread      The current thread.
    1241  *
    1242  * @todo Move this.
    1243  */
    1244 RTDECL(void) RTThreadWriteLockInc(RTTHREAD Thread)
    1245 {
    1246     PRTTHREADINT pThread = rtThreadGet(Thread);
    1247     AssertReturnVoid(pThread);
    1248     ASMAtomicIncS32(&pThread->LockValidator.cWriteLocks);
    1249     rtThreadRelease(pThread);
    1250 }
    1251 RT_EXPORT_SYMBOL(RTThreadWriteLockInc);
    1252 
    1253 
    1254 /**
    1255  * Works the THREADINT::cWriteLocks member, mostly internal.
    1256  *
    1257  * @param   Thread      The current thread.
    1258  *
    1259  * @todo Move this.
    1260  */
    1261 RTDECL(void) RTThreadWriteLockDec(RTTHREAD Thread)
    1262 {
    1263     PRTTHREADINT pThread = rtThreadGet(Thread);
    1264     AssertReturnVoid(pThread);
    1265     ASMAtomicDecS32(&pThread->LockValidator.cWriteLocks);
    1266     rtThreadRelease(pThread);
    1267 }
    1268 RT_EXPORT_SYMBOL(RTThreadWriteLockDec);
    1269 
    1270 
    1271 /**
    1272  * Gets the number of read locks the specified thread owns.
    1273  *
    1274  * Note that nesting read lock entry will be included in the
    1275  * total sum. And that it probably will return 0 for non-strict
    1276  * builds since release builds doesn't do unnecessary diagnostic
    1277  * counting like this.
    1278  *
    1279  * @returns Number of read locks on success (0+) and VERR_INVALID_HANDLER on failure
    1280  * @param   Thread          The thread we're inquiring about.
    1281  *
    1282  * @todo Move this.
    1283  */
    1284 RTDECL(int32_t) RTThreadGetReadLockCount(RTTHREAD Thread)
    1285 {
    1286     if (Thread == NIL_RTTHREAD)
    1287         return 0;
    1288 
    1289     PRTTHREADINT pThread = rtThreadGet(Thread);
    1290     if (!pThread)
    1291         return VERR_INVALID_HANDLE;
    1292     int32_t cReadLocks = ASMAtomicReadS32(&pThread->LockValidator.cReadLocks);
    1293     rtThreadRelease(pThread);
    1294     return cReadLocks;
    1295 }
    1296 RT_EXPORT_SYMBOL(RTThreadGetReadLockCount);
    1297 
    1298 
    1299 /**
    1300  * Works the THREADINT::cReadLocks member.
    1301  *
    1302  * @param   Thread      The current thread.
    1303  *
    1304  * @todo Move this.
    1305  */
    1306 RTDECL(void) RTThreadReadLockInc(RTTHREAD Thread)
    1307 {
    1308     PRTTHREADINT pThread = rtThreadGet(Thread);
    1309     Assert(pThread);
    1310     ASMAtomicIncS32(&pThread->LockValidator.cReadLocks);
    1311     rtThreadRelease(pThread);
    1312 }
    1313 RT_EXPORT_SYMBOL(RTThreadReadLockInc);
    1314 
    1315 
    1316 /**
    1317  * Works the THREADINT::cReadLocks member.
    1318  *
    1319  * @param   Thread      The current thread.
    1320  *
    1321  * @todo Move this.
    1322  */
    1323 RTDECL(void) RTThreadReadLockDec(RTTHREAD Thread)
    1324 {
    1325     PRTTHREADINT pThread = rtThreadGet(Thread);
    1326     Assert(pThread);
    1327     ASMAtomicDecS32(&pThread->LockValidator.cReadLocks);
    1328     rtThreadRelease(pThread);
    1329 }
    1330 RT_EXPORT_SYMBOL(RTThreadReadLockDec);
    1331 
    1332 
    1333 
    1334 
    13351206
    13361207/**
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