summaryrefslogtreecommitdiff
path: root/lib/CurrentThread.cs
blob: b2c38a61eb36a81c8f87d4d10e70debd57632928 (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
{
  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;
    }
  }
}