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.

126 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. PList.hxx
  5. Abstract:
  6. The CPList class is similar to a priority queue except that new elements
  7. are ordered after all the other elments.
  8. PList - Insert O(1) (except when the list grows..)
  9. PeekMin O(1)
  10. RemoveMin O(1)
  11. PQueue - Insert O(ln 2) (except when the list grows..)
  12. PeekMin O(1)
  13. RemoveMin O(ln 2)
  14. The PListElement are designed to be embedded in a larger
  15. object and a macro used to get for the embedded PList element
  16. back to the original object.
  17. Author:
  18. Mario Goertzel [MarioGo]
  19. Revision History:
  20. MarioGo 02-22-95 Bits 'n pieces
  21. MarioGo 12-15-95 Change to embedded object.
  22. --*/
  23. #ifndef __PLIST_HXX
  24. #define __PLIST_HXX
  25. class CPList;
  26. class CPListElement : public CListElement
  27. {
  28. friend class CPList;
  29. friend class CServerOidPList;
  30. public:
  31. CPListElement() : _timeout(0) {
  32. }
  33. private:
  34. CTime _timeout;
  35. protected:
  36. CTime *
  37. GetTimeout() { return(&_timeout); }
  38. void
  39. SetTimeout(const CTime &timeout) { _timeout = timeout; }
  40. CPListElement *Next() {
  41. return( (CPListElement *) CListElement::Next());
  42. }
  43. CPListElement *Previous() {
  44. return( (CPListElement *) CListElement::Previous());
  45. }
  46. };
  47. class CServerOidPList;
  48. class CPList : public CList
  49. {
  50. friend class CServerOidPList;
  51. private:
  52. DWORD _timeout;
  53. CRITICAL_SECTION _lock;
  54. public:
  55. CPList(ORSTATUS &status, DWORD timeout) :
  56. _timeout(timeout)
  57. {
  58. NTSTATUS ntstatus = RtlInitializeCriticalSection(&_lock);
  59. status = NT_SUCCESS(ntstatus) ? OR_OK : OR_NOMEM;
  60. }
  61. ~CPList() {
  62. ASSERT(0); // Unused - would delete the critical section.
  63. // And unlink all (any?) elements in the list.
  64. }
  65. void
  66. Insert(
  67. IN CPListElement *p
  68. );
  69. CPListElement *
  70. Remove(CPListElement *);
  71. BOOL PeekMin(CTime &timeout);
  72. CListElement *
  73. MaybeRemoveMin(CTime &when);
  74. void Reset(CPListElement *);
  75. CPListElement *First() {
  76. return( (CPListElement *) CList::First());
  77. }
  78. CPListElement *Last() {
  79. return( (CPListElement *) CList::Last());
  80. }
  81. };
  82. #endif