github.com/haliliceylan/bsc@v1.1.10-0.20220501224556-eb78d644ebcb/core/state/shared_pool.go (about) 1 package state 2 3 import ( 4 "sync" 5 6 "github.com/ethereum/go-ethereum/common" 7 ) 8 9 // sharedPool is used to store maps of originStorage of stateObjects 10 type StoragePool struct { 11 sync.RWMutex 12 sharedMap map[common.Address]*sync.Map 13 } 14 15 func NewStoragePool() *StoragePool { 16 sharedMap := make(map[common.Address]*sync.Map) 17 return &StoragePool{ 18 sync.RWMutex{}, 19 sharedMap, 20 } 21 } 22 23 // getStorage Check whether the storage exist in pool, 24 // new one if not exist, the content of storage will be fetched in stateObjects.GetCommittedState() 25 func (s *StoragePool) getStorage(address common.Address) *sync.Map { 26 s.RLock() 27 storageMap, ok := s.sharedMap[address] 28 s.RUnlock() 29 if !ok { 30 s.Lock() 31 defer s.Unlock() 32 if storageMap, ok = s.sharedMap[address]; !ok { 33 m := new(sync.Map) 34 s.sharedMap[address] = m 35 return m 36 } 37 } 38 return storageMap 39 }