コード例 #1
0
            public override ILockStrategy CreateLock(NodeHandle handle, out object refobj)
            {
                NodeWithLock nlck = new NodeWithLock(null, LockFactory.Create());

                handle.SetCacheEntry(nlck);
                refobj = nlck;
                bool acquired = nlck.Lock.TryWrite(base.Options.LockTimeout);

                DeadlockException.Assert(acquired);
                return(nlck.Lock);
            }
コード例 #2
0
            protected override NodePin Lock(NodePin parent, LockType ltype, NodeHandle child)
            {
                NodeWithLock nlck;

                if (!child.TryGetCache(out nlck))
                {
                    child.SetCacheEntry(nlck = new NodeWithLock(null, LockFactory.Create()));
                }

                bool acquired;

                if (ltype == LockType.Read)
                {
                    acquired = nlck.Lock.TryRead(base.Options.LockTimeout);
                }
                else
                {
                    acquired = nlck.Lock.TryWrite(base.Options.LockTimeout);
                }
                DeadlockException.Assert(acquired);
                try
                {
                    if (nlck.Node == null)
                    {
                        using (new SafeLock <DeadlockException>(nlck, base.Options.LockTimeout))
                            Storage.TryGetNode(child.StoreHandle, out nlck.Node, NodeSerializer);
                    }

                    Assert(nlck.Node != null);
                    return(new NodePin(child, nlck.Lock, ltype, ltype, nlck, nlck.Node, null));
                }
                catch
                {
                    if (ltype == LockType.Read)
                    {
                        nlck.Lock.ReleaseRead();
                    }
                    else
                    {
                        nlck.Lock.ReleaseWrite();
                    }
                    throw;
                }
            }