Exemplo n.º 1
0
        /// <summary>
        ///     Lock write lock.
        /// </summary>
        private void AcquireWriteLock()
        {
            if (ThreadLogUtil.ENABLED_TRACE) {
                ThreadLogUtil.TraceLock(ACQUIRE_TEXT + " write " + _name, Lock);
            }

            _writerLock = Lock.WriteLock.Acquire();

            if (ThreadLogUtil.ENABLED_TRACE) {
                ThreadLogUtil.TraceLock(ACQUIRED_TEXT + " write " + _name, Lock);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Lock read lock.
        /// </summary>
        public void AcquireReadLock()
        {
            if (ThreadLogUtil.ENABLED_TRACE) {
                ThreadLogUtil.TraceLock(ACQUIRE_TEXT + " read " + _name, Lock);
            }

            _readerLock = Lock.ReadLock.Acquire();

            if (ThreadLogUtil.ENABLED_TRACE) {
                ThreadLogUtil.TraceLock(ACQUIRED_TEXT + " read " + _name, Lock);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Unlock read lock.
        /// </summary>
        public void ReleaseReadLock()
        {
            if (ThreadLogUtil.ENABLED_TRACE) {
                ThreadLogUtil.TraceLock(RELEASE_TEXT + " read " + _name, Lock);
            }

            _readerLock.Dispose();
            _readerLock = null;

            if (ThreadLogUtil.ENABLED_TRACE) {
                ThreadLogUtil.TraceLock(RELEASED_TEXT + " read " + _name, Lock);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Try write lock with timeout, returning an indicator whether the lock was acquired or not.
        /// </summary>
        /// <param name="msec">number of milliseconds to wait for lock</param>
        /// <returns>indicator whether the lock could be acquired or not</returns>
        public bool TryWriteLock(long msec)
        {
            if (ThreadLogUtil.ENABLED_TRACE) {
                ThreadLogUtil.TraceLock(TRY_TEXT + " write " + _name, Lock);
            }

            try {
                _writerLock = Lock.WriteLock.Acquire(msec);
            }
            catch (ThreadInterruptedException) {
                Log.Warn("Lock wait interrupted");
            }

            if (ThreadLogUtil.ENABLED_TRACE) {
                ThreadLogUtil.TraceLock(TRY_TEXT + " write " + _name, Lock);
            }

            return true;
        }