SmartThreadPool.ThreadEntry.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Amib.Threading.Internal;
  2. using System;
  3. using System.Threading;
  4. namespace Amib.Threading
  5. {
  6. public partial class SmartThreadPool
  7. {
  8. #region ThreadEntry class
  9. internal class ThreadEntry
  10. {
  11. /// <summary>
  12. /// The thread creation time
  13. /// The value is stored as UTC value.
  14. /// </summary>
  15. private readonly DateTime _creationTime;
  16. /// <summary>
  17. /// The last time this thread has been running
  18. /// It is updated by IAmAlive() method
  19. /// The value is stored as UTC value.
  20. /// </summary>
  21. private DateTime _lastAliveTime;
  22. /// <summary>
  23. /// A reference from each thread in the thread pool to its SmartThreadPool
  24. /// object container.
  25. /// With this variable a thread can know whatever it belongs to a
  26. /// SmartThreadPool.
  27. /// </summary>
  28. private SmartThreadPool _associatedSmartThreadPool;
  29. /// <summary>
  30. /// A reference to the current work item a thread from the thread pool
  31. /// is executing.
  32. /// </summary>
  33. public WorkItem CurrentWorkItem { get; set; }
  34. public Thread WorkThread;
  35. public ThreadEntry(SmartThreadPool stp, Thread th)
  36. {
  37. _associatedSmartThreadPool = stp;
  38. _creationTime = DateTime.UtcNow;
  39. _lastAliveTime = DateTime.MinValue;
  40. WorkThread = th;
  41. }
  42. public SmartThreadPool AssociatedSmartThreadPool
  43. {
  44. get { return _associatedSmartThreadPool; }
  45. }
  46. public void IAmAlive()
  47. {
  48. _lastAliveTime = DateTime.UtcNow;
  49. }
  50. public void Clean()
  51. {
  52. WorkThread = null;
  53. _associatedSmartThreadPool = null;
  54. }
  55. }
  56. #endregion
  57. }
  58. }