示例#1
0
        /// <summary />
        public ReaderLock(Guid id, string traceInfo)
        {
            this.LockTime = -1;
            m_Lock        = LockingManager.GetLocker(id);

            this.ReadLockCount       = m_Lock.CurrentReadCount;
            this.WaitingLocksOnEntry = m_Lock.WaitingWriteCount;
            if (this.WaitingLocksOnEntry > 10)
            {
                Logger.LogWarning("Waiting Writer Locks: Count=" + this.WaitingLocksOnEntry + ", RepositoryId=" + id);
            }

            if (!m_Lock.TryEnterReadLock(TimeOut))
            {
                _inError = true;

                throw new Exception("Could not get reader lock: " +
                                    ((m_Lock.ObjectId == Guid.Empty) ? string.Empty : "ID=" + m_Lock.ObjectId) +
                                    ", CurrentReadCount=" + m_Lock.CurrentReadCount +
                                    ", WaitingReadCount=" + m_Lock.WaitingReadCount +
                                    ", WaitingWriteCount=" + m_Lock.WaitingWriteCount +
                                    ", HoldingThread=" + m_Lock.HoldingThreadId +
                                    ", TraceInfo=" + m_Lock.TraceInfo +
                                    ", LockFailTime=" + (int)DateTime.Now.Subtract(_initTime).TotalMilliseconds +
                                    ", WriteHeldTime=" + m_Lock.WriteHeldTime);
            }

            this.LockTime          = (int)DateTime.Now.Subtract(_initTime).TotalMilliseconds;
            m_Lock.TraceInfo       = traceInfo;
            m_Lock.HoldingThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
        }
示例#2
0
        public WriterLock(Guid id, string traceInfo)
        {
            if (id == Guid.Empty)
            {
                return;
            }

            m_Lock = LockingManager.GetLocker(id);

            this.ReadLockCount       = m_Lock.CurrentReadCount;
            this.WaitingLocksOnEntry = m_Lock.WaitingWriteCount;
            if (this.WaitingLocksOnEntry > 10)
            {
                Logger.LogWarning("Waiting Writer Locks: Count=" + this.WaitingLocksOnEntry + ", RepositoryId=" + id);
            }

            if (!m_Lock.TryEnterWriteLock(TimeOut))
            {
                _inError = true;

                var lapses = string.Join("-", m_Lock.HeldReads.Values.ToList().Select(x => (int)DateTime.Now.Subtract(x).TotalSeconds).ToList());
                throw new Exception("Could not get writer lock: " +
                                    ((m_Lock.ObjectId == Guid.Empty) ? string.Empty : "ID=" + m_Lock.ObjectId) +
                                    ", CurrentReadCount=" + m_Lock.CurrentReadCount +
                                    ", WaitingReadCount=" + m_Lock.WaitingReadCount +
                                    ", WaitingWriteCount=" + m_Lock.WaitingWriteCount +
                                    ", HoldingThread=" + m_Lock.HoldingThreadId +
                                    ", TraceInfo=" + m_Lock.TraceInfo +
                                    ", WriteHeldTime=" + m_Lock.WriteHeldTime +
                                    ", LockFailTime=" + (int)DateTime.Now.Subtract(_initTime).TotalMilliseconds +
                                    ", Lapses=" + lapses);
            }

            this.LockTime            = (int)DateTime.Now.Subtract(_initTime).TotalMilliseconds;
            m_Lock.TraceInfo         = traceInfo;
            m_Lock.WriteLockHeldTime = DateTime.Now;
            m_Lock.HoldingThreadId   = System.Threading.Thread.CurrentThread.ManagedThreadId;
        }