Permalink
Browse files

changed license.

  • Loading branch information...
1 parent 9bab566 commit 259d5fb968489ee75cc027c97594a96175d4f597 @atheken committed Feb 23, 2010
Showing with 40 additions and 15 deletions.
  1. +24 −0 LICENSE.txt
  2. +15 −15 NoRM/BSON/ExpandoProps.cs
  3. +1 −0 README.markdown
View
@@ -0,0 +1,24 @@
+Copyright (c) 2010, Andrew T. Theken
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the <organization> nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -12,20 +12,20 @@ namespace NoRM.BSON
public static class ExpandoProps
{
private static Dictionary<WeakReference, Flyweight> _expandoProps = new Dictionary<WeakReference, Flyweight>(0);
- private static ReaderWriterLockSlim _dictionaryLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
+ private static ReaderWriterLock _dictionaryLock = new ReaderWriterLock();
private static String _lockToken = "LOCK_THREAD";
private static Thread _scrubExpandos;
public static Flyweight FlyweightForObject<T>(T document)
{
Flyweight retval = null;
- ExpandoProps._dictionaryLock.EnterReadLock();
+ ExpandoProps._dictionaryLock.AcquireReaderLock(30000);
var p = ExpandoProps._expandoProps.FirstOrDefault(y => y.Key.Target == (object)document);
if (p.Value != null)
{
retval = p.Value;
}
- ExpandoProps._dictionaryLock.ExitReadLock();
+ ExpandoProps._dictionaryLock.ReleaseReaderLock();
return retval;
}
@@ -48,12 +48,12 @@ public static void SetFlyWeightObjects(IDictionary<WeakReference, Flyweight> pro
{
while (true)
{
- ExpandoProps._dictionaryLock.EnterWriteLock();
+ ExpandoProps._dictionaryLock.AcquireWriterLock(30000);
//trim the dictionary of anything where the object has been collected.
ExpandoProps._expandoProps = new Dictionary<WeakReference, Flyweight>(
ExpandoProps._expandoProps.Where(y => y.Key.IsAlive)
.ToDictionary(j => j.Key, k => k.Value));
- ExpandoProps._dictionaryLock.ExitWriteLock();
+ ExpandoProps._dictionaryLock.ReleaseWriterLock();
//wait 15 seconds before attempting to clear again.
Thread.Sleep(15000);
@@ -68,12 +68,12 @@ public static void SetFlyWeightObjects(IDictionary<WeakReference, Flyweight> pro
}
#endregion
- ExpandoProps._dictionaryLock.EnterWriteLock();
+ ExpandoProps._dictionaryLock.AcquireWriterLock(30000);
foreach (var a in props)
{
ExpandoProps._expandoProps[a.Key] = a.Value;
}
- ExpandoProps._dictionaryLock.ExitWriteLock();
+ ExpandoProps._dictionaryLock.ReleaseWriterLock();
}
/// <summary>
@@ -85,7 +85,7 @@ public static void SetFlyWeightObjects(IDictionary<WeakReference, Flyweight> pro
/// <param name="property"></param>
public static void Set<T>(this IFlyweight obj, String propertyName, T property)
{
- ExpandoProps._dictionaryLock.EnterWriteLock();
+ ExpandoProps._dictionaryLock.AcquireWriterLock(30000);
var dict = ExpandoProps._expandoProps.FirstOrDefault(y => y.Key.Target == (object)obj);
if (dict.Key == null)
@@ -94,7 +94,7 @@ public static void Set<T>(this IFlyweight obj, String propertyName, T property)
ExpandoProps._expandoProps[reference] = new Flyweight();
}
ExpandoProps._expandoProps[dict.Key][propertyName] = property;
- ExpandoProps._dictionaryLock.ExitWriteLock();
+ ExpandoProps._dictionaryLock.ReleaseLock();
}
/// <summary>
@@ -106,24 +106,24 @@ public static void Set<T>(this IFlyweight obj, String propertyName, T property)
public static bool DeleteProperty(this IFlyweight obj, String propertyName)
{
bool retval = false;
- ExpandoProps._dictionaryLock.EnterWriteLock();
+ ExpandoProps._dictionaryLock.AcquireWriterLock(30000);
var dict = ExpandoProps._expandoProps.FirstOrDefault(y => y.Key.Target == (object)obj);
dict.Value.DeleteProperty(propertyName);
- ExpandoProps._dictionaryLock.ExitWriteLock();
+ ExpandoProps._dictionaryLock.ReleaseWriterLock();
return retval;
}
public static IEnumerable<ExpandoProperty> AllProperties(this IFlyweight obj)
{
var retval = Enumerable.Empty<ExpandoProperty>();
- ExpandoProps._dictionaryLock.EnterReadLock();
+ ExpandoProps._dictionaryLock.AcquireReaderLock(30000);
var dict = ExpandoProps._expandoProps.FirstOrDefault(y => y.Key.Target == (object)obj);
if (dict.Key != null && dict.Value != null)
{
retval = dict.Value.AllProperties().ToArray();
}
- ExpandoProps._dictionaryLock.ExitReadLock();
+ ExpandoProps._dictionaryLock.ReleaseReaderLock();
return retval;
}
@@ -138,14 +138,14 @@ public static IEnumerable<ExpandoProperty> AllProperties(this IFlyweight obj)
{
T retval = null;
- ExpandoProps._dictionaryLock.EnterReadLock();
+ ExpandoProps._dictionaryLock.AcquireReaderLock(30000);
var dict = ExpandoProps._expandoProps.FirstOrDefault(y => y.Key.Target == (object)obj);
if (dict.Key != null && dict.Value != null)
{
var value = dict.Value.Get<T>(propertyName);
}
- ExpandoProps._dictionaryLock.ExitReadLock();
+ ExpandoProps._dictionaryLock.ReleaseReaderLock();
return retval;
}
View
@@ -0,0 +1 @@
+NoRM - Persistence is key.

0 comments on commit 259d5fb

Please sign in to comment.