You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In file stats.go, all code paths accessing (*counter).prev are protected with a mutex, yet every time the field is being accessed with an atomic Load/Store operation.
These are the possible code paths accessing the field, in reverse order:
(*counter).prev > (*counter).value [ReadWrite] >
(*counter).report > (*scope).report, protected by (*scope).cm.RLock
(*counter).cachedReport > (*scope).cachedReport, protected by (*scope).cm.RLock
(*histogram).report > (*scope).report, protected by (*scope).hm.RLock
(*histogram).cachedReport > (*scope).cachedReport, protected by (*scope).hm.RLock
(*counter).prev > (*counter).snapshot [Read] >
(*scope).Snapshot, protected by (*scope).cm.RLock
(*histogram).snapshotValues > (*scope).Snapshot, protected by (*scope).hm.RLock
(*histogram).snapshotDurations > (*scope).Snapshot, protected by (*scope).hm.RLock
Note that:
A (*histogram) can have multiple (*counter) but only its methods access them, i.e. clients of (*histogram) only use its methods, not its fields.
There's no background forking in any of the methods, so e.g. (*scope).Snapshot would work sequentially inside the (R)Lock/(R)Unlock blocks of each mutex.
So (*counter).prev is always protected by a mutex, there's no need for atomic operations to access it.
The text was updated successfully, but these errors were encountered:
In file
stats.go
, all code paths accessing(*counter).prev
are protected with a mutex, yet every time the field is being accessed with an atomic Load/Store operation.These are the possible code paths accessing the field, in reverse order:
(*counter).prev
>(*counter).value
[ReadWrite] >(*counter).report
>(*scope).report
, protected by(*scope).cm.RLock
(*counter).cachedReport
>(*scope).cachedReport
, protected by(*scope).cm.RLock
(*histogram).report
>(*scope).report
, protected by(*scope).hm.RLock
(*histogram).cachedReport
>(*scope).cachedReport
, protected by(*scope).hm.RLock
(*counter).prev
>(*counter).snapshot
[Read] >(*scope).Snapshot
, protected by(*scope).cm.RLock
(*histogram).snapshotValues
>(*scope).Snapshot
, protected by(*scope).hm.RLock
(*histogram).snapshotDurations
>(*scope).Snapshot
, protected by(*scope).hm.RLock
Note that:
(*histogram)
can have multiple(*counter)
but only its methods access them, i.e. clients of(*histogram)
only use its methods, not its fields.(*scope).Snapshot
would work sequentially inside the (R)Lock/(R)Unlock blocks of each mutex.So
(*counter).prev
is always protected by a mutex, there's no need for atomic operations to access it.The text was updated successfully, but these errors were encountered: