Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.3 KiB

  1. /*
  2. *
  3. * NOTES:
  4. *
  5. * REVISIONS:
  6. * ane12Jan93: made Threadable an updateable object
  7. * pcy04Mar93: spilt off from thread. thrdable is not OS specific.
  8. * rct17May93: added IsA() method
  9. * cad19May93: defined IsA() to default (tired of fixing children)
  10. * cad09Jul93: using new semaphores
  11. * cad07Oct93: Made methods virtual
  12. * rct16Nov93: Added single thread implementation
  13. * cad11Jan94: Changes for new process manager
  14. * ajr02May95: Need to stop carrying time in milliseconds
  15. */
  16. #ifndef _THRDABLE_H
  17. #define _THRDABLE_H
  18. #include "_defs.h"
  19. _CLASSDEF(Threadable)
  20. #include "apc.h"
  21. #include "update.h"
  22. #include "semaphor.h"
  23. /* const LONG DEFAULT_SERVICE_PERIOD = 10000L; // Ten Seconds */
  24. /* const ULONG THREAD_EXIT_TIMEOUT = 1000L; */
  25. const LONG DEFAULT_SERVICE_PERIOD = 10; // Ten Seconds
  26. const ULONG THREAD_EXIT_TIMEOUT = 1; // one second;
  27. const INT MAX_THREAD_NAME = 32;
  28. class Threadable : public UpdateObj {
  29. protected:
  30. PSemaphore theResumeFlag;
  31. PSemaphore theExitSem;
  32. PSemaphore theExitDoneSem;
  33. CHAR theThreadName[MAX_THREAD_NAME+1];
  34. #ifdef SINGLETHREADED
  35. ULONG theServicePeriod;
  36. ULONG theLastPeriod;
  37. ULONG theNextPeriod;
  38. #endif
  39. INT ExitNow();
  40. INT DoneExiting();
  41. public:
  42. Threadable ();
  43. virtual ~Threadable ();
  44. virtual VOID ThreadMain () = 0;
  45. virtual VOID SetThreadName(PCHAR aName);
  46. virtual PCHAR GetThreadName(VOID);
  47. #ifdef SINGLETHREADED
  48. virtual ULONG GetServicePeriod() const;
  49. virtual VOID SetServicePeriod(ULONG period = DEFAULT_SERVICE_PERIOD);
  50. virtual ULONG GetLastPeriod(void);
  51. virtual VOID SetLastPeriod(ULONG period = 0L);
  52. virtual ULONG GetNextPeriod(void);
  53. virtual VOID SetNextPeriod(ULONG period = 0L);
  54. #endif
  55. virtual INT Wait () {return theResumeFlag->Wait();};
  56. virtual INT Release () {return theResumeFlag->Pulse();};
  57. virtual INT Exit();
  58. virtual INT ExitWait();
  59. #if (C_OS & C_NLM)
  60. virtual SLONG TimedWait(SLONG msDelay) { return theResumeFlag->TimedWait(msDelay); };
  61. #else
  62. virtual INT TimedWait(INT msDelay) { return theResumeFlag->TimedWait(msDelay); };
  63. #endif
  64. virtual INT Equal(RObj anObj) const { return ((PObj) this == &anObj); };
  65. virtual INT Reset();
  66. };
  67. #endif