Changeset 8645 in vbox for trunk/src/VBox
- Timestamp:
- May 7, 2008 11:01:00 AM (17 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/thread.cpp
r8245 r8645 199 199 #ifdef IN_RING3 200 200 201 inline voidrtThreadLockRW(void)201 DECLINLINE(void) rtThreadLockRW(void) 202 202 { 203 203 if (g_ThreadRWSem == NIL_RTSEMRW) … … 208 208 209 209 210 inline voidrtThreadLockRD(void)210 DECLINLINE(void) rtThreadLockRD(void) 211 211 { 212 212 if (g_ThreadRWSem == NIL_RTSEMRW) … … 217 217 218 218 219 inline voidrtThreadUnLockRW(void)219 DECLINLINE(void) rtThreadUnLockRW(void) 220 220 { 221 221 int rc = RTSemRWReleaseWrite(g_ThreadRWSem); … … 224 224 225 225 226 inline voidrtThreadUnLockRD(void)226 DECLINLINE(void) rtThreadUnLockRD(void) 227 227 { 228 228 int rc = RTSemRWReleaseRead(g_ThreadRWSem); … … 244 244 /* 245 245 * Allocate and insert the thread. 246 * (It is vital that rtThreadNativeAdopt updates the TLS before 247 * we try inserting the thread because of locking.) 246 248 */ 247 249 int rc = VERR_NO_MEMORY; … … 1054 1056 1055 1057 /** 1058 * Gets the number of write locks and critical sections the specified 1059 * thread owns. 1060 * 1061 * This number does not include any nested lock/critect entries. 1062 * 1063 * Note that it probably will return 0 for non-strict builds since 1064 * release builds doesn't do unnecessary diagnostic counting like this. 1065 * 1066 * @returns Number of locks on success (0+) and VERR_INVALID_HANDLER on failure 1067 * @param Thread The thread we're inquiring about. 1068 */ 1069 RTDECL(int32_t) RTThreadGetWriteLockCount(RTTHREAD Thread) 1070 { 1071 PRTTHREADINT pThread = rtThreadGet(Thread); 1072 if (!pThread) 1073 return VERR_INVALID_HANDLE; 1074 int32_t cWriteLocks = ASMAtomicReadS32(&pThread->cWriteLocks); 1075 rtThreadRelease(pThread); 1076 return cWriteLocks; 1077 } 1078 1079 1080 /** 1081 * Works the THREADINT::cWriteLocks member, mostly internal. 1082 * 1083 * @param Thread The current thread. 1084 */ 1085 RTDECL(void) RTThreadWriteLockInc(RTTHREAD Thread) 1086 { 1087 PRTTHREADINT pThread = rtThreadGet(Thread); 1088 Assert(pThread); 1089 ASMAtomicIncS32(&pThread->cWriteLocks); 1090 rtThreadRelease(pThread); 1091 } 1092 1093 1094 /** 1095 * Works the THREADINT::cWriteLocks member, mostly internal. 1096 * 1097 * @param Thread The current thread. 1098 */ 1099 RTDECL(void) RTThreadWriteLockDec(RTTHREAD Thread) 1100 { 1101 PRTTHREADINT pThread = rtThreadGet(Thread); 1102 Assert(pThread); 1103 ASMAtomicDecS32(&pThread->cWriteLocks); 1104 rtThreadRelease(pThread); 1105 } 1106 1107 1108 /** 1109 * Gets the number of read locks the specified thread owns. 1110 * 1111 * Note that nesting read lock entry will be included in the 1112 * total sum. And that it probably will return 0 for non-strict 1113 * builds since release builds doesn't do unnecessary diagnostic 1114 * counting like this. 1115 * 1116 * @returns Number of read locks on success (0+) and VERR_INVALID_HANDLER on failure 1117 * @param Thread The thread we're inquiring about. 1118 */ 1119 RTDECL(int32_t) RTThreadGetReadLockCount(RTTHREAD Thread) 1120 { 1121 PRTTHREADINT pThread = rtThreadGet(Thread); 1122 if (!pThread) 1123 return VERR_INVALID_HANDLE; 1124 int32_t cReadLocks = ASMAtomicReadS32(&pThread->cReadLocks); 1125 rtThreadRelease(pThread); 1126 return cReadLocks; 1127 } 1128 1129 1130 /** 1131 * Works the THREADINT::cReadLocks member. 1132 * 1133 * @param Thread The current thread. 1134 */ 1135 RTDECL(void) RTThreadReadLockInc(RTTHREAD Thread) 1136 { 1137 PRTTHREADINT pThread = rtThreadGet(Thread); 1138 Assert(pThread); 1139 ASMAtomicIncS32(&pThread->cReadLocks); 1140 rtThreadRelease(pThread); 1141 } 1142 1143 1144 /** 1145 * Works the THREADINT::cReadLocks member. 1146 * 1147 * @param Thread The current thread. 1148 */ 1149 RTDECL(void) RTThreadReadLockDec(RTTHREAD Thread) 1150 { 1151 PRTTHREADINT pThread = rtThreadGet(Thread); 1152 Assert(pThread); 1153 ASMAtomicDecS32(&pThread->cReadLocks); 1154 rtThreadRelease(pThread); 1155 } 1156 1157 1158 1159 1160 1161 /** 1056 1162 * Recalculates scheduling attributes for the the default process 1057 1163 * priority using the specified priority type for the calling thread. … … 1062 1168 * 1063 1169 * @returns iprt status code. 1170 * @remarks Will only work for strict builds. 1064 1171 */ 1065 1172 int rtThreadDoCalcDefaultPriority(RTTHREADTYPE enmType) -
trunk/src/VBox/Runtime/generic/critsect-generic.cpp
r8245 r8645 46 46 * in order to get the RT thread structure there and this tree is 47 47 * protected by a critsect atm. 48 * @todo the L4 exclusion is no longer true, we've been using TLS for storing this for quite a while now. 48 49 */ 49 50 #if !defined(RTCRITSECT_STRICT) && defined(RT_STRICT) && !defined(RT_OS_L4) … … 353 354 pCritSect->Strict.uEnterId = uId; 354 355 ASMAtomicXchgSize(&pCritSect->Strict.ThreadOwner, (RTUINTPTR)ThreadSelf); /* screw gcc and its pedantic warnings. */ 356 RTThreadWriteLockInc(ThreadSelf); 355 357 #endif 356 358 … … 389 391 */ 390 392 #ifdef RTCRITSECT_STRICT 393 RTThreadWriteLockDec(pCritSect->Strict.ThreadOwner); 391 394 ASMAtomicXchgSize(&pCritSect->Strict.ThreadOwner, NIL_RTTHREAD); 392 395 #endif -
trunk/src/VBox/Runtime/include/internal/thread.h
r8245 r8645 66 66 /** Waiting on a event multiple wakeup semaphore. */ 67 67 RTTHREADSTATE_EVENTMULTI, 68 /** Waiting on a read write semaphore, read (shared) access. */ 69 RTTHREADSTATE_RW_READ, 70 /** Waiting on a read write semaphore, write (exclusive) access. */ 71 RTTHREADSTATE_RW_WRITE, 68 72 /** The thread is sleeping. */ 69 73 RTTHREADSTATE_SLEEP, … … 78 82 || (enmState) == RTTHREADSTATE_EVENT \ 79 83 || (enmState) == RTTHREADSTATE_EVENTMULTI \ 84 || (enmState) == RTTHREADSTATE_RW_READ \ 85 || (enmState) == RTTHREADSTATE_RW_WRITE \ 80 86 || (enmState) == RTTHREADSTATE_SLEEP \ 81 87 ) … … 140 146 /** Where we're blocking. */ 141 147 RTUINTPTR volatile uBlockId; 148 /** Number of registered write locks, mutexes and critsects that this thread owns. */ 149 int32_t volatile cWriteLocks; 150 /** Number of registered read locks that this thread owns, nesting included. */ 151 int32_t volatile cReadLocks; 142 152 #endif /* IN_RING3 */ 143 153 #ifdef IPRT_WITH_GENERIC_TLS
Note:
See TracChangeset
for help on using the changeset viewer.