mk TaskInventoryDictionary IDisposable

master
UbitUmarov 2020-05-12 18:52:02 +01:00
parent c63fabe054
commit d613287a77
1 changed files with 31 additions and 18 deletions

View File

@ -45,8 +45,7 @@ namespace OpenSim.Framework
/// This class is not thread safe. Callers must synchronize on Dictionary methods or Clone() this object before /// This class is not thread safe. Callers must synchronize on Dictionary methods or Clone() this object before
/// iterating over it. /// iterating over it.
/// </remarks> /// </remarks>
public class TaskInventoryDictionary : Dictionary<UUID, TaskInventoryItem>, public class TaskInventoryDictionary : Dictionary<UUID, TaskInventoryItem>, ICloneable, IXmlSerializable, IDisposable
ICloneable, IXmlSerializable
{ {
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -64,11 +63,27 @@ namespace OpenSim.Framework
/// </value> /// </value>
private volatile System.Threading.ReaderWriterLockSlim m_itemLock = new System.Threading.ReaderWriterLockSlim(); private volatile System.Threading.ReaderWriterLockSlim m_itemLock = new System.Threading.ReaderWriterLockSlim();
~TaskInventoryDictionary() ~TaskInventoryDictionary()
{ {
m_itemLock.Dispose(); Dispose(false);
m_itemLock = null; }
private bool disposed = false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!disposed)
{
m_itemLock.Dispose();
m_itemLock = null;
disposed = true;
}
} }
/// <summary> /// <summary>
@ -248,21 +263,19 @@ namespace OpenSim.Framework
return clone; return clone;
} }
#endregion #endregion
// The alternative of simply serializing the list doesn't appear to work on mono, since public List<TaskInventoryItem> GetItems()
// we get a {
// var ret = new List<TaskInventoryItem>(this.Count);
// System.TypeInitializationException: An exception was thrown by the type initializer for OpenSim.Framework.TaskInventoryDictionary ---> System.ArgumentOutOfRangeException: < 0 m_itemLock.EnterReadLock();
// Parameter name: length foreach (TaskInventoryItem it in Values)
// at System.String.Substring (Int32 startIndex, Int32 length) [0x00088] in /build/buildd/mono-1.2.4/mcs/class/corlib/System/String.cs:381 {
// at System.Xml.Serialization.TypeTranslator.GetTypeData (System.Type runtimeType, System.String xmlDataType) [0x001f6] in /build/buildd/mono-1.2.4/mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs:217 ret.Add(it);
// ... }
// private static XmlSerializer tiiSerializer m_itemLock.ExitReadLock();
// = new XmlSerializer(typeof(Dictionary<UUID, TaskInventoryItem>.ValueCollection)); return ret;
}
// see IXmlSerializable
#region IXmlSerializable Members #region IXmlSerializable Members