summaryrefslogtreecommitdiff
path: root/lib/infrastructure/threading/PerThread.cs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/infrastructure/threading/PerThread.cs')
-rw-r--r--[-rwxr-xr-x]lib/infrastructure/threading/PerThread.cs118
1 files changed, 59 insertions, 59 deletions
diff --git a/lib/infrastructure/threading/PerThread.cs b/lib/infrastructure/threading/PerThread.cs
index eb09756..6eed137 100755..100644
--- a/lib/infrastructure/threading/PerThread.cs
+++ b/lib/infrastructure/threading/PerThread.cs
@@ -1,59 +1,59 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Threading;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading
-{
- public class PerThread : Context
- {
- readonly IDictionary<int, LocalDataStoreSlot> slots;
- readonly object mutex = new object();
-
- public PerThread()
- {
- slots = new Dictionary<int, LocalDataStoreSlot>();
- }
-
- public bool contains<T>(Key<T> key)
- {
- return key.is_found_in(get_items());
- }
-
- public void add<T>(Key<T> key, T value)
- {
- key.add_value_to(get_items(), value);
- }
-
- public T value_for<T>(Key<T> key)
- {
- return key.parse_from(get_items());
- }
-
- public void remove<T>(Key<T> key)
- {
- key.remove_from(get_items());
- }
-
- IDictionary get_items()
- {
- var id = Thread.CurrentThread.ManagedThreadId;
- within_lock(() =>
- {
- if (!slots.ContainsKey(id))
- {
- var slot = Thread.GetNamedDataSlot(GetType().FullName);
- slots.Add(id, slot);
- Thread.SetData(slot, new Hashtable());
- }
- });
- return (IDictionary) Thread.GetData(slots[id]);
- }
-
- void within_lock(Action action)
- {
- lock (mutex) action();
- }
- }
-} \ No newline at end of file
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Threading;
+using jive.utility;
+
+namespace jive.infrastructure.threading
+{
+ public class PerThread : Context
+ {
+ readonly IDictionary<int, LocalDataStoreSlot> slots;
+ readonly object mutex = new object();
+
+ public PerThread()
+ {
+ slots = new Dictionary<int, LocalDataStoreSlot>();
+ }
+
+ public bool contains<T>(Key<T> key)
+ {
+ return key.is_found_in(get_items());
+ }
+
+ public void add<T>(Key<T> key, T value)
+ {
+ key.add_value_to(get_items(), value);
+ }
+
+ public T value_for<T>(Key<T> key)
+ {
+ return key.parse_from(get_items());
+ }
+
+ public void remove<T>(Key<T> key)
+ {
+ key.remove_from(get_items());
+ }
+
+ IDictionary get_items()
+ {
+ var id = Thread.CurrentThread.ManagedThreadId;
+ within_lock(() =>
+ {
+ if (!slots.ContainsKey(id))
+ {
+ var slot = Thread.GetNamedDataSlot(GetType().FullName);
+ slots.Add(id, slot);
+ Thread.SetData(slot, new Hashtable());
+ }
+ });
+ return (IDictionary) Thread.GetData(slots[id]);
+ }
+
+ void within_lock(Action action)
+ {
+ lock (mutex) action();
+ }
+ }
+}