Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DisposableReaderWriter"/> class.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="type">The type.</param>
        public DisposableReaderWriter(IExposesReaderWriterLock root, ReaderWriterLockSynchronizeType type)
        {
            m_Root            = root;
            m_SynchronizeType = type;

            AcquireLock();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DisposableLockGrabber"/> class.
        /// </summary>
        /// <param name="rwlock">The rwlock.</param>
        /// <param name="type">The type.</param>
        /// <param name="timeoutMilliseconds">The timeout milliseconds.</param>
        public DisposableLockGrabber(ReaderWriterLock rwlock, ReaderWriterLockSynchronizeType type, int timeoutMilliseconds)
        {
            m_rwlock = rwlock;
            m_type = type;

            DoLock(timeoutMilliseconds);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DisposableReaderWriter"/> class.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="type">The type.</param>
        public DisposableReaderWriter(IExposesReaderWriterLock root, ReaderWriterLockSynchronizeType type)
        {
            m_Root = root;
            m_SynchronizeType = type;

            AcquireLock();
        }
 /// <summary>
 /// Downgrades from writer lock.
 /// </summary>
 public virtual void DowngradeFromWriterLock()
 {
     if (m_UpgradeLockCookie != null)
     {
         m_SynchronizeType = ReaderWriterLockSynchronizeType.Read;
         LockCookie tempCookie = m_UpgradeLockCookie.Value;
         m_Root.Sync.DowngradeFromWriterLock(ref tempCookie);
         m_UpgradeLockCookie = null;
     }
 }
        /// <summary>
        /// This can only be used if there will be no other static calls to this method within the
        /// context of this call on this thread.
        /// </summary>
        /// <param name="rwlock">The rwlock.</param>
        /// <param name="type">The type.</param>
        /// <param name="timeoutMilliseconds">The timeout milliseconds.</param>
        /// <returns></returns>
        public static DisposableLockGrabber GetLock(ReaderWriterLock rwlock, ReaderWriterLockSynchronizeType type, int timeoutMilliseconds)
        {
            // This is because there is only one instance per thread
            if (s_lock == null)
            {
                s_lock = new DisposableLockGrabber();
            }

            s_lock.m_rwlock = rwlock;
            s_lock.m_type = type;

            s_lock.DoLock(timeoutMilliseconds);

            return s_lock;
        }
 /// <summary>
 /// This can only be used if there will be no other static calls to this method within the
 /// context of this call on this thread.
 /// </summary>
 /// <param name="rwlock">The rwlock.</param>
 /// <param name="type">The type.</param>
 /// <returns></returns>
 public static DisposableLockGrabber GetLock(ReaderWriterLock rwlock, ReaderWriterLockSynchronizeType type)
 {
     return GetLock(rwlock, type, -1);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DisposableLockGrabber"/> class.
 /// </summary>
 /// <param name="rwlock">The rwlock.</param>
 /// <param name="type">The type.</param>
 public DisposableLockGrabber(ReaderWriterLock rwlock, ReaderWriterLockSynchronizeType type)
     : this(rwlock, type, -1)
 {
 }
 /// <summary>
 /// Upgrades to writer lock.
 /// </summary>
 public virtual void UpgradeToWriterLock()
 {
     m_SynchronizeType = ReaderWriterLockSynchronizeType.Write;
     m_UpgradeLockCookie = m_Root.Sync.UpgradeToWriterLock(DefaultLockTimeout);
 }