Changeset 3362 in kBuild
- Timestamp:
- Jun 8, 2020 7:28:44 PM (5 years ago)
- Location:
- trunk/src/lib/nt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/nt/kFsCache.c
r3359 r3362 429 429 ? pCache->auGenerations[ pFsObj->fFlags & KFSOBJ_F_USE_CUSTOM_GEN] 430 430 : pCache->auGenerationsMissing[pFsObj->fFlags & KFSOBJ_F_USE_CUSTOM_GEN]; 431 pFsObj-> abUnused[0]+= 1; // for debugging431 pFsObj->cPathHashRefs += 1; // for debugging 432 432 } 433 433 else … … 486 486 ? pCache->auGenerations[ pFsObj->fFlags & KFSOBJ_F_USE_CUSTOM_GEN] 487 487 : pCache->auGenerationsMissing[pFsObj->fFlags & KFSOBJ_F_USE_CUSTOM_GEN]; 488 pFsObj-> abUnused[0]+= 1; // for debugging488 pFsObj->cPathHashRefs += 1; // for debugging 489 489 } 490 490 else … … 593 593 pObj->bObjType = bObjType; 594 594 pObj->fHaveStats = K_FALSE; 595 pObj-> abUnused[0] = K_FALSE;596 pObj-> abUnused[1] = K_FALSE;595 pObj->cPathHashRefs = 0; 596 pObj->idxUserDataLock = KU8_MAX; 597 597 pObj->fFlags = pParent->Obj.fFlags & KFSOBJ_F_INHERITED_MASK; 598 598 pObj->pParent = pParent; … … 3386 3386 else 3387 3387 { 3388 pHashEntry->pFsObj->cPathHashRefs -= 1; 3388 3389 kFsCacheObjRelease(pCache, pHashEntry->pFsObj); 3389 3390 if (pHashEntry->fAbsolute) … … 3447 3448 else 3448 3449 { 3450 pHashEntry->pFsObj->cPathHashRefs -= 1; 3449 3451 kFsCacheObjRelease(pCache, pHashEntry->pFsObj); 3450 3452 if (pHashEntry->fAbsolute) … … 3900 3902 KFSCACHE_LOG(("Destroying %s/%s, type=%d, pObj=%p, pszWhere=%s\n", 3901 3903 pObj->pParent ? pObj->pParent->Obj.pszName : "", pObj->pszName, pObj->bObjType, pObj, pszWhere)); 3902 if (pObj-> abUnused[1]!= 0)3904 if (pObj->cPathHashRefs != 0) 3903 3905 { 3904 3906 fprintf(stderr, "Destroying %s/%s, type=%d, path hash entries: %d!\n", pObj->pParent ? pObj->pParent->Obj.pszName : "", 3905 pObj->pszName, pObj->bObjType, pObj-> abUnused[0]);3907 pObj->pszName, pObj->bObjType, pObj->cPathHashRefs); 3906 3908 fflush(stderr); 3907 3909 __debugbreak(); … … 4080 4082 { 4081 4083 kHlpAssert(cbUserData >= sizeof(*pNew)); 4082 KFSCACHE_ LOCK(pCache);4084 KFSCACHE_OBJUSERDATA_LOCK(pCache, pObj); 4083 4085 4084 4086 if (kFsCacheObjGetUserData(pCache, pObj, uKey) == NULL) … … 4091 4093 pNew->pNext = pObj->pUserDataHead; 4092 4094 pObj->pUserDataHead = pNew; 4093 KFSCACHE_ UNLOCK(pCache);4095 KFSCACHE_OBJUSERDATA_UNLOCK(pCache, pObj); 4094 4096 return pNew; 4095 4097 } 4096 4098 } 4097 4099 4098 KFSCACHE_ UNLOCK(pCache);4100 KFSCACHE_OBJUSERDATA_UNLOCK(pCache, pObj); 4099 4101 return NULL; 4100 4102 } … … 4115 4117 kHlpAssert(pCache->u32Magic == KFSCACHE_MAGIC); 4116 4118 kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC); 4117 KFSCACHE_ LOCK(pCache);4119 KFSCACHE_OBJUSERDATA_LOCK(pCache, pObj); 4118 4120 4119 4121 for (pCur = pObj->pUserDataHead; pCur; pCur = pCur->pNext) 4120 4122 if (pCur->uKey == uKey) 4121 4123 { 4122 KFSCACHE_ UNLOCK(pCache);4124 KFSCACHE_OBJUSERDATA_UNLOCK(pCache, pObj); 4123 4125 return pCur; 4124 4126 } 4125 4127 4126 KFSCACHE_ UNLOCK(pCache);4128 KFSCACHE_OBJUSERDATA_UNLOCK(pCache, pObj); 4127 4129 return NULL; 4128 4130 } 4129 4131 4132 4133 /** 4134 * Determins the idxUserDataLock value. 4135 * 4136 * Called by KFSCACHE_OBJUSERDATA_LOCK when idxUserDataLock is set to KU8_MAX. 4137 * 4138 * @returns The proper idxUserDataLock value. 4139 * @param pCache The cache. 4140 * @param pObj The object. 4141 */ 4142 KU8 kFsCacheObjGetUserDataLockIndex(PKFSCACHE pCache, PKFSOBJ pObj) 4143 { 4144 KU8 idxUserDataLock = pObj->idxUserDataLock; 4145 if (idxUserDataLock == KU8_MAX) 4146 { 4147 KFSCACHE_LOCK(pCache); 4148 idxUserDataLock = pObj->idxUserDataLock; 4149 if (idxUserDataLock == KU8_MAX) 4150 { 4151 idxUserDataLock = pCache->idxUserDataNext++; 4152 idxUserDataLock %= K_ELEMENTS(pCache->auUserDataLocks); 4153 pObj->idxUserDataLock = idxUserDataLock; 4154 } 4155 KFSCACHE_UNLOCK(pCache); 4156 } 4157 return idxUserDataLock; 4158 } 4130 4159 4131 4160 /** … … 4766 4795 4767 4796 #ifdef KFSCACHE_CFG_LOCKING 4768 InitializeCriticalSection(&pCache->u.CritSect); 4797 { 4798 KSIZE idx = K_ELEMENTS(pCache->auUserDataLocks); 4799 while (idx-- > 0) 4800 InitializeCriticalSection(&pCache->auUserDataLocks[idx].CritSect); 4801 InitializeCriticalSection(&pCache->u.CritSect); 4802 } 4769 4803 #endif 4770 4804 return pCache; -
trunk/src/lib/nt/kFsCache.h
r3359 r3362 161 161 /** Set if the Stats member is valid, clear if not. */ 162 162 KBOOL fHaveStats; 163 /** Unused flags. */ 164 KBOOL abUnused[2]; 163 /** Internal debug field for counting path hash references. 164 * @internal */ 165 KU8 cPathHashRefs; 166 /** Index into KFSCACHE::auUserData. */ 167 KU8 idxUserDataLock; 165 168 /** Flags, KFSOBJ_F_XXX. */ 166 169 KU32 fFlags; … … 381 384 /** @def KFSCACHE_UNLOCK 382 385 * Counterpart to KFSCACHE_LOCK. */ 386 /** @def KFSCACHE_OBJUSERDATA_LOCK 387 * Locks the user data list of an object exclusively. */ 388 /** @def KFSCACHE_OBJUSERDATA_UNLOCK 389 * Counterpart to KFSCACHE_OBJUSERDATA_LOCK. */ 383 390 #ifdef KFSCACHE_CFG_LOCKING 384 391 # define KFSCACHE_LOCK(a_pCache) EnterCriticalSection(&(a_pCache)->u.CritSect) 385 392 # define KFSCACHE_UNLOCK(a_pCache) LeaveCriticalSection(&(a_pCache)->u.CritSect) 393 # define KFSCACHE_OBJUSERDATA_LOCK(a_pCache, a_pObj) do { \ 394 KU8 idxUserDataLock = (a_pObj)->idxUserDataLock; \ 395 if (idxUserDataLock != KU8_MAX) \ 396 { /* likely */ } \ 397 else \ 398 idxUserDataLock = kFsCacheObjGetUserDataLockIndex(a_pCache, a_pObj); \ 399 idxUserDataLock &= (KU8)(K_ELEMENTS((a_pCache)->auUserDataLocks) - 1); \ 400 EnterCriticalSection(&(a_pCache)->auUserDataLocks[idxUserDataLock].CritSect); \ 401 } while (0) 402 # define KFSCACHE_OBJUSERDATA_UNLOCK(a_pCache, a_pObj) \ 403 LeaveCriticalSection(&(a_pCache)->auUserDataLocks[(a_pObj)->idxUserDataLock & (K_ELEMENTS((a_pCache)->auUserDataLocks) - 1)].CritSect) 386 404 #else 387 405 # define KFSCACHE_LOCK(a_pCache) do { } while (0) 388 406 # define KFSCACHE_UNLOCK(a_pCache) do { } while (0) 407 # define KFSCACHE_OBJUSERDATA_LOCK(a_pCache, a_pObj) do { } while (0) 408 # define KFSCACHE_OBJUSERDATA_UNLOCK(a_pCache, a_pObj) do { } while (0) 389 409 #endif 390 410 … … 456 476 457 477 #ifdef KFSCACHE_CFG_LOCKING 458 /** Critical section protecting the cache. */459 478 union 460 479 { … … 463 482 # endif 464 483 KU64 abPadding[2 * 4 + 4 * sizeof(void *)]; 465 } u; 484 } 485 /** Critical section protecting the cache. */ 486 u, 487 /** Critical section protecting the pUserDataHead of objects. 488 * @note Array size must be a power of two. */ 489 auUserDataLocks[8]; 490 /** The next auUserData index. */ 491 KU8 idxUserDataNext; 466 492 #endif 467 493 … … 544 570 PKFSUSERDATA kFsCacheObjAddUserData(PKFSCACHE pCache, PKFSOBJ pObj, KUPTR uKey, KSIZE cbUserData); 545 571 PKFSUSERDATA kFsCacheObjGetUserData(PKFSCACHE pCache, PKFSOBJ pObj, KUPTR uKey); 572 KU8 kFsCacheObjGetUserDataLockIndex(PKFSCACHE pCache, PKFSOBJ pObj); 546 573 KBOOL kFsCacheObjGetFullPathA(PKFSOBJ pObj, char *pszPath, KSIZE cbPath, char chSlash); 547 574 KBOOL kFsCacheObjGetFullPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash);
Note:
See TracChangeset
for help on using the changeset viewer.