public void Update <T>(IStorageHandle handleIn, ISerializer <T> serializer, T node)
        {
            InvalidNodeHandleException.Assert(handleIn is MyStorageHandle);
            MyStorageHandle handle = (MyStorageHandle)handleIn;

            handle.Node = node;
        }
        public void Destroy(IStorageHandle handleIn)
        {
            InvalidNodeHandleException.Assert(handleIn is MyStorageHandle);
            MyStorageHandle handle = (MyStorageHandle)handleIn;

            handle.Clear();
        }
Exemplo n.º 3
0
            private NodePin LockInternal(NodePin parent, LockType ltype, NodeHandle child, bool ignoreHandleComparison)
            {
                CacheEntry entry = GetCache(child, false);

                LockType locked = NoLock;

                if (ltype == LockType.Read && entry.Lock.TryRead(base.Options.LockTimeout))
                {
                    locked = LockType.Read;
                }
                if (ltype != LockType.Read && entry.Lock.TryWrite(base.Options.LockTimeout))
                {
                    locked = ltype;
                }

                DeadlockException.Assert(locked != NoLock);
                try
                {
                    Node node = entry.Node;
                    if (node == null)
                    {
                        using (new SafeLock <DeadlockException>(entry))
                        {
                            node = entry.Node;
                            if (node == null)
                            {
                                InvalidNodeHandleException.Assert(
                                    Storage.TryGetNode(child.StoreHandle, out node, NodeSerializer) && node != null &&
                                    ignoreHandleComparison
                                        ? true
                                        : node.StorageHandle.Equals(entry.Handle.StoreHandle));



                                Node old = Interlocked.CompareExchange(ref entry.Node, node, null);
                                Assert(null == old, "Collision on cache load.");
                            }
                        }
                    }
                    return(new NodePin(child, entry.Lock, ltype, locked, entry, node, null));
                }
                catch
                {
                    if (locked == LockType.Read)
                    {
                        entry.Lock.ReleaseRead();
                    }
                    else if (locked != NoLock)
                    {
                        entry.Lock.ReleaseWrite();
                    }
                    throw;
                }
            }
        public bool TryGetNode <TNode>(IStorageHandle handleIn, out TNode node, ISerializer <TNode> serializer)
        {
            InvalidNodeHandleException.Assert(handleIn is MyStorageHandle);
            MyStorageHandle handle = (MyStorageHandle)handleIn;

            if (handle.Node != null)
            {
                node = (TNode)handle.Node;
                return(true);
            }
            node = default(TNode);
            return(false);
        }