Ignore:
Timestamp:
Jun 8, 2020, 9:28:44 PM (5 years ago)
Author:
bird
Message:

kFsCache: Don't need to lock the whole cache when using kFsCacheObjAddUserData and kFsCacheObjGetUserData. Fixed incorrect debug hack checking that we don't release objects while they are in the path hash structures.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/nt/kFsCache.h

    r3359 r3362  
    161161    /** Set if the Stats member is valid, clear if not. */
    162162    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;
    165168    /** Flags, KFSOBJ_F_XXX. */
    166169    KU32                fFlags;
     
    381384/** @def KFSCACHE_UNLOCK
    382385 *  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. */
    383390#ifdef KFSCACHE_CFG_LOCKING
    384391# define KFSCACHE_LOCK(a_pCache)        EnterCriticalSection(&(a_pCache)->u.CritSect)
    385392# 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)
    386404#else
    387405# define KFSCACHE_LOCK(a_pCache)        do { } while (0)
    388406# 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)
    389409#endif
    390410
     
    456476
    457477#ifdef KFSCACHE_CFG_LOCKING
    458     /** Critical section protecting the cache. */
    459478    union
    460479    {
     
    463482# endif
    464483        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;
    466492#endif
    467493
     
    544570PKFSUSERDATA kFsCacheObjAddUserData(PKFSCACHE pCache, PKFSOBJ pObj, KUPTR uKey, KSIZE cbUserData);
    545571PKFSUSERDATA kFsCacheObjGetUserData(PKFSCACHE pCache, PKFSOBJ pObj, KUPTR uKey);
     572KU8         kFsCacheObjGetUserDataLockIndex(PKFSCACHE pCache, PKFSOBJ pObj);
    546573KBOOL       kFsCacheObjGetFullPathA(PKFSOBJ pObj, char *pszPath, KSIZE cbPath, char chSlash);
    547574KBOOL       kFsCacheObjGetFullPathW(PKFSOBJ pObj, wchar_t *pwszPath, KSIZE cwcPath, wchar_t wcSlash);
Note: See TracChangeset for help on using the changeset viewer.