29 using System.Collections.Generic;
30 using System.Threading;
31 using System.Reflection;
33 using System.Diagnostics;
34 using System.Xml.Schema;
35 using System.Xml.Serialization;
39 namespace OpenSim.Framework
49 ICloneable, IXmlSerializable
53 private static XmlSerializer tiiSerializer =
new XmlSerializer(typeof (
TaskInventoryItem));
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
56 private Thread LockedByThread;
65 private volatile System.Threading.ReaderWriterLockSlim m_itemLock =
new System.Threading.ReaderWriterLockSlim();
72 if (m_itemLock.RecursiveReadCount > 0)
89 if (m_itemLock.IsWriteLockHeld && LockedByThread != null)
91 if (!LockedByThread.IsAlive)
94 m_itemLock =
new System.Threading.ReaderWriterLockSlim();
98 if (m_itemLock.RecursiveReadCount > 0)
100 m_log.Error(
"[TaskInventoryDictionary] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
125 m_itemLock.ExitReadLock();
127 if (m_itemLock.RecursiveWriteCount > 0)
129 m_log.Error(
"[TaskInventoryDictionary] Recursive write lock requested. This should not happen and means something needs to be fixed.");
140 m_itemLock.ExitWriteLock();
143 while (!m_itemLock.TryEnterReadLock(60000))
145 m_log.Error(
"Thread lock detected while trying to aquire READ lock in TaskInventoryDictionary. Locked by thread " + LockedByThread.Name +
". I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
148 m_itemLock =
new System.Threading.ReaderWriterLockSlim();
162 if (m_itemLock.RecursiveReadCount>0)
164 m_itemLock.ExitReadLock();
179 if (m_itemLock.RecursiveReadCount > 0)
181 m_log.Error(
"[TaskInventoryDictionary] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
182 m_itemLock.ExitReadLock();
184 if (m_itemLock.RecursiveWriteCount > 0)
186 m_log.Error(
"[TaskInventoryDictionary] Recursive write lock requested. This should not happen and means something needs to be fixed.");
188 m_itemLock.ExitWriteLock();
190 while (!m_itemLock.TryEnterWriteLock(60000))
192 if (m_itemLock.IsWriteLockHeld)
194 m_log.Error(
"Thread lock detected while trying to aquire WRITE lock in TaskInventoryDictionary. Locked by thread " + LockedByThread.Name +
". I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
203 m_log.Error(
"Thread lock detected while trying to aquire WRITE lock in TaskInventoryDictionary. Locked by a reader. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
213 m_itemLock =
new System.Threading.ReaderWriterLockSlim();
217 LockedByThread = Thread.CurrentThread;
222 if (m_itemLock.RecursiveWriteCount > 0)
224 m_itemLock.ExitWriteLock();
229 #region ICloneable Members
235 m_itemLock.EnterReadLock();
236 foreach (UUID uuid
in Keys)
240 m_itemLock.ExitReadLock();
260 #region IXmlSerializable Members
272 if (!reader.IsEmptyElement)
275 while (tiiSerializer.CanDeserialize(reader))
304 tiiSerializer.Serialize(writer, item);
A dictionary containing task inventory items. Indexed by item UUID.
Represents an item in a task inventory
bool IsReadLockedByMe()
Are we readlocked by the calling thread?
void LockItemsForRead(bool locked)
Lock our inventory list for reading (many can read, one can write)
void WriteXml(XmlWriter writer)
void LockItemsForWrite(bool locked)
Lock our inventory list for writing (many can read, one can write)
void ReadXml(XmlReader reader)