Changeset 3184 in kBuild for trunk/src/lib/nt
- Timestamp:
- Mar 23, 2018 10:36:43 PM (7 years ago)
- Location:
- trunk/src/lib/nt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/nt/kFsCache.c
r3082 r3184 577 577 { 578 578 KU8 *pbExtra = (KU8 *)pObj + cbObj; 579 580 KFSCACHE_LOCK(pCache); /** @todo reduce the amount of work done holding the lock */ 579 581 580 582 pCache->cbObjects += cbObj + cbNames; … … 662 664 pDirObj->fPopulated = K_FALSE; 663 665 } 666 667 KFSCACHE_UNLOCK(pCache); 664 668 } 665 669 else … … 710 714 #endif 711 715 { 716 /* No locking needed here, kFsCacheCreateObject takes care of that. */ 712 717 return kFsCacheCreateObject(pCache, pParent, 713 718 szName, cchName, pwszName, cwcName, … … 1729 1734 { 1730 1735 KFSLOOKUPERROR enmIgnored; 1736 KBOOL fRet; 1737 KFSCACHE_LOCK(pCache); 1731 1738 if ( pDir->fPopulated 1732 1739 && !pDir->fNeedRePopulating 1733 1740 && ( pDir->Obj.uCacheGen == KFSOBJ_CACHE_GEN_IGNORE 1734 1741 || pDir->Obj.uCacheGen == pCache->auGenerations[pDir->Obj.fFlags & KFSOBJ_F_USE_CUSTOM_GEN]) ) 1735 return K_TRUE; 1736 return kFsCachePopuplateOrRefreshDir(pCache, pDir, penmError ? penmError : &enmIgnored); 1742 fRet = K_TRUE; 1743 else 1744 fRet = kFsCachePopuplateOrRefreshDir(pCache, pDir, penmError ? penmError : &enmIgnored); 1745 KFSCACHE_UNLOCK(pCache); 1746 return fRet; 1737 1747 } 1738 1748 … … 2760 2770 if (ppLastAncestor) 2761 2771 *ppLastAncestor = NULL; 2772 KFSCACHE_LOCK(pCache); 2762 2773 for (;;) 2763 2774 { … … 2798 2809 if (ppLastAncestor) 2799 2810 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 2811 KFSCACHE_UNLOCK(pCache); 2800 2812 return NULL; 2801 2813 } … … 2818 2830 { 2819 2831 if (pChild) 2820 return kFsCacheObjRetainInternal(pChild); 2832 { 2833 kFsCacheObjRetainInternal(pChild); 2834 KFSCACHE_UNLOCK(pCache); 2835 return pChild; 2836 } 2821 2837 *penmError = KFSLOOKUPERROR_NOT_FOUND; 2822 2838 } … … 2825 2841 if (ppLastAncestor) 2826 2842 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 2843 KFSCACHE_UNLOCK(pCache); 2827 2844 return NULL; 2828 2845 } … … 2843 2860 if (ppLastAncestor) 2844 2861 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 2862 KFSCACHE_UNLOCK(pCache); 2845 2863 return NULL; 2846 2864 } 2847 return kFsCacheObjRetainInternal(pChild); 2865 kFsCacheObjRetainInternal(pChild); 2866 KFSCACHE_UNLOCK(pCache); 2867 return pChild; 2848 2868 } 2849 2869 … … 2859 2879 if (ppLastAncestor) 2860 2880 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 2881 KFSCACHE_UNLOCK(pCache); 2861 2882 return NULL; 2862 2883 } … … 2868 2889 if (ppLastAncestor) 2869 2890 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 2891 KFSCACHE_UNLOCK(pCache); 2870 2892 return NULL; 2871 2893 } … … 2876 2898 if (ppLastAncestor) 2877 2899 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 2900 KFSCACHE_UNLOCK(pCache); 2878 2901 return NULL; 2879 2902 } … … 2881 2904 2882 2905 /* not reached */ 2906 KFSCACHE_UNLOCK(pCache); 2883 2907 return NULL; 2884 2908 } … … 2914 2938 if (ppLastAncestor) 2915 2939 *ppLastAncestor = NULL; 2940 KFSCACHE_LOCK(pCache); 2916 2941 for (;;) 2917 2942 { … … 2952 2977 if (ppLastAncestor) 2953 2978 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 2979 KFSCACHE_UNLOCK(pCache); 2954 2980 return NULL; 2955 2981 } … … 2972 2998 { 2973 2999 if (pChild) 2974 return kFsCacheObjRetainInternal(pChild); 3000 { 3001 kFsCacheObjRetainInternal(pChild); 3002 KFSCACHE_UNLOCK(pCache); 3003 return pChild; 3004 } 2975 3005 *penmError = KFSLOOKUPERROR_NOT_FOUND; 2976 3006 } … … 2979 3009 if (ppLastAncestor) 2980 3010 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 3011 KFSCACHE_UNLOCK(pCache); 2981 3012 return NULL; 2982 3013 } … … 2997 3028 if (ppLastAncestor) 2998 3029 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 3030 KFSCACHE_UNLOCK(pCache); 2999 3031 return NULL; 3000 3032 } 3001 return kFsCacheObjRetainInternal(pChild); 3033 kFsCacheObjRetainInternal(pChild); 3034 KFSCACHE_UNLOCK(pCache); 3035 return pChild; 3002 3036 } 3003 3037 … … 3013 3047 if (ppLastAncestor) 3014 3048 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 3049 KFSCACHE_UNLOCK(pCache); 3015 3050 return NULL; 3016 3051 } … … 3023 3058 if (ppLastAncestor) 3024 3059 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 3060 KFSCACHE_UNLOCK(pCache); 3025 3061 return NULL; 3026 3062 } … … 3031 3067 if (ppLastAncestor) 3032 3068 *ppLastAncestor = kFsCacheObjRetainInternal(&pParent->Obj); 3069 KFSCACHE_UNLOCK(pCache); 3033 3070 return NULL; 3034 3071 } 3035 3072 } 3036 3073 3074 KFSCACHE_UNLOCK(pCache); 3037 3075 return NULL; 3038 3076 } … … 3677 3715 PKFSOBJ kFsCacheLookupA(PKFSCACHE pCache, const char *pszPath, KFSLOOKUPERROR *penmError) 3678 3716 { 3679 KU32 uHashPath; 3680 KU32 cchPath = (KU32)kFsCacheStrHashEx(pszPath, &uHashPath); 3681 return kFsCacheLookupHashedA(pCache, pszPath, cchPath, uHashPath, penmError); 3717 KU32 uHashPath; 3718 KU32 cchPath = (KU32)kFsCacheStrHashEx(pszPath, &uHashPath); 3719 PKFSOBJ pObj; 3720 KFSCACHE_LOCK(pCache); 3721 pObj = kFsCacheLookupHashedA(pCache, pszPath, cchPath, uHashPath, penmError); 3722 KFSCACHE_UNLOCK(pCache); 3723 return pObj; 3682 3724 } 3683 3725 … … 3703 3745 PKFSOBJ kFsCacheLookupW(PKFSCACHE pCache, const wchar_t *pwszPath, KFSLOOKUPERROR *penmError) 3704 3746 { 3705 KU32 uHashPath; 3706 KU32 cwcPath = (KU32)kFsCacheUtf16HashEx(pwszPath, &uHashPath); 3707 return kFsCacheLookupHashedW(pCache, pwszPath, cwcPath, uHashPath, penmError); 3747 KU32 uHashPath; 3748 KU32 cwcPath = (KU32)kFsCacheUtf16HashEx(pwszPath, &uHashPath); 3749 PKFSOBJ pObj; 3750 KFSCACHE_LOCK(pCache); 3751 pObj = kFsCacheLookupHashedW(pCache, pwszPath, cwcPath, uHashPath, penmError); 3752 KFSCACHE_UNLOCK(pCache); 3753 return pObj; 3708 3754 } 3709 3755 … … 3731 3777 PKFSOBJ kFsCacheLookupWithLengthA(PKFSCACHE pCache, const char *pchPath, KSIZE cchPath, KFSLOOKUPERROR *penmError) 3732 3778 { 3733 return kFsCacheLookupHashedA(pCache, pchPath, (KU32)cchPath, kFsCacheStrHashN(pchPath, cchPath), penmError); 3779 KU32 uHashPath = kFsCacheStrHashN(pchPath, cchPath); 3780 PKFSOBJ pObj; 3781 KFSCACHE_LOCK(pCache); 3782 pObj = kFsCacheLookupHashedA(pCache, pchPath, (KU32)cchPath, uHashPath, penmError); 3783 KFSCACHE_UNLOCK(pCache); 3784 return pObj; 3734 3785 } 3735 3786 … … 3757 3808 PKFSOBJ kFsCacheLookupWithLengthW(PKFSCACHE pCache, const wchar_t *pwcPath, KSIZE cwcPath, KFSLOOKUPERROR *penmError) 3758 3809 { 3759 return kFsCacheLookupHashedW(pCache, pwcPath, (KU32)cwcPath, kFsCacheUtf16HashN(pwcPath, cwcPath), penmError); 3810 KU32 uHashPath = kFsCacheUtf16HashN(pwcPath, cwcPath); 3811 PKFSOBJ pObj; 3812 KFSCACHE_LOCK(pCache); 3813 pObj = kFsCacheLookupHashedW(pCache, pwcPath, (KU32)cwcPath, uHashPath, penmError); 3814 KFSCACHE_UNLOCK(pCache); 3815 return pObj; 3760 3816 } 3761 3817 … … 3775 3831 PKFSOBJ kFsCacheLookupNoMissingA(PKFSCACHE pCache, const char *pszPath, KFSLOOKUPERROR *penmError) 3776 3832 { 3777 PKFSOBJ pObj = kFsCacheLookupA(pCache, pszPath, penmError); 3833 PKFSOBJ pObj; 3834 KFSCACHE_LOCK(pCache); /* probably not necessary */ 3835 pObj = kFsCacheLookupA(pCache, pszPath, penmError); 3778 3836 if (pObj) 3779 3837 { 3780 3838 if (pObj->bObjType != KFSOBJ_TYPE_MISSING) 3839 { 3840 KFSCACHE_UNLOCK(pCache); 3781 3841 return pObj; 3842 } 3782 3843 3783 3844 kFsCacheObjRelease(pCache, pObj); 3784 3845 *penmError = KFSLOOKUPERROR_NOT_FOUND; 3785 3846 } 3847 KFSCACHE_UNLOCK(pCache); 3786 3848 return NULL; 3787 3849 } … … 3802 3864 PKFSOBJ kFsCacheLookupNoMissingW(PKFSCACHE pCache, const wchar_t *pwszPath, KFSLOOKUPERROR *penmError) 3803 3865 { 3804 PKFSOBJ pObj = kFsCacheLookupW(pCache, pwszPath, penmError); 3866 PKFSOBJ pObj; 3867 KFSCACHE_LOCK(pCache); /* probably not necessary */ 3868 pObj = kFsCacheLookupW(pCache, pwszPath, penmError); 3805 3869 if (pObj) 3806 3870 { 3807 3871 if (pObj->bObjType != KFSOBJ_TYPE_MISSING) 3872 { 3873 KFSCACHE_UNLOCK(pCache); 3808 3874 return pObj; 3875 } 3809 3876 3810 3877 kFsCacheObjRelease(pCache, pObj); 3811 3878 *penmError = KFSLOOKUPERROR_NOT_FOUND; 3812 3879 } 3880 KFSCACHE_UNLOCK(pCache); 3813 3881 return NULL; 3814 3882 } … … 3828 3896 kHlpAssert(pObj->pParent == NULL); 3829 3897 kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC); 3898 KFSCACHE_LOCK(pCache); 3830 3899 3831 3900 KFSCACHE_LOG(("Destroying %s/%s, type=%d, pObj=%p, pszWhere=%s\n", … … 3891 3960 3892 3961 default: 3962 KFSCACHE_UNLOCK(pCache); 3893 3963 return 0; 3894 3964 } … … 3918 3988 } 3919 3989 3990 KFSCACHE_UNLOCK(pCache); 3991 3920 3992 kHlpFree(pObj); 3921 3993 return 0; … … 3939 4011 kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC); 3940 4012 3941 cRefs = --pObj->cRefs;4013 cRefs = _InterlockedDecrement(&pObj->cRefs); 3942 4014 if (cRefs) 3943 4015 return cRefs; … … 3964 4036 kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC); 3965 4037 3966 cRefs = --pObj->cRefs;4038 cRefs = _InterlockedDecrement(&pObj->cRefs); 3967 4039 if (cRefs) 3968 4040 return cRefs; … … 3985 4057 kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC); 3986 4058 3987 cRefs = ++pObj->cRefs;4059 cRefs = _InterlockedIncrement(&pObj->cRefs); 3988 4060 kHlpAssert(cRefs < 16384); 3989 4061 return cRefs; … … 4008 4080 { 4009 4081 kHlpAssert(cbUserData >= sizeof(*pNew)); 4082 KFSCACHE_LOCK(pCache); 4083 4010 4084 if (kFsCacheObjGetUserData(pCache, pObj, uKey) == NULL) 4011 4085 { … … 4017 4091 pNew->pNext = pObj->pUserDataHead; 4018 4092 pObj->pUserDataHead = pNew; 4093 KFSCACHE_UNLOCK(pCache); 4019 4094 return pNew; 4020 4095 } 4021 4096 } 4022 4097 4098 KFSCACHE_UNLOCK(pCache); 4023 4099 return NULL; 4024 4100 } … … 4039 4115 kHlpAssert(pCache->u32Magic == KFSCACHE_MAGIC); 4040 4116 kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC); 4117 KFSCACHE_LOCK(pCache); 4041 4118 4042 4119 for (pCur = pObj->pUserDataHead; pCur; pCur = pCur->pNext) 4043 4120 if (pCur->uKey == uKey) 4121 { 4122 KFSCACHE_UNLOCK(pCache); 4044 4123 return pCur; 4124 } 4125 4126 KFSCACHE_UNLOCK(pCache); 4045 4127 return NULL; 4046 4128 } … … 4058 4140 KBOOL kFsCacheObjGetFullPathA(PKFSOBJ pObj, char *pszPath, KSIZE cbPath, char chSlash) 4059 4141 { 4142 /** @todo No way of to do locking here w/o pCache parameter; need to verify 4143 * that we're only access static data! */ 4060 4144 KSIZE off = pObj->cchParent; 4061 4145 kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC); … … 4112 4196 KBOOL kFsCacheObjGetFullPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash) 4113 4197 { 4198 /** @todo No way of to do locking here w/o pCache parameter; need to verify 4199 * that we're only access static data! */ 4114 4200 KSIZE off = pObj->cwcParent; 4115 4201 kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC); … … 4168 4254 KBOOL kFsCacheObjGetFullShortPathA(PKFSOBJ pObj, char *pszPath, KSIZE cbPath, char chSlash) 4169 4255 { 4256 /** @todo No way of to do locking here w/o pCache parameter; need to verify 4257 * that we're only access static data! */ 4170 4258 KSIZE off = pObj->cchShortParent; 4171 4259 kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC); … … 4222 4310 KBOOL kFsCacheObjGetFullShortPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash) 4223 4311 { 4312 /** @todo No way of to do locking here w/o pCache parameter; need to verify 4313 * that we're only access static data! */ 4224 4314 KSIZE off = pObj->cwcShortParent; 4225 4315 kHlpAssert(pObj->u32Magic == KFSOBJ_MAGIC); … … 4303 4393 UniStr.MaximumLength = UniStr.Length + sizeof(wchar_t); 4304 4394 4395 /** @todo potential race against kFsCacheInvalidateDeletedDirectoryA */ 4305 4396 MyInitializeObjectAttributes(&ObjAttr, &UniStr, OBJ_CASE_INSENSITIVE, pFileObj->pParent->hDir, NULL /*pSecAttr*/); 4306 4397 … … 4354 4445 { 4355 4446 kHlpAssert(pCache->u32Magic == KFSOBJ_MAGIC); 4447 KFSCACHE_LOCK(pCache); 4448 4356 4449 pCache->auGenerationsMissing[0]++; 4357 4450 kHlpAssert(pCache->uGenerationMissing < KU32_MAX); 4451 4358 4452 KFSCACHE_LOG(("Invalidate missing %#x\n", pCache->auGenerationsMissing[0])); 4453 KFSCACHE_UNLOCK(pCache); 4359 4454 } 4360 4455 … … 4368 4463 { 4369 4464 kHlpAssert(pCache->u32Magic == KFSOBJ_MAGIC); 4465 KFSCACHE_LOCK(pCache); 4370 4466 4371 4467 pCache->auGenerationsMissing[0]++; … … 4382 4478 pCache->auGenerationsMissing[0], pCache->auGenerations[0], 4383 4479 pCache->auGenerationsMissing[1], pCache->auGenerations[1])); 4480 KFSCACHE_UNLOCK(pCache); 4384 4481 } 4385 4482 … … 4394 4491 { 4395 4492 kHlpAssert(pCache->u32Magic == KFSOBJ_MAGIC); 4493 KFSCACHE_LOCK(pCache); 4494 4396 4495 pCache->auGenerationsMissing[1]++; 4397 4496 kHlpAssert(pCache->auGenerationsMissing[1] < KU32_MAX); 4497 4398 4498 KFSCACHE_LOG(("Invalidate missing custom %#x\n", pCache->auGenerationsMissing[1])); 4499 KFSCACHE_UNLOCK(pCache); 4399 4500 } 4400 4501 … … 4410 4511 { 4411 4512 kHlpAssert(pCache->u32Magic == KFSOBJ_MAGIC); 4513 KFSCACHE_LOCK(pCache); 4514 4412 4515 pCache->auGenerations[1]++; 4413 4516 kHlpAssert(pCache->auGenerations[1] < KU32_MAX); 4414 4517 pCache->auGenerationsMissing[1]++; 4415 4518 kHlpAssert(pCache->auGenerationsMissing[1] < KU32_MAX); 4519 4416 4520 KFSCACHE_LOG(("Invalidate both custom %#x/%#x\n", pCache->auGenerationsMissing[1], pCache->auGenerations[1])); 4521 KFSCACHE_UNLOCK(pCache); 4417 4522 } 4418 4523 … … 4460 4565 if (pRoot) 4461 4566 { 4567 KFSCACHE_LOCK(pCache); 4462 4568 if (pRoot->bObjType == KFSOBJ_TYPE_DIR) 4463 4569 kFsCacheApplyFlagsToTree((PKFSDIR)pRoot, KU32_MAX, KFSOBJ_F_USE_CUSTOM_GEN); 4464 4570 else 4465 4571 pRoot->fFlags |= KFSOBJ_F_USE_CUSTOM_GEN; 4572 KFSCACHE_UNLOCK(pCache); 4466 4573 return K_TRUE; 4467 4574 } … … 4482 4589 KFSLOOKUPERROR enmError; 4483 4590 PKFSOBJ pFsObj; 4591 4592 KFSCACHE_LOCK(pCache); 4484 4593 4485 4594 /* Is absolute without any '..' bits? */ … … 4512 4621 pDir->fNeedRePopulating = K_TRUE; 4513 4622 pDir->Obj.uCacheGen = pCache->auGenerations[pDir->Obj.fFlags & KFSOBJ_F_USE_CUSTOM_GEN] - 1; 4514 kFsCacheObjRetainInternal(&pDir->Obj); 4623 kFsCacheObjRelease(pCache, &pDir->Obj); 4624 KFSCACHE_UNLOCK(pCache); 4515 4625 return K_TRUE; 4516 4626 } … … 4520 4630 KFSCACHE_LOG(("kFsCacheInvalidateDeletedDirectoryA: Trying to invalidate a non-directory: bObjType=%d %s\n", 4521 4631 pFsObj->bObjType, pszDir)); 4522 kFsCacheObjRe tainInternal(pFsObj);4632 kFsCacheObjRelease(pCache, pFsObj); 4523 4633 } 4524 4634 else 4525 4635 KFSCACHE_LOG(("kFsCacheInvalidateDeletedDirectoryA: '%s' was not found\n", pszDir)); 4636 KFSCACHE_UNLOCK(pCache); 4526 4637 return K_FALSE; 4527 4638 } … … 4598 4709 pCache->cbUtf16Paths = 0; 4599 4710 #endif 4711 4712 #ifdef KFSCACHE_CFG_LOCKING 4713 InitializeCriticalSection(&pCache->u.CritSect); 4714 #endif 4600 4715 return pCache; 4601 4716 } -
trunk/src/lib/nt/kFsCache.h
r2967 r3184 55 55 /** The max UTF-16 name length. */ 56 56 #define KFSCACHE_CFG_MAX_UTF16_NAME (256*2 + 16) 57 /** Enables locking of the cache and thereby making it thread safe. */ 58 #define KFSCACHE_CFG_LOCKING 1 57 59 58 60 … … 372 374 PKFSOBJ pFsObj; 373 375 } KFSHASHW; 376 #endif 377 378 379 /** @def KFSCACHE_LOCK 380 * Locks the cache exclusively. */ 381 /** @def KFSCACHE_UNLOCK 382 * Counterpart to KFSCACHE_LOCK. */ 383 #ifdef KFSCACHE_CFG_LOCKING 384 # define KFSCACHE_LOCK(a_pCache) EnterCriticalSection(&(a_pCache)->u.CritSect) 385 # define KFSCACHE_UNLOCK(a_pCache) LeaveCriticalSection(&(a_pCache)->u.CritSect) 386 #else 387 # define KFSCACHE_LOCK(a_pCache) do { } while (0) 388 # define KFSCACHE_UNLOCK(a_pCache) do { } while (0) 374 389 #endif 375 390 … … 440 455 KFSDIR RootDir; 441 456 457 #ifdef KFSCACHE_CFG_LOCKING 458 /** Critical section protecting the cache. */ 459 union 460 { 461 # ifdef _WINBASE_ 462 CRITICAL_SECTION CritSect; 463 # endif 464 KU64 abPadding[2 * 4 + 4 * sizeof(void *)]; 465 } u; 466 #endif 467 442 468 /** File system hash table for ANSI filename strings. */ 443 469 PKFSHASHA apAnsiPaths[KFSCACHE_CFG_PATH_HASH_TAB_SIZE];
Note:
See TracChangeset
for help on using the changeset viewer.