Skip to content

Commit

Permalink
chore: add comment about concurrency of cache functions
Browse files Browse the repository at this point in the history
  • Loading branch information
egonspace committed May 21, 2021
1 parent 19d7180 commit 0c78434
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions x/params/types/subspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ func (s *Subspace) checkType(key []byte, value interface{}) {
}
}

// All the cache-related functions here are thread-safe.
// Currently, since `CheckTx` and `DeliverTx` can run without abci locking,
// these functions must be thread-safe as tx can run concurrently.
// The map data type is not thread-safe by itself, but concurrent access is
// possible with entry fixed. If we access the subspace with an unregistered key,
// it panics, ensuring that the entry of the map is not extended after the server runs.
// Value update and read operations for a single entry of a map can be performed concurrently by
// `atomic.StorePointer` and `atomic.LoadPointer`.
func (s *Subspace) cacheValue(key []byte, value interface{}) {
attr, ok := s.table.m[string(key)]
if !ok {
Expand Down

0 comments on commit 0c78434

Please sign in to comment.