From: Jeffrey Altman Date: Fri, 19 Oct 2012 15:26:21 +0000 (-0400) Subject: Windows: ObjectInfo RefCount 0 <-> 1 transitions X-Git-Tag: upstream/1.8.0_pre1^2~1880 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=5857dd36b2b129fd2cf187650723b896c24f5177;p=packages%2Fo%2Fopenafs.git Windows: ObjectInfo RefCount 0 <-> 1 transitions When the reference count transitions from 0 <-> 1 ensure that the ObjectInfoLock is held exclusive to prevent the current thread from altering the state while another thread is holding the ObjectInfoLock shared in order to conditionally perform an action based upon the the reference count being zero. Change-Id: I5bcf384a0ea90e4896e55b537e92112ac3791a4c Reviewed-on: http://gerrit.openafs.org/8257 Reviewed-by: Rod Widdowson Tested-by: BuildBot Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- diff --git a/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp b/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp index fc85688c0..6a7a9388d 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp @@ -6543,10 +6543,31 @@ AFSObjectInfoIncrement( IN AFSObjectInfoCB *ObjectInfo) LONG lCount; - AFSAcquireShared( &ObjectInfo->NonPagedInfo->ObjectInfoLock, - TRUE); + if ( ObjectInfo->ObjectReferenceCount == 0) + { + + AFSAcquireExcl( &ObjectInfo->NonPagedInfo->ObjectInfoLock, + TRUE); + + lCount = InterlockedIncrement( &ObjectInfo->ObjectReferenceCount); + } + else + { + + AFSAcquireShared( &ObjectInfo->NonPagedInfo->ObjectInfoLock, + TRUE); + + lCount = InterlockedIncrement( &ObjectInfo->ObjectReferenceCount); + + if ( lCount == 1) + { - lCount = InterlockedIncrement( &ObjectInfo->ObjectReferenceCount); + AFSReleaseResource( &ObjectInfo->NonPagedInfo->ObjectInfoLock); + + AFSAcquireExcl( &ObjectInfo->NonPagedInfo->ObjectInfoLock, + TRUE); + } + } AFSReleaseResource( &ObjectInfo->NonPagedInfo->ObjectInfoLock); @@ -6564,6 +6585,19 @@ AFSObjectInfoDecrement( IN AFSObjectInfoCB *ObjectInfo) lCount = InterlockedDecrement( &ObjectInfo->ObjectReferenceCount); + if ( lCount == 0) + { + + lCount = InterlockedIncrement( &ObjectInfo->ObjectReferenceCount); + + AFSReleaseResource(&ObjectInfo->NonPagedInfo->ObjectInfoLock); + + AFSAcquireExcl( &ObjectInfo->NonPagedInfo->ObjectInfoLock, + TRUE); + + lCount = InterlockedDecrement( &ObjectInfo->ObjectReferenceCount); + } + AFSReleaseResource( &ObjectInfo->NonPagedInfo->ObjectInfoLock); return lCount;