コード例 #1
0
            private LockingDictionary <StorageKey, ObjectDecorator> GetSingleKeySpace(DataBuffer keySpace)
            {
                var hash = keySpace.GetHashCode();
                LockingDictionary <StorageKey, ObjectDecorator> keySpaceDct;

                // upgradeable blocks other upgradeable, so try read first
                using (_keySpaces.Lock(LockType.Read))
                {
                    if (_keySpaces.TryGetValue(hash, out keySpaceDct))
                    {
                        return(keySpaceDct);
                    }
                }
                // didn't find it, so now try upgradeable to write if need be
                using (_keySpaces.Lock(LockType.ReadUpgradable))
                {
                    if (!_keySpaces.TryGetValue(hash, out keySpaceDct))
                    {
                        using (_keySpaces.Lock(LockType.Write))
                        {
                            keySpaceDct = new LockingDictionary <StorageKey, ObjectDecorator>();
                            _keySpaces.Add(hash, keySpaceDct);
                        }
                    }
                    return(keySpaceDct);
                }
            }