summaryrefslogtreecommitdiff
path: root/lib/infrastructure/threading/CurrentThread.cs
blob: 75afa12b36e8257e265a284a5e151487d51b33c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System.Threading;

namespace jive.infrastructure.threading
{
  public class CurrentThread : ApplicationThread
  {
    public T provide_slot_for<T>() where T : class, new()
    {
      var slot = Thread.GetNamedDataSlot(create_key_for<T>());
      if (null == Thread.GetData(slot)) Thread.SetData(slot, new T());
      return (T) Thread.GetData(slot);
    }

    string create_key_for<T>()
    {
      return Thread.CurrentThread.ManagedThreadId + GetType().FullName + typeof (T).FullName;
    }
  }
}