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.

89 lines
2.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996.
  5. //
  6. // File: workq.hxx
  7. //
  8. // Contents: A class to permit multiple threads to access work items from
  9. // queue.
  10. //
  11. // Classes: CWorkQueue
  12. //
  13. // Functions:
  14. //
  15. // Coupling:
  16. //
  17. // Notes: The queue observes FIFO
  18. //
  19. // History: 9-30-1996 ericne Created
  20. //
  21. //----------------------------------------------------------------------------
  22. #ifndef _CWORKQ
  23. #define _CWORKQ
  24. #include <windows.h>
  25. const DWORD dwSleepTime = 5000; // milliseconds
  26. //+---------------------------------------------------------------------------
  27. //
  28. // Class: CWorkQueue
  29. //
  30. // Purpose:
  31. //
  32. // Interface: CWorkQueue -- Constructor. Create semaphores
  33. // ~CWorkQueue -- Destructor. Close semaphores
  34. // AddItem -- Adds item to queue. Block if full
  35. // GetItem -- Gets item from queue. Block if empty
  36. // Done -- Sets m_hEventDone event.
  37. // m_WorkItems -- Queue
  38. // m_iAddItemIndex -- Index where next item is stored
  39. // m_iGetItemIndex -- Index of next item to retreive
  40. // m_hSemFull -- Counting semaphore. Equal to nbr full
  41. // m_hSemEmpty -- Counting semaphore. Equal to nbr empty
  42. // m_hEventDone -- Signaled after Done() method is called
  43. // m_CriticalSection -- Used for mutual exclusion.
  44. //
  45. // History: 10-03-1996 ericne Created
  46. //
  47. // Notes:
  48. //
  49. //----------------------------------------------------------------------------
  50. template<class T, int I>
  51. class CWorkQueue
  52. {
  53. public:
  54. CWorkQueue();
  55. ~CWorkQueue();
  56. void AddItem( const T & );
  57. BOOL GetItem( T & );
  58. void Done( );
  59. private:
  60. T m_WorkItems[ I ];
  61. int m_iAddItemIndex;
  62. int m_iGetItemIndex;
  63. HANDLE m_hSemFull;
  64. HANDLE m_hSemEmpty;
  65. HANDLE m_hEventDone;
  66. CRITICAL_SECTION m_CriticalSection;
  67. };
  68. #endif