[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/Generics SynchronizedCollection.cs,N
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/Generics SynchronizedCollection.cs,NONE,1.1 SynchronizedDeque.cs,NONE,1.1 SynchronizedDictionary.cs,NONE,1.1 SynchronizedList.cs,NONE,1.1 SynchronizedQueue.cs,NONE,1.1 SynchronizedStack.cs,NONE,1.1 ArrayList.cs,1.5,1.6 ArrayQueue.cs,1.3,1.4 ArrayStack.cs,1.3,1.4 Hashtable.cs,1.3,1.4 SynchronizedDictIterator.cs,1.3,NONESynchronizedIterator.cs,1.3,NONE SynchronizedListIterator.cs,1.2,NONE |
Date: |
Mon, 24 Feb 2003 05:01:06 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/Generics
In directory subversions:/tmp/cvs-serv25436/Generics
Modified Files:
ArrayList.cs ArrayQueue.cs ArrayStack.cs Hashtable.cs
Added Files:
SynchronizedCollection.cs SynchronizedDeque.cs
SynchronizedDictionary.cs SynchronizedList.cs
SynchronizedQueue.cs SynchronizedStack.cs
Removed Files:
SynchronizedDictIterator.cs SynchronizedIterator.cs
SynchronizedListIterator.cs
Log Message:
Add synchronized wrapper classes to replace the concrete-specific
"Synchronized" methods.
--- NEW FILE ---
/*
* SynchronizedCollection.cs - Wrap a collection to make it synchronized.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public class SynchronizedCollection<T> : ICollection<T>, ICloneable
{
// Internal state.
protected ICollection<T> coll;
// Constructors.
public SynchronizedCollection(ICollection<T> coll)
{
if(coll == null)
{
throw new ArgumentNullException("coll");
}
this.coll = coll;
}
// Implement the ICollection<T> interface.
public void CopyTo(T[] array, int index)
{
lock(SyncRoot)
{
coll.CopyTo(array, index);
}
}
public int Count
{
get
{
lock(SyncRoot)
{
return coll.Count;
}
}
}
public bool IsSynchronized
{
get
{
return true;
}
}
public Object SyncRoot
{
get
{
return coll.SyncRoot;
}
}
// Implement the IIterable<T> interface.
public IIterator<T> GetIterator()
{
lock(SyncRoot)
{
return new SynchronizedIterator<T>
(coll, coll.GetIterator());
}
}
// Implement the ICloneable interface.
public virtual Object Clone()
{
if(coll is ICloneable)
{
return new SynchronizedCollection<T>
((ICollection<T>)(((ICloneable)coll).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
// Synchronized collection iterator.
private sealed class SynchronizedIterator<T> : IIterator<T>
{
// Internal state.
protected ICollection<T> coll;
protected IIterator<T> iterator;
// Constructor.
public SynchronizedIterator(ICollection<T> coll, IIterator<T>
iterator)
{
this.coll = coll;
this.iterator = iterator;
}
// Implement the IIterator<T> interface.
public bool MoveNext()
{
lock(coll.SyncRoot)
{
return iterator.MoveNext();
}
}
public void Reset()
{
lock(coll.SyncRoot)
{
iterator.Reset();
}
}
public void Remove()
{
lock(coll.SyncRoot)
{
iterator.Remove();
}
}
public T Current
{
get
{
lock(coll.SyncRoot)
{
return iterator.Current;
}
}
}
}; // class SynchronizedIterator<T>
}; // class SynchronizedCollection<T>
}; // namespace Generics
--- NEW FILE ---
/*
* SynchronizedDeque.cs - Wrap a deque to make it synchronized.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public class SynchronizedDeque<T> : SynchronizedCollection<T>, IDeque<T>
{
// Internal state.
protected IDeque<T> deque;
// Constructor.
public SynchronizedDeque(IDeque<T> deque) : base(deque)
{
this.deque = deque;
}
// Implement the IDeque<T> interface.
public void PushFront(T value)
{
lock(SyncRoot)
{
deque.PushFront(value);
}
}
public void PushBack(T value)
{
lock(SyncRoot)
{
deque.PushBack(value);
}
}
public T PopFront()
{
lock(SyncRoot)
{
return deque.PopFront();
}
}
public T PopBack()
{
lock(SyncRoot)
{
return deque.PopBack();
}
}
public T PeekFront()
{
lock(SyncRoot)
{
return deque.PeekFront();
}
}
public T PeekEnd()
{
lock(SyncRoot)
{
return deque.PeekEnd();
}
}
public T[] ToArray()
{
lock(SyncRoot)
{
return deque.ToArray();
}
}
public bool IsFixedSize
{
get
{
lock(SyncRoot)
{
return deque.IsFixedSize;
}
}
}
public bool IsReadOnly
{
get
{
lock(SyncRoot)
{
return deque.IsReadOnly;
}
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(deque is ICloneable)
{
return new SynchronizedDeque<T>
((IDeque<T>)(((ICloneable)deque).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class SynchronizedDeque<T>
}; // namespace Generics
--- NEW FILE ---
/*
* SynchronizedDictionary.cs - Wrap a dictionary to make it synchronized.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public class SynchronizedDictionary<KeyT, ValueT>
: SynchronizedCollection< DictionaryEntry<KeyT, ValueT> >,
IDictionary<KeyT, ValueT>
{
// Internal state.
protected IDictionary<KeyT, ValueT> dict;
// Constructor.
public SynchronizedDictionary(IDictionary<KeyT, ValueT> dict) :
base(dict)
{
this.dict = dict;
}
// Implement the IDictionary<KeyT, ValueT> interface.
public void Add(KeyT key, ValueT value)
{
lock(SyncRoot)
{
dict.Add(key, value);
}
}
public void Clear()
{
lock(SyncRoot)
{
dict.Clear();
}
}
public bool Contains(KeyT key)
{
lock(SyncRoot)
{
return dict.Contains(key);
}
}
public new IDictionaryIterator<KeyT, ValueT> GetIterator()
{
lock(SyncRoot)
{
return new
SynchronizedDictIterator<KeyT, ValueT>
(dict,
dict.GetIterator());
}
}
public void Remove(KeyT key)
{
lock(SyncRoot)
{
dict.Remove(key);
}
}
public bool IsFixedSize
{
get
{
lock(SyncRoot)
{
return dict.IsFixedSize;
}
}
}
public bool IsReadOnly
{
get
{
lock(SyncRoot)
{
return dict.IsReadOnly;
}
}
}
public ValueT this[KeyT key]
{
get
{
lock(SyncRoot)
{
return dict[key];
}
}
set
{
lock(SyncRoot)
{
dict[key] = value;
}
}
}
public ICollection<KeyT> Keys
{
get
{
lock(SyncRoot)
{
return new
SynchronizedCollection<KeyT>(dict.Keys);
}
}
}
public ICollection<ValueT> Values
{
get
{
lock(SyncRoot)
{
return new
SynchronizedCollection<ValueT>(dict.Values);
}
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(dict is ICloneable)
{
return new SynchronizedDictionary<T>
((IDictionary<T>)(((ICloneable)dict).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
// Synchronized dictionary iterator.
private sealed class SynchronizedDictIterator<KeyT, ValueT>
: IDictionaryIterator<KeyT, ValueT>
{
// Internal state.
protected IDictionary<KeyT, ValueT> dict;
protected IDictionaryIterator<KeyT, ValueT> iterator;
// Constructor.
public SynchronizedDictIterator
(IDictionary<KeyT, ValueT> dict,
IDictionaryIterator<KeyT, ValueT>
iterator)
{
this.dict = dict;
this.iterator = iterator;
}
// Implement the IIterator<ValueT> interface.
public bool MoveNext()
{
lock(dict.SyncRoot)
{
return iterator.MoveNext();
}
}
public void Reset()
{
lock(dict.SyncRoot)
{
iterator.Reset();
}
}
public void Remove()
{
lock(dict.SyncRoot)
{
iterator.Remove();
}
}
public DictionaryEntry<KeyT, ValueT> Current
{
get
{
lock(dict.SyncRoot)
{
return iterator.Current;
}
}
}
// Implement the IDictionaryIterator<KeyT, ValueT> interface.
public DictionaryEntry<KeyT, ValueT> Entry
{
get
{
lock(dict.SyncRoot)
{
return iterator.Entry;
}
}
}
public KeyT Key
{
get
{
lock(dict.SyncRoot)
{
return iterator.Key;
}
}
}
public ValueT Value
{
get
{
lock(dict.SyncRoot)
{
return iterator.Value;
}
}
set
{
lock(dict.SyncRoot)
{
iterator.Value = value;
}
}
}
}; // class SynchronizedDictIterator<KeyT, ValueT>
}; // class SynchronizedDictionary<KeyT, ValueT>
}; // namespace Generics
--- NEW FILE ---
/*
* SynchronizedList.cs - Wrap a list to make it synchronized.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public class SynchronizedList<T> : SynchronizedCollection<T>, IList<T>
{
// Internal state.
protected IList<T> list;
// Constructor.
public SynchronizedList(IList<T> list) : base(list)
{
this.list = list;
}
// Implement the IList<T> interface.
public int Add(T value)
{
lock(SyncRoot)
{
return list.Add(value);
}
}
public void Clear()
{
lock(SyncRoot)
{
list.Clear();
}
}
public bool Contains(T value)
{
lock(SyncRoot)
{
return list.Contains(value);
}
}
public new IListIterator<T> GetIterator()
{
lock(SyncRoot)
{
return new SynchronizedListIterator<T>
(list, list.GetIterator());
}
}
public int IndexOf(T value)
{
lock(SyncRoot)
{
return list.IndexOf(value);
}
}
public void Insert(int index, T value)
{
lock(SyncRoot)
{
list.Insert(index, value);
}
}
public void Remove(T value)
{
lock(SyncRoot)
{
list.Remove(value);
}
}
public void RemoveAt(int index)
{
lock(SyncRoot)
{
list.RemoveAt(index);
}
}
public bool IsFixedSize
{
get
{
lock(SyncRoot)
{
return list.IsFixedSize;
}
}
}
public bool IsReadOnly
{
get
{
lock(SyncRoot)
{
return list.IsReadOnly;
}
}
}
public bool IsRandomAccess
{
get
{
lock(SyncRoot)
{
return list.IsRandomAccess;
}
}
}
public T this[int index]
{
get
{
lock(SyncRoot)
{
return list[index];
}
}
set
{
lock(SyncRoot)
{
list[index] = value;
}
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(list is ICloneable)
{
return new SynchronizedList<T>
((IList<T>)(((ICloneable)list).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
// Synchronized list iterator.
private sealed class SynchronizedListIterator<T> : IListIterator<T>
{
// Internal state.
protected IList<T> list;
protected IListIterator<T> iterator;
// Constructor.
public SynchronizedListIterator
(IList<T> list, IListIterator<T>
iterator)
{
this.list = list;
this.iterator = iterator;
}
// Implement the IIterator<T> interface.
public bool MoveNext()
{
lock(list.SyncRoot)
{
return iterator.MoveNext();
}
}
public void Reset()
{
lock(list.SyncRoot)
{
iterator.Reset();
}
}
public void Remove()
{
lock(list.SyncRoot)
{
iterator.Remove();
}
}
T IIterator<T>.Current
{
get
{
lock(list.SyncRoot)
{
return
((IIterator<T>)iterator).Current;
}
}
}
// Implement the IListIterator<T> interface.
public bool MovePrev()
{
lock(list.SyncRoot)
{
return iterator.MovePrev();
}
}
public int Position
{
get
{
lock(list.SyncRoot)
{
return
iterator.Position;
}
}
}
public T Current
{
get
{
lock(list.SyncRoot)
{
return iterator.Current;
}
}
set
{
lock(list.SyncRoot)
{
iterator.Current =
value;
}
}
}
}; // class SynchronizedListIterator<T>
}; // class SynchronizedList<T>
}; // namespace Generics
--- NEW FILE ---
/*
* SynchronizedQueue.cs - Wrap a queue to make it synchronized.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public class SynchronizedQueue<T> : SynchronizedCollection<T>, IQueue<T>
{
// Internal state.
protected IQueue<T> queue;
// Constructor.
public SynchronizedQueue(IQueue<T> queue) : base(queue)
{
this.queue = queue;
}
// Implement the IQueue<T> interface.
public void Enqueue(T value)
{
lock(SyncRoot)
{
queue.Enqueue(value);
}
}
public T Dequeue()
{
lock(SyncRoot)
{
return queue.Dequeue();
}
}
public T Peek()
{
lock(SyncRoot)
{
return queue.Peek();
}
}
public T[] ToArray()
{
lock(SyncRoot)
{
return queue.ToArray();
}
}
public bool IsFixedSize
{
get
{
lock(SyncRoot)
{
return queue.IsFixedSize;
}
}
}
public bool IsReadOnly
{
get
{
lock(SyncRoot)
{
return queue.IsReadOnly;
}
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(queue is ICloneable)
{
return new SynchronizedQueue<T>
((IQueue<T>)(((ICloneable)queue).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class SynchronizedQueue<T>
}; // namespace Generics
--- NEW FILE ---
/*
* SynchronizedStack.cs - Wrap a stack to make it synchronized.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public class SynchronizedStack<T> : SynchronizedCollection<T>, IStack<T>
{
// Internal state.
protected IStack<T> stack;
// Constructor.
public SynchronizedStack(IStack<T> stack) : base(stack)
{
this.stack = stack;
}
// Implement the IStack<T> interface.
public void Push(T value)
{
lock(SyncRoot)
{
stack.Push(value);
}
}
public T Pop()
{
lock(SyncRoot)
{
return stack.Pop();
}
}
public T Peek()
{
lock(SyncRoot)
{
return stack.Peek();
}
}
public T[] ToArray()
{
lock(SyncRoot)
{
return stack.ToArray();
}
}
public bool IsFixedSize
{
get
{
lock(SyncRoot)
{
return stack.IsFixedSize;
}
}
}
public bool IsReadOnly
{
get
{
lock(SyncRoot)
{
return stack.IsReadOnly;
}
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(stack is ICloneable)
{
return new SynchronizedStack<T>
((IStack<T>)(((ICloneable)stack).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class SynchronizedStack<T>
}; // namespace Generics
Index: ArrayList.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/ArrayList.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** ArrayList.cs 24 Feb 2003 08:58:10 -0000 1.5
--- ArrayList.cs 24 Feb 2003 10:01:00 -0000 1.6
***************
*** 1483,1845 ****
}; // class RangeWrapper<T>
- // Adapt an array list to appear to be synchronized
- public static ArrayList<T> Synchronized<T>(ArrayList<T> list)
- {
- if(list == null)
- {
- throw new ArgumentNullException("list");
- }
- else if(list.IsSynchronized)
- {
- return list;
- }
- else
- {
- return new SynchronizedWrapper<T>(list);
- }
- }
-
- // Wrapper class for synchronized lists.
- private class SynchronizedWrapper<T> : ArrayList<T>
- {
- // Internal state.
- private ArrayList<T> list;
-
- // Constructor.
- public SynchronizedWrapper(ArrayList<T> list)
- {
- this.list = list;
- }
-
- // Implement the IList interface.
- public override int Add(T value)
- {
- lock(SyncRoot)
- {
- return list.Add(value);
- }
- }
- public override void Clear()
- {
- lock(SyncRoot)
- {
- list.Clear();
- }
- }
- public override bool Contains(T item)
- {
- lock(SyncRoot)
- {
- return list.Contains(item);
- }
- }
- public override int IndexOf(T value)
- {
- lock(SyncRoot)
- {
- return list.IndexOf(value);
- }
- }
- public override void Insert(int index, T value)
- {
- lock(SyncRoot)
- {
- list.Insert(index, value);
- }
- }
- public override void Remove(T value)
- {
- lock(SyncRoot)
- {
- list.Remove(value);
- }
- }
- public override void RemoveAt(int index)
- {
- lock(SyncRoot)
- {
- list.RemoveAt(index);
- }
- }
- public override bool IsFixedSize
- {
- get
- {
- lock(SyncRoot)
- {
- return list.IsFixedSize;
- }
- }
- }
- public override bool IsReadOnly
- {
- get
- {
- lock(SyncRoot)
- {
- return list.IsReadOnly;
- }
- }
- }
- public override T this[int index]
- {
- get
- {
- lock(SyncRoot)
- {
- return list[index];
- }
- }
- set
- {
- lock(SyncRoot)
- {
- list[index] = value;
- }
- }
- }
-
- // Range-related methods.
- public override void AddRange(ICollection<T> c)
- {
- lock(SyncRoot)
- {
- list.AddRange(c);
- }
- }
- public override void InsertRange(int index, ICollection<T> c)
- {
- lock(SyncRoot)
- {
- list.InsertRange(index, c);
- }
- }
- public override void RemoveRange(int index, int count)
- {
- lock(SyncRoot)
- {
- list.RemoveRange(index, count);
- }
- }
- public override void SetRange(int index, ICollection<T> c)
- {
- lock(SyncRoot)
- {
- list.SetRange(index, c);
- }
- }
-
- // Searching methods.
- public override int BinarySearch(T value)
- {
- lock(SyncRoot)
- {
- return list.BinarySearch(value);
- }
- }
- public override int BinarySearch(T value, IComparer<T> comparer)
- {
- lock(SyncRoot)
- {
- return list.BinarySearch(value,
comparer);
- }
- }
- public override int BinarySearch(int index, int count,
- T
value, IComparer<T> comparer)
- {
- lock(SyncRoot)
- {
- return list.BinarySearch(index,
count, value, comparer);
- }
- }
- public override int IndexOf(T value, int startIndex)
- {
- lock(SyncRoot)
- {
- return list.IndexOf(value,
startIndex);
- }
- }
- public override int IndexOf(T value, int startIndex, int count)
- {
- lock(SyncRoot)
- {
- return list.IndexOf(value,
startIndex, count);
- }
- }
- public override int LastIndexOf(T value)
- {
- lock(SyncRoot)
- {
- return list.LastIndexOf(value);
- }
- }
- public override int LastIndexOf(T value, int startIndex)
- {
- lock(SyncRoot)
- {
- return list.LastIndexOf(value,
startIndex);
- }
- }
- public override int LastIndexOf(T value, int startIndex, int
count)
- {
- lock(SyncRoot)
- {
- return list.LastIndexOf(value,
startIndex, count);
- }
- }
-
- // Implement the ICollection interface.
- public override void CopyTo(T[] array, int arrayIndex)
- {
- lock(SyncRoot)
- {
- list.CopyTo(array, arrayIndex);
- }
- }
- public override int Count
- {
- get
- {
- lock(SyncRoot)
- {
- return list.count;
- }
- }
- }
- public override bool IsSynchronized
- {
- get
- {
- return true;
- }
- }
- public override Object SyncRoot
- {
- get
- {
- return list.SyncRoot;
- }
- }
-
- // Copy from this array list to another array.
- public override void CopyTo(T[] array)
- {
- lock(SyncRoot)
- {
- list.CopyTo(array);
- }
- }
- public override void CopyTo(int index, T[] array,
- int
arrayIndex, int count)
- {
- lock(SyncRoot)
- {
- list.CopyTo(index, array,
arrayIndex, count);
- }
- }
-
- // Reverse the contents of this array list.
- public override void Reverse()
- {
- lock(SyncRoot)
- {
- list.Reverse();
- }
- }
- public override void Reverse(int index, int count)
- {
- lock(SyncRoot)
- {
- list.Reverse(index, count);
- }
- }
-
- // Sort the contents of this array list.
- public override void Sort()
- {
- lock(SyncRoot)
- {
- list.Sort();
- }
- }
- public override void Sort(IComparer<T> comparer)
- {
- lock(SyncRoot)
- {
- list.Sort(comparer);
- }
- }
- public override void Sort(int index, int count, IComparer<T>
comparer)
- {
- lock(SyncRoot)
- {
- list.Sort(index, count,
comparer);
- }
- }
-
- // Create an array that contains the elements of this array
list.
- public override T[] ToArray()
- {
- lock(SyncRoot)
- {
- return list.ToArray();
- }
- }
- public override Array ToArray(Type type)
- {
- lock(SyncRoot)
- {
- return list.ToArray(type);
- }
- }
-
- // Trim the array list to its actual size.
- public override void TrimToSize()
- {
- lock(SyncRoot)
- {
- list.TrimToSize();
- }
- }
-
- // Get or set the current capacity of the array list.
- public override int Capacity
- {
- get
- {
- lock(SyncRoot)
- {
- return list.Capacity;
- }
- }
- set
- {
- lock(SyncRoot)
- {
- list.Capacity = value;
- }
- }
- }
-
- // Get an iterator for this array list.
- public override IListIterator<T> GetIterator()
- {
- lock(SyncRoot)
- {
- return new
SynchronizedIterator<T>
- (SyncRoot,
list.GetIterator());
- }
- }
- public override IListIterator<T> GetIterator(int index, int
count)
- {
- lock(SyncRoot)
- {
- return new
SynchronizedIterator<T>
- (SyncRoot,
list.GetIterator(index, count));
- }
- }
-
- }; // class SynchronizedWrapper<T>
-
}; // class ArrayList<T>
--- 1483,1486 ----
Index: ArrayQueue.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/ArrayQueue.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** ArrayQueue.cs 24 Feb 2003 06:56:27 -0000 1.3
--- ArrayQueue.cs 24 Feb 2003 10:01:00 -0000 1.4
***************
*** 303,441 ****
}
- // Convert this queue into a synchronized queue.
- public static ArrayQueue<T> Synchronized(ArrayQueue<T> queue)
- {
- if(queue == null)
- {
- throw new
ArgumentNullException("queue");
- }
- else if(queue.IsSynchronized)
- {
- return queue;
- }
- else
- {
- return new SynchronizedQueue<T>(queue);
- }
- }
-
- // Private class that implements synchronized queues.
- private class SynchronizedQueue : Queue
- {
- // Internal state.
- private ArrayQueue<T> queue;
-
- // Constructor.
- public SynchronizedQueue(ArrayQueue<T> queue)
- {
- this.queue = queue;
- }
-
- // Implement the ICollection<T> interface.
- public override void CopyTo(T[] array, int index)
- {
- lock(SyncRoot)
- {
- queue.CopyTo(array, index);
- }
- }
- public override int Count
- {
- get
- {
- lock(SyncRoot)
- {
- return queue.Count;
- }
- }
- }
- public override bool IsSynchronized
- {
- get
- {
- return true;
- }
- }
- public override Object SyncRoot
- {
- get
- {
- return queue.SyncRoot;
- }
- }
-
- // Implement the ICloneable interface.
- public override Object Clone()
- {
- return new SynchronizedQueue<T>
-
((ArrayQueue<T>)(queue.Clone()));
- }
-
- // Implement the IIterable<T> interface.
- public override IIterator<T> GetIterator()
- {
- lock(SyncRoot)
- {
- return new
SynchronizedIterator<T>
- (SyncRoot,
queue.GetIterator());
- }
- }
-
- // Clear the contents of this queue.
- public override void Clear()
- {
- lock(SyncRoot)
- {
- queue.Clear();
- }
- }
-
- // Determine if this queue contains a specific object.
- public override bool Contains(T obj)
- {
- lock(SyncRoot)
- {
- return queue.Contains(obj);
- }
- }
-
- // Dequeue an item.
- public override T Dequeue()
- {
- lock(SyncRoot)
- {
- return queue.Dequeue();
- }
- }
-
- // Enqueue an item.
- public override void Enqueue(T obj)
- {
- lock(SyncRoot)
- {
- queue.Enqueue(obj);
- }
- }
-
- // Peek at the first item without dequeuing it.
- public override T Peek()
- {
- lock(SyncRoot)
- {
- return queue.Peek();
- }
- }
-
- // Convert the contents of this queue into an array.
- public override T[] ToArray()
- {
- lock(SyncRoot)
- {
- return queue.ToArray();
- }
- }
-
- }; // class SynchronizedQueue
-
// Private class for implementing queue enumeration.
private class QueueIterator<T> : IIterator<T>
--- 303,306 ----
Index: ArrayStack.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/ArrayStack.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** ArrayStack.cs 24 Feb 2003 06:56:27 -0000 1.3
--- ArrayStack.cs 24 Feb 2003 10:01:00 -0000 1.4
***************
*** 234,372 ****
}
- // Convert this stack into a synchronized stack.
- public static ArrayStack<T> Synchronized(ArrayStack<T> stack)
- {
- if(stack == null)
- {
- throw new
ArgumentNullException("stack");
- }
- else if(stack.IsSynchronized)
- {
- return stack;
- }
- else
- {
- return new SynchronizedStack<T>(stack);
- }
- }
-
- // Private class that implements synchronized stacks.
- private class SynchronizedStack<T> : ArrayStack<T>
- {
- // Internal state.
- private ArrayStack<T> stack;
-
- // Constructor.
- public SynchronizedStack(ArrayStack<T> stack)
- {
- this.stack = stack;
- }
-
- // Implement the ICollection<T> interface.
- public override void CopyTo(T[] array, int index)
- {
- lock(SyncRoot)
- {
- stack.CopyTo(array, index);
- }
- }
- public override int Count
- {
- get
- {
- lock(SyncRoot)
- {
- return stack.Count;
- }
- }
- }
- public override bool IsSynchronized
- {
- get
- {
- return true;
- }
- }
- public override Object SyncRoot
- {
- get
- {
- return stack.SyncRoot;
- }
- }
-
- // Implement the ICloneable interface.
- public override Object Clone()
- {
- return new SynchronizedStack<T>
-
((ArrayStack<T>)(stack.Clone()));
- }
-
- // Implement the IIterable<T> interface.
- public override IIterator<T> GetIterator()
- {
- lock(SyncRoot)
- {
- return new
SynchronizedIterator<T>
- (SyncRoot,
stack.GetIterator());
- }
- }
-
- // Clear the contents of this stack.
- public override void Clear()
- {
- lock(SyncRoot)
- {
- stack.Clear();
- }
- }
-
- // Determine if this stack contains a specific object.
- public override bool Contains(T obj)
- {
- lock(SyncRoot)
- {
- return stack.Contains(obj);
- }
- }
-
- // Pop an item.
- public override T Pop()
- {
- lock(SyncRoot)
- {
- return stack.Pop();
- }
- }
-
- // Push an item.
- public override void Push(T obj)
- {
- lock(SyncRoot)
- {
- stack.Push(obj);
- }
- }
-
- // Peek at the top-most item without popping it.
- public override T Peek()
- {
- lock(SyncRoot)
- {
- return stack.Peek();
- }
- }
-
- // Convert the contents of this stack into an array.
- public override T[] ToArray()
- {
- lock(SyncRoot)
- {
- return stack.ToArray();
- }
- }
-
- }; // class SynchronizedStack<T>
-
// Private class for implementing stack iteration.
private class StackIterator<T> : IIterator<T>
--- 234,237 ----
Index: Hashtable.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/Hashtable.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** Hashtable.cs 24 Feb 2003 05:20:34 -0000 1.3
--- Hashtable.cs 24 Feb 2003 10:01:00 -0000 1.4
***************
*** 837,858 ****
}
- // Wrap a Hashtable object to make it synchronized.
- public static Hashtable<KeyT, ValueT> Synchronized
- (Hashtable<KeyT, ValueT> table)
- {
- if(table == null)
- {
- throw new
ArgumentNullException("table");
- }
- else if(table.IsSynchronized)
- {
- return table;
- }
- else
- {
- return new SynchronizedHashtable<KeyT,
ValueT>(table);
- }
- }
-
// Get the hash code provider that is being used by this instance.
protected virtual IHashCodeProvider<KeyT> hcp
--- 837,840 ----
***************
*** 872,1094 ****
}
}
-
- // Synchronized hash table implementation.
- //
- // Note: We lock every operation on the underlying hash table,
- // even if it is a read or iterator operation. This is because
- // we cannot guarantee correct behaviour in symmetric multi-processing
- // environments if we only lock write operations.
- private sealed class SynchronizedHashtable<KeyT, ValueT>
- : Hashtable<KeyT, ValueT>
- {
- // Internal state.
- private new Hashtable<KeyT, ValueT> table;
-
- // Constructor.
- public SynchronizedHashtable(Hashtable<KeyT, ValueT> table)
- {
- this.table = table;
- }
-
- // Implement the ICloneable interface.
- public override Object Clone()
- {
- lock(SyncRoot)
- {
- return new
SynchronizedHashtable<KeyT, ValueT>
- ((Hashtable<KeyT,
ValueT>)(table.Clone()));
- }
- }
-
- // Implement the ICollection interface.
- public override void CopyTo
- (DictionaryEntry<KeyT, ValueT>[] array,
int index)
- {
- lock(SyncRoot)
- {
- table.CopyTo(array, index);
- }
- }
- public override int Count
- {
- get
- {
- lock(SyncRoot)
- {
- return table.Count;
- }
- }
- }
- public override bool IsSynchronized
- {
- get
- {
- return true;
- }
- }
- public override Object SyncRoot
- {
- get
- {
- return table.SyncRoot;
- }
- }
-
- // Implement the IDictionary interface.
- public override void Add(KeyT key, ValueT value)
- {
- lock(SyncRoot)
- {
- table.Add(key, value);
- }
- }
- public override void Clear()
- {
- lock(SyncRoot)
- {
- table.Clear();
- }
- }
- public override bool Contains(KeyT key)
- {
- lock(SyncRoot)
- {
- return table.Contains(key);
- }
- }
- public override IDictionaryIterator<KeyT, ValueT> GetIterator()
- {
- lock(SyncRoot)
- {
- return new
SynchronizedDictIterator<KeyT, ValueT>
- (SyncRoot,
table.GetIterator());
- }
- }
- public override void Remove(KeyT key)
- {
- lock(SyncRoot)
- {
- table.Remove(key);
- }
- }
- public override bool IsFixedSize
- {
- get
- {
- lock(SyncRoot)
- {
- return
table.IsFixedSize;
- }
- }
- }
- public override bool IsReadOnly
- {
- get
- {
- lock(SyncRoot)
- {
- return table.IsReadOnly;
- }
- }
- }
- public override ValueT this[KeyT key]
- {
- get
- {
- lock(SyncRoot)
- {
- return table[key];
- }
- }
- set
- {
- lock(SyncRoot)
- {
- table[key] = value;
- }
- }
- }
- public override ICollection<KeyT> Keys
- {
- get
- {
- lock(SyncRoot)
- {
- return table.Keys;
- }
- }
- }
- public override ICollection<ValueT> Values
- {
- get
- {
- lock(SyncRoot)
- {
- return table.Values;
- }
- }
- }
-
- // Determine if this hash table contains a specific key.
- public override bool ContainsKey(KeyT key)
- {
- lock(SyncRoot)
- {
- return table.ContainsKey(key);
- }
- }
-
- // Determine if this hash table contains a specific value.
- public override bool ContainsValue(ValueT value)
- {
- lock(SyncRoot)
- {
- return
table.ContainsValue(value);
- }
- }
-
- // Get the hash value for a key.
- protected override int GetHash(KeyT key)
- {
- // We don't lock this because it does
not modify
- // the underlying hash table, or access
fields
- // that may be modified by other
threads.
- return table.GetHash(key);
- }
-
- // Determine if an item is equal to a key value.
- protected override bool KeyEquals(KeyT item, KeyT key)
- {
- // We don't lock this because it does
not modify
- // the underlying hash table, or access
fields
- // that may be modified by other
threads.
- return table.KeyEquals(item, key);
- }
-
- // Get the hash code provider that is being used by this
instance.
- protected override IHashCodeProvider<KeyT> hcp
- {
- get
- {
- // We don't lock this because
it does not modify
- // the underlying hash table,
or access fields
- // that may be modified by
other threads.
- return table.hcp;
- }
- }
-
- // Get the comparer that is being used by this instance.
- protected override IComparer<KeyT> comparer
- {
- get
- {
- // We don't lock this because
it does not modify
- // the underlying hash table,
or access fields
- // that may be modified by
other threads.
- return table.comparer;
- }
- }
-
- }; // SynchronizedHashtable<KeyT, ValueT>
// Hashtable collection and dictionary iterator.
--- 854,857 ----
--- SynchronizedDictIterator.cs DELETED ---
--- SynchronizedIterator.cs DELETED ---
--- SynchronizedListIterator.cs DELETED ---
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/Generics SynchronizedCollection.cs,NONE,1.1 SynchronizedDeque.cs,NONE,1.1 SynchronizedDictionary.cs,NONE,1.1 SynchronizedList.cs,NONE,1.1 SynchronizedQueue.cs,NONE,1.1 SynchronizedStack.cs,NONE,1.1 ArrayList.cs,1.5,1.6 ArrayQueue.cs,1.3,1.4 ArrayStack.cs,1.3,1.4 Hashtable.cs,1.3,1.4 SynchronizedDictIterator.cs,1.3,NONESynchronizedIterator.cs,1.3,NONE SynchronizedListIterator.cs,1.2,NONE,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnetlib ChangeLog,1.715,1.716
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/Generics DictionaryEnumeratorAdapter.cs,1.2,1.3 DictionaryEnumeratorWrapper.cs,1.2,1.3 FixedSizeDictionary.cs,1.2,1.3 Hashtable.cs,1.4,1.5 IDictionaryIterator.cs,1.2,1.3 ReadOnlyDictionary.cs,1.3,1.4 SynchronizedDictionary.cs,1.1,1.2
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnetlib ChangeLog,1.715,1.716
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/Generics DictionaryEnumeratorAdapter.cs,1.2,1.3 DictionaryEnumeratorWrapper.cs,1.2,1.3 FixedSizeDictionary.cs,1.2,1.3 Hashtable.cs,1.4,1.5 IDictionaryIterator.cs,1.2,1.3 ReadOnlyDictionary.cs,1.3,1.4 SynchronizedDictionary.cs,1.1,1.2
- Index(es):