From: Jeffrey Altman Date: Mon, 14 Nov 2011 22:49:45 +0000 (-0500) Subject: Windows: interlocked refCount increment in cm_GetSCache X-Git-Tag: upstream/1.8.0_pre1^2~3041 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=c4d19e5d4271a31fd29c111fb27d145dc83b83b7;p=packages%2Fo%2Fopenafs.git Windows: interlocked refCount increment in cm_GetSCache Failure to use interlocked operations in cm_GetSCache can result in an under count Change-Id: I370bcb9ac8b40f1c1b7ea3b7647fc76e3a554e2c Reviewed-on: http://gerrit.openafs.org/6046 Tested-by: BuildBot Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman --- diff --git a/src/WINNT/afsd/cm_scache.c b/src/WINNT/afsd/cm_scache.c index e55690865..9410c7fcd 100644 --- a/src/WINNT/afsd/cm_scache.c +++ b/src/WINNT/afsd/cm_scache.c @@ -680,6 +680,7 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp, int special = 0; // yj: boolean variable to test if file is on root.afs int isRoot = 0; extern cm_fid_t cm_rootFid; + afs_int32 refCount; hash = CM_SCACHE_HASH(fidp); @@ -766,8 +767,8 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp, cm_data.scacheHashTablep[hash] = scp; _InterlockedOr(&scp->flags, CM_SCACHEFLAG_INHASH); } - scp->refCount = 1; - osi_Log1(afsd_logp,"cm_GetSCache (freelance) sets refCount to 1 scp 0x%p", scp); + refCount = InterlockedIncrement(&scp->refCount); + osi_Log2(afsd_logp,"cm_GetSCache (freelance) sets refCount to 1 scp 0x%p refCount %d", scp, refCount); lock_ReleaseWrite(&cm_scacheLock); /* must be called after the scp->fid is set */ @@ -889,13 +890,13 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp, scp->nextp = cm_data.scacheHashTablep[hash]; cm_data.scacheHashTablep[hash] = scp; _InterlockedOr(&scp->flags, CM_SCACHEFLAG_INHASH); + refCount = InterlockedIncrement(&scp->refCount); lock_ReleaseWrite(&cm_scacheLock); lock_ReleaseWrite(&scp->rw); - scp->refCount = 1; #ifdef DEBUG_REFCOUNT - afsi_log("%s:%d cm_GetSCache sets refCount to 1 scp 0x%p", file, line, scp); + afsi_log("%s:%d cm_GetSCache sets refCount to 1 scp 0x%p refCount %d", file, line, scp, refCount); #endif - osi_Log1(afsd_logp,"cm_GetSCache sets refCount to 1 scp 0x%p", scp); + osi_Log2(afsd_logp,"cm_GetSCache sets refCount to 1 scp 0x%p refCount %d", scp, refCount); /* XXX - The following fields in the cm_scache are * uninitialized: