Stores the lock state of a ReaderWriterLock before its lock state is changed, such that the lock state may later be restored.
 public static void Animate(Image image, EventHandler onFrameChangedHandler)
 {
     if (image != null)
     {
         ImageInfo item = null;
         lock (image)
         {
             item = new ImageInfo(image);
         }
         StopAnimate(image, onFrameChangedHandler);
         bool isReaderLockHeld = rwImgListLock.IsReaderLockHeld;
         LockCookie lockCookie = new LockCookie();
         threadWriterLockWaitCount++;
         try
         {
             if (isReaderLockHeld)
             {
                 lockCookie = rwImgListLock.UpgradeToWriterLock(-1);
             }
             else
             {
                 rwImgListLock.AcquireWriterLock(-1);
             }
         }
         finally
         {
             threadWriterLockWaitCount--;
         }
         try
         {
             if (item.Animated)
             {
                 if (imageInfoList == null)
                 {
                     imageInfoList = new List<ImageInfo>();
                 }
                 item.FrameChangedHandler = onFrameChangedHandler;
                 imageInfoList.Add(item);
                 if (animationThread == null)
                 {
                     animationThread = new Thread(new ThreadStart(ImageAnimator.AnimateImages50ms));
                     animationThread.Name = typeof(ImageAnimator).Name;
                     animationThread.IsBackground = true;
                     animationThread.Start();
                 }
             }
         }
         finally
         {
             if (isReaderLockHeld)
             {
                 rwImgListLock.DowngradeFromWriterLock(ref lockCookie);
             }
             else
             {
                 rwImgListLock.ReleaseWriterLock();
             }
         }
     }
 }
예제 #2
0
        private void LockAndGet <T>(T data)
        {
            try {
                //ロックを取得する
                _rwLock.AcquireReaderLock(_timeout);

                //Double-Checked Lockingパターン
                if (data == null)
                {
                    System.Threading.LockCookie aLockCookie = default(System.Threading.LockCookie);
                    try {
                        aLockCookie = _rwLock.UpgradeToWriterLock(_timeout);
                        if (data == null)
                        {
                            _callFromMe = true;
                            //初期化用SELECT文を発行し、同じViewInfoに属する他全てのView列と共にメタ情報を取得する
                            _aViewInfo.RegistAllColumnsType();
                        }
                    } finally {
                        _callFromMe = false;
                        _rwLock.DowngradeFromWriterLock(ref aLockCookie);
                    }
                }

                //RegistAllColumnsType()で登録した値は仮引数であるdataには反映されないことに注意
                //Return data
            } finally {
                //ロックを開放する
                _rwLock.ReleaseReaderLock();
            }
        }
예제 #3
0
        public LockCookie UpgradeToWriterLock(int millisecondsTimeout)
        {
            LockCookie result = new LockCookie();

            this.FCallUpgradeToWriterLock(ref result, millisecondsTimeout);
            return(result);
        }
예제 #4
0
 /// <summary>
 /// Execute the action under a write lock
 /// </summary>
 /// <param name="cacheAction">The cache action.</param>
 public void WriteLock(CacheAction cacheAction)
 {
     if(readerWriterLock.IsWriterLockHeld)
     {
         cacheAction();
         return;
     }
     bool readerLockHeld = readerWriterLock.IsReaderLockHeld;
     LockCookie writerLock = new LockCookie();
     if (readerLockHeld)
     {
         writerLock = readerWriterLock.UpgradeToWriterLock(Timeout.Infinite);
     }
     else
         readerWriterLock.AcquireWriterLock(Timeout.Infinite);
     try
     {
         cacheAction();
     }
     finally
     {
         if (readerLockHeld)
             readerWriterLock.DowngradeFromWriterLock(ref writerLock);
         else
             readerWriterLock.ReleaseWriterLock();
     }
 }
예제 #5
0
        public LockCookie ReleaseLock()
        {
            LockCookie result = new LockCookie();

            this.FCallReleaseLock(ref result);
            return(result);
        }
예제 #6
0
 /// <summary>指定当前实例是否等于指定的 <see cref="T:System.Threading.LockCookie" />。</summary>
 /// <returns>如果 <paramref name="obj" /> 等于当前实例的值,则为 true;否则为 false。</returns>
 /// <param name="obj">要与当前实例进行比较的 <see cref="T:System.Threading.LockCookie" />。</param>
 public bool Equals(LockCookie obj)
 {
     if (obj._dwFlags == this._dwFlags && obj._dwWriterSeqNum == this._dwWriterSeqNum && obj._wReaderAndWriterLevel == this._wReaderAndWriterLevel)
     {
         return(obj._dwThreadID == this._dwThreadID);
     }
     return(false);
 }
예제 #7
0
 public bool Equals(LockCookie obj)
 {
     return
         (_flags == obj._flags &&
          _readerLevel == obj._readerLevel &&
          _writerLevel == obj._writerLevel &&
          _threadID == obj._threadID);
 }
예제 #8
0
 public static void Fade(object caller, EventHandler onFadeChangedHandler)
 {
     if (caller != null)
     {
         FadeAnimator.FadeInfo fadeInfo = null;
         lock (caller)
         {
             fadeInfo = new FadeAnimator.FadeInfo(caller);
         }
         FadeAnimator.StopFade(caller, onFadeChangedHandler);
         bool flag1 = FadeAnimator.rwImgListLock.IsReaderLockHeld;
         LockCookie cookie1 = new LockCookie();
         FadeAnimator.threadWriterLockWaitCount++;
         try
         {
             if (flag1)
             {
                 cookie1 = FadeAnimator.rwImgListLock.UpgradeToWriterLock(-1);
             }
             else
             {
                 FadeAnimator.rwImgListLock.AcquireWriterLock(-1);
             }
         }
         finally
         {
             FadeAnimator.threadWriterLockWaitCount--;
         }
         try
         {
             if (FadeAnimator.fadeInfoList == null)
             {
                 FadeAnimator.fadeInfoList = new ArrayList();
             }
             fadeInfo.FadeChangedHandler = onFadeChangedHandler;
             FadeAnimator.fadeInfoList.Add((FadeAnimator.FadeInfo)fadeInfo);
             if (FadeAnimator.fadeThread == null)
             {
                 FadeAnimator.fadeThread = new Thread(new ThreadStart(FadeAnimator.AnimateFade50ms));
                 FadeAnimator.fadeThread.Name = typeof(FadeAnimator).Name;
                 FadeAnimator.fadeThread.IsBackground = true;
                 FadeAnimator.fadeThread.Start();
             }
         }
         finally
         {
             if (flag1)
             {
                 FadeAnimator.rwImgListLock.DowngradeFromWriterLock(ref cookie1);
             }
             else
             {
                 FadeAnimator.rwImgListLock.ReleaseWriterLock();
             }
         }
     }
 }
예제 #9
0
파일: LockCookie.cs 프로젝트: raj581/Marvin
		public bool Equals (LockCookie obj)
		{
			if (this.ThreadId == obj.ThreadId &&
			    this.ReaderLocks == obj.ReaderLocks &&
			    this.WriterLocks == obj.WriterLocks) {
				return(true);
			} else {
				return(false);
			}
		}
예제 #10
0
 public void RestoreLock(ref LockCookie lockCookie)
 {
     lock (this) {
         if (lockCookie.WriterLocks != 0)
         {
             AcquireWriterLock(-1, lockCookie.WriterLocks);
         }
         else if (lockCookie.ReaderLocks != 0)
         {
             AcquireReaderLock(-1, lockCookie.ReaderLocks);
         }
     }
 }
예제 #11
0
 /// <summary>Restores the lock status of the thread to what it was before <see cref="M:System.Threading.ReaderWriterLock.UpgradeToWriterLock(System.Int32)" /> was called.</summary>
 /// <param name="lockCookie">A <see cref="T:System.Threading.LockCookie" /> returned by <see cref="M:System.Threading.ReaderWriterLock.UpgradeToWriterLock(System.Int32)" />. </param>
 /// <exception cref="T:System.ApplicationException">The thread does not have the writer lock. </exception>
 /// <exception cref="T:System.NullReferenceException">The address of <paramref name="lockCookie" /> is a null pointer. </exception>
 /// <filterpriority>2</filterpriority>
 public void DowngradeFromWriterLock(ref LockCookie lockCookie)
 {
     lock (this)
     {
         if (!this.HasWriterLock())
         {
             throw new ApplicationException("The thread does not have the writer lock.");
         }
         this.state = lockCookie.ReaderLocks;
         this.reader_locks[Thread.CurrentThreadId] = this.state;
         if (this.readers > 0)
         {
             Monitor.PulseAll(this);
         }
     }
 }
 private void AcquireLock()
 {
     switch (_mode)
     {
         case LockMode.Read:
             _lock.AcquireReaderLock(_timeout);
             break;
         case LockMode.UpgrateToWrite:
             _cookie = _lock.UpgradeToWriterLock(_timeout);
             break;
         case LockMode.Write:
             _lock.AcquireWriterLock(_timeout);
             break;
     }
     Logger.TraceFormat("lock {0} acured", _mode);
 }
예제 #13
0
        public LockingObject(ReaderWriterLock _lock, AccessMode _lockMode)
        {
            this.readerWriterLock = _lock;
            this.accessMode = _lockMode;

            if (this.accessMode == AccessMode.Read)
            {
                this.readerWriterLock.AcquireReaderLock(-1);
            }
            else if (this.accessMode == AccessMode.Write)
            {
                this.readerWriterLock.AcquireWriterLock(-1);
            }
            else //UpAndDowngrade
            {
                this.lockCookie = this.readerWriterLock.UpgradeToWriterLock(-1);
            }
        }
예제 #14
0
        LockCookie GetLockCookie()
        {
            LockCookie cookie = new LockCookie(Thread.CurrentThreadId);

            if (HasWriterLock())
            {
                cookie.WriterLocks = -state;
            }
            else
            {
                object locks = reader_locks [Thread.CurrentThreadId];
                if (locks != null)
                {
                    cookie.ReaderLocks = (int)locks;
                }
            }
            return(cookie);
        }
예제 #15
0
        private LockCookie GetLockCookie()
        {
            LockCookie result = new LockCookie(Thread.CurrentThreadId);

            if (this.HasWriterLock())
            {
                result.WriterLocks = -this.state;
            }
            else
            {
                object obj = this.reader_locks[Thread.CurrentThreadId];
                if (obj != null)
                {
                    result.ReaderLocks = (int)obj;
                }
            }
            return(result);
        }
예제 #16
0
        public void DowngradeFromWriterLock(ref LockCookie lockCookie)
        {
            lock (this) {
                if (!HasWriterLock())
                {
                    throw new ApplicationException("The thread does not have the writer lock.");
                }

                state = lockCookie.ReaderLocks;
                reader_locks [Thread.CurrentThreadId] = state;
                if (readers > 0)
                {
                    Monitor.PulseAll(this);
                }

                // MSDN: A thread does not block when downgrading from the writer lock,
                // even if other threads are waiting for the writer lock
            }
        }
예제 #17
0
 public void Remove(IPAddr ip)
 {
     try
     {
         locker.AcquireReaderLock(new TimeSpan(0, 1, 0));
         try
         {
             if (list.ContainsKey(ip))
             {
                 LockCookie lc = new LockCookie();
                 try
                 {
                     lc = locker.UpgradeToWriterLock(new TimeSpan(0, 1, 0));
                     try
                     {
                         list.Remove(ip);
                     }
                     finally
                     {
                         locker.DowngradeFromWriterLock(ref lc);
                     }
                 }
                 catch (ApplicationException e)
                 {
                     Logging.LogCenter.Instance.LogException(e);
                 }
             }
         }
         finally
         {
             locker.ReleaseReaderLock();
         }
     }
     catch (ApplicationException aex)
     {
         Logging.LogCenter.Instance.LogException(aex);
     }
 }
예제 #18
0
		public static void UnregisterMessageClient(IMessageHandlerClient client)
		{
            if (m_Clients.Contains(client))
            {
                LockCookie cookie1 = new LockCookie();
                bool readerLockHeld = MessageHandler.rwClientsListLock.IsReaderLockHeld;

                if (readerLockHeld)
                {
                    cookie1 = MessageHandler.rwClientsListLock.UpgradeToWriterLock(-1);
                }
                else
                {
                    MessageHandler.rwClientsListLock.AcquireWriterLock(-1);
                }
                bool unregister = false;
                try
                {
                    m_Clients.Remove(client);
                    unregister = m_Clients.Count == 0;
                }
                finally
                {
                    if (readerLockHeld)
                    {
                        MessageHandler.rwClientsListLock.DowngradeFromWriterLock(ref cookie1);
                    }
                    else
                    {
                        MessageHandler.rwClientsListLock.ReleaseWriterLock();
                    }
                }

                if (BarUtilities.AutoRemoveMessageFilter && unregister && m_FilterOnThread.ContainsKey(System.Threading.Thread.CurrentThread.GetHashCode()))
                    UninstallMessageFilter();
            }
		}
예제 #19
0
        public static void RegisterHook(ISkinHook client)
        {
            if (m_Clients.Contains(client))
                return;

            if (!m_FilterOnThread.ContainsKey(System.Threading.Thread.CurrentThread.GetHashCode()))
                HookThread();

            LockCookie cookie1 = new LockCookie();
            bool readerLockHeld = NonClientHook.rwClientsListLock.IsReaderLockHeld;

            if (readerLockHeld)
            {
                cookie1 = NonClientHook.rwClientsListLock.UpgradeToWriterLock(-1);
            }
            else
            {
                NonClientHook.rwClientsListLock.AcquireWriterLock(-1);
            }

            try
            {
                m_Clients.Add(client);
            }
            finally
            {
                if (readerLockHeld)
                {
                    NonClientHook.rwClientsListLock.DowngradeFromWriterLock(ref cookie1);
                }
                else
                {
                    NonClientHook.rwClientsListLock.ReleaseWriterLock();
                }
            }
        }
예제 #20
0
		public static void RegisterMessageClient(IMessageHandlerClient client)
		{
			if(m_Clients.Contains(client))
				return;

			if(!m_FilterOnThread.ContainsKey(System.Threading.Thread.CurrentThread.GetHashCode()))
				InstallMessageFilter();

            LockCookie cookie1 = new LockCookie();
            bool readerLockHeld = MessageHandler.rwClientsListLock.IsReaderLockHeld;

            if (readerLockHeld)
            {
                cookie1 = MessageHandler.rwClientsListLock.UpgradeToWriterLock(-1);
            }
            else
            {
                MessageHandler.rwClientsListLock.AcquireWriterLock(-1);
            }

            try
            {
                m_Clients.Add(client);
            }
            finally
            {
                if (readerLockHeld)
                {
                    MessageHandler.rwClientsListLock.DowngradeFromWriterLock(ref cookie1);
                }
                else
                {
                    MessageHandler.rwClientsListLock.ReleaseWriterLock();
                }
            }
		}
예제 #21
0
 private extern void FCallReleaseLock(ref LockCookie result);
		public void DowngradeFromWriterLock(ref LockCookie lockCookie)
		{
			lock (this) {
				if (!HasWriterLock())
					throw new ApplicationException ("The thread does not have the writer lock.");
				
				state = lockCookie.ReaderLocks;
				reader_locks [Thread.CurrentThreadId] = state;
				if (readers > 0) {
					Monitor.PulseAll (this);
				}
				
				// MSDN: A thread does not block when downgrading from the writer lock, 
				// even if other threads are waiting for the writer lock
			}
		}
예제 #23
0
 /// <summary>Indicates whether the current instance is equal to the specified <see cref="T:System.Threading.LockCookie" />.</summary>
 /// <returns>true if <paramref name="obj" /> is equal to the value of the current instance; otherwise, false.</returns>
 /// <param name="obj">The <see cref="T:System.Threading.LockCookie" /> to compare to the current instance.</param>
 public bool Equals(LockCookie obj)
 {
     return(this.ThreadId == obj.ThreadId && this.ReaderLocks == obj.ReaderLocks && this.WriterLocks == obj.WriterLocks);
 }
예제 #24
0
 public bool Equals(LockCookie obj)
 {
     return(default(bool));
 }
예제 #25
0
 public bool Load()
 {
     try
     {
         LockCookie upgrade = new LockCookie();
         bool upgraded = false;
         if (locker.IsReaderLockHeld)
         {
             upgrade = locker.UpgradeToWriterLock(new TimeSpan(0, 1, 0));
             upgraded = true;
         }
         else
             locker.AcquireWriterLock(new TimeSpan(0, 1, 0));
         try
         {
             try
             {
                 if (File.Exists(ConfigurationManagement.Instance.ConfigurationPath + Path.DirectorySeparatorChar + "IPLists.cfg"))
                 {
                     XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary<string, IPList>));
                     TextReader reader = new StreamReader(ConfigurationManagement.Instance.ConfigurationPath + Path.DirectorySeparatorChar + "IPLists.cfg");
                     iplists = (SerializableDictionary<string, IPList>)serializer.Deserialize(reader);
                     reader.Close();
                     reader.Dispose();
                 }
                 else
                 {
                     iplists = new SerializableDictionary<string,IPList>();
                 }
             }
             catch (Exception e)
             {
                 Logging.LogCenter.Instance.LogException(e);
                 iplists = new SerializableDictionary<string, IPList>();
             }
         }
         finally
         {
             if (upgraded)
                 locker.DowngradeFromWriterLock(ref upgrade);
             else
                 locker.ReleaseWriterLock();
         }
         return true;
     }
     catch (ApplicationException ex)
     {
         Logging.LogCenter.Instance.LogException(ex);
         return false;
     }
 }
 public void RestoreLock(ref LockCookie lockCookie)
 {
 }
예제 #27
0
 private extern void RestoreLockInternal(ref LockCookie lockCookie);
		LockCookie GetLockCookie ()
		{
			LockCookie cookie = new LockCookie (Thread.CurrentThreadId);
			
			if (HasWriterLock())
				cookie.WriterLocks = -state;
			else {
				object locks = reader_locks [Thread.CurrentThreadId];
				if (locks != null) cookie.ReaderLocks = (int)locks;
			}
			return cookie;
		}
예제 #29
0
 public extern void RestoreLock(ref LockCookie lockCookie);
예제 #30
0
 public void RestoreLock(ref LockCookie lockCookie)
 {
     throw new NotImplementedException();
 }
예제 #31
0
 private extern void FCallUpgradeToWriterLock(ref LockCookie result, int millisecondsTimeout);
예제 #32
0
 public void DowngradeFromWriterLock(ref LockCookie lockCookie)
 {
     this.DowngradeFromWriterLockInternal(ref lockCookie);
 }
 public void DowngradeFromWriterLock(ref LockCookie lockCookie)
 {
 }
 public void RestoreLock(ref LockCookie lockCookie)
 {
 }
예제 #35
0
 public void AddToList(string list, IPAddr ip)
 {
     try
     {
         LockCookie upgrade = new LockCookie();
         bool upgraded = false;
         if (locker.IsReaderLockHeld)
         {
             upgrade = locker.UpgradeToWriterLock(new TimeSpan(0, 1, 0));
             upgraded = true;
         }
         else
             locker.AcquireWriterLock(new TimeSpan(0, 1, 0));
         try
         {
             if (!iplists.ContainsKey(list))
             {
                 iplists[list] = new IPList();
             }
             iplists[list].Add(ip);
         }
         finally
         {
             if (upgraded)
                 locker.DowngradeFromWriterLock(ref upgrade);
             else
                 locker.ReleaseWriterLock();
         }
     }
     catch (ApplicationException a)
     {
         Logging.LogCenter.Instance.LogException(a);
     }
 }
 public void DowngradeFromWriterLock(ref LockCookie lockCookie)
 {
 }
예제 #37
0
 private extern void FCallReleaseLock(ref LockCookie result);
예제 #38
0
 public bool Equals(LockCookie obj)
 {
     return((((obj._dwFlags == this._dwFlags) && (obj._dwWriterSeqNum == this._dwWriterSeqNum)) && (obj._wReaderAndWriterLevel == this._wReaderAndWriterLevel)) && (obj._dwThreadID == this._dwThreadID));
 }
예제 #39
0
 public LockCookie ReleaseLock()
 {
     LockCookie result = new LockCookie();
     this.FCallReleaseLock(ref result);
     return result;
 }
예제 #40
0
 public extern void DowngradeFromWriterLock(ref LockCookie lockCookie);
예제 #41
0
        public void Upgrade()
        {
            if (_lockMode != IICLockMode.ReaderLock)
                    throw new InvalidOperationException("lock mode can't upgraded:" + _lockMode);

                _lockCookie = _innerLock.UpgradeToWriterLock(_msTimeout);
                _lockMode = IICLockMode.UpdatedWriterLock;
        }
예제 #42
0
 public void DowngradeFromWriterLock(ref LockCookie lockCookie)
 {
     this.DowngradeFromWriterLockInternal(ref lockCookie);
 }
예제 #43
0
 public void DowngradeFromWriterLock(ref LockCookie lc)
 {
     this.ExitWriteLock();
 }
예제 #44
0
 private extern void DowngradeFromWriterLockInternal(ref LockCookie lockCookie);
		public void RestoreLock(ref LockCookie lockCookie)
		{
			lock (this) {
				if (lockCookie.WriterLocks != 0)
					AcquireWriterLock (-1, lockCookie.WriterLocks);
				else if (lockCookie.ReaderLocks != 0)
					AcquireReaderLock (-1, lockCookie.ReaderLocks);
			}
		}
예제 #46
0
 public void DowngradeFromWriterLock(ref LockCookie lockCookie)
 {
     throw new NotImplementedException();
 }
예제 #47
0
 public void RestoreLock(ref LockCookie lockCookie)
 {
     this.RestoreLockInternal(ref lockCookie);
 }
예제 #48
0
        /// <summary>
        /// Returns a DataTable from the Cache.
        ///
        /// </summary>
        /// <param name="ACacheableTableName">Name of the DataTable</param>
        /// <param name="AType"></param>
        /// <returns>DataTable from the Cache</returns>
        /// <exception cref="ECacheableTablesMgrTableNotUpToDateException">if the Cacheable
        /// DataTable isn't in an up-to-date state. This means it needs to be retrieved
        /// anew before it can be used
        /// </exception>
        public DataTable GetCachedDataTable(String ACacheableTableName, out System.Type AType)
        {
            CacheableTablesTDSContentsRow ContentsEntryDR;
            DataTable TmpTable;

            System.Type CachedDataTableType;
            LockCookie UpgradeLockCookie = new LockCookie();

            // Variable initialisation (just to prevent compiler warnings)
            TmpTable = new DataTable();
            CachedDataTableType = new System.Data.DataTable().GetType();
            try
            {
                TLogging.LogAtLevel(10, "TCacheableTablesManager.GetCachedDataTable waiting for a ReaderLock...");

                // Try to get a read lock [We don't specify a timeout because reading the DB tables into the cached table should be fairly quick]
                FReadWriteLock.AcquireReaderLock(SharedConstants.THREADING_WAIT_INFINITE);
                TLogging.LogAtLevel(10, "TCacheableTablesManager.GetCachedDataTable grabbed a ReaderLock.");

                if (!UDataCacheDataSet.Tables.Contains(ACacheableTableName))
                {
                    throw new ECacheableTablesMgrException(
                        "TCacheableTablesManager.GetCachedDataTable: Cacheable DataTable '" + ACacheableTableName + "' does not exist in Cache");
                }

                ContentsEntryDR = GetContentsEntry(ACacheableTableName); // GetContentsEntry reuses the ReaderLock

                if (ContentsEntryDR != null)
                {
                    if (ContentsEntryDR.DataUpToDate)
                    {
                        try
                        {
                            TLogging.LogAtLevel(10, "TCacheableTablesManager.GetCachedDataTable waiting for upgrading to a WriterLock...");

                            // Need to temporarily upgrade to a write lock to prevent other threads from obtaining a read lock on the cache table while we are modifying the Cache Contents table!
                            UpgradeLockCookie = FReadWriteLock.UpgradeToWriterLock(SharedConstants.THREADING_WAIT_INFINITE);
                            TLogging.LogAtLevel(10, "TCacheableTablesManager.GetCachedDataTable upgraded to a WriterLock.");
                            ContentsEntryDR.LastAccessed = DateTime.Now;
                        }
                        finally
                        {
                            TLogging.LogAtLevel(10, "TCacheableTablesManager.GetCachedDataTable waiting for downgrading to a ReaderLock...");

                            // Downgrade from a WriterLock to a ReaderLock again!
                            FReadWriteLock.DowngradeFromWriterLock(ref UpgradeLockCookie);
                            TLogging.LogAtLevel(10, "TCacheableTablesManager.GetCachedDataTable downgraded to a ReaderLock.");
                        }
                    }
                    else
                    {
                        throw new ECacheableTablesMgrTableNotUpToDateException(ACacheableTableName);
                    }
                }

                /*
                 * To get around multi-threading reading/writing issues that might occur
                 * when the caller of this function performs read or write operations on the
                 * DataTable, we must return only a *copy* of the DataTable, not a reference
                 * to the DataTable!
                 */
                TmpTable = UDataCacheDataSet.Tables[ACacheableTableName].Copy();
                CachedDataTableType = UDataCacheDataSet.Tables[ACacheableTableName].GetType();
            }
            finally
            {
                // Release read lock
                FReadWriteLock.ReleaseReaderLock();
                TLogging.LogAtLevel(10, "TCacheableTablesManager.GetCachedDataTable released the ReaderLock.");
            }

            if (TmpTable is TTypedDataTable)
            {
                // The Copy needs to be a typed DataTable, so we need to type it
                DataUtilities.ChangeDataTableToTypedDataTable(ref TmpTable, CachedDataTableType, "");
            }

            TLogging.LogAtLevel(7, "TCacheableTablesManager.GetCachedDataTable: Returned Type: " + TmpTable.GetType().FullName);
            AType = TmpTable.GetType();
            return TmpTable;
        }
예제 #49
0
 public LockCookie UpgradeToWriterLock(int millisecondsTimeout)
 {
     LockCookie result = new LockCookie();
     this.FCallUpgradeToWriterLock(ref result, millisecondsTimeout);
     return result;
 }
예제 #50
0
                public WriteLatch(ReaderWriterLock lck, int timeout)
                {
                    _mutex = lck;

                    if (_mutex.IsReaderLockHeld)
                    {
                        _upgraded = true;
                        _cookie = lck.UpgradeToWriterLock(timeout);
                    }
                    else
                    {
                        _upgraded = false;
                        lck.AcquireWriterLock(timeout);
                    }
                }
예제 #51
0
 private extern void DowngradeFromWriterLockInternal(ref LockCookie lockCookie);
예제 #52
0
 public void RestoreLock(ref LockCookie lockCookie)
 {
     this.RestoreLockInternal(ref lockCookie);
 }
예제 #53
0
 private extern void FCallUpgradeToWriterLock(ref LockCookie result, int millisecondsTimeout);
예제 #54
0
 private extern void RestoreLockInternal(ref LockCookie lockCookie);
예제 #55
0
 public bool Equals(LockCookie obj)
 {
     return obj._dwFlags == _dwFlags && obj._dwWriterSeqNum == _dwWriterSeqNum &&
         obj._wReaderAndWriterLevel == _wReaderAndWriterLevel && obj._dwThreadID == _dwThreadID;
 }
예제 #56
0
 /// <summary>Indicates whether the current instance is equal to the specified <see cref="T:System.Threading.LockCookie" />.</summary><returns>true if <paramref name="obj" /> is equal to the value of the current instance; otherwise, false.</returns><param name="obj">The <see cref="T:System.Threading.LockCookie" /> to compare to the current instance.</param>
 public bool Equals(LockCookie obj)
 {
     throw new NotImplementedException();
 }