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.

107 lines
1.6 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Plist.cxx
  5. Abstract:
  6. Implementation of the CPList class.
  7. Author:
  8. Mario Goertzel [MarioGo]
  9. Revision History:
  10. MarioGo 02-24-95 Bits 'n pieces
  11. --*/
  12. #include<or.hxx>
  13. void
  14. CPList::Insert(CPListElement *p)
  15. {
  16. CMutexLock lock(&this->_lock);
  17. CTime time;
  18. time += _timeout;
  19. p->SetTimeout(time);
  20. this->CList::Insert(p);
  21. }
  22. BOOL
  23. CPList::PeekMin(CTime &timeout)
  24. // inline?
  25. {
  26. CTime *pT;
  27. CMutexLock lock(&this->_lock);
  28. CPListElement *first = (CPListElement *)this->First();
  29. if (first && (pT = first->GetTimeout()))
  30. {
  31. timeout = *pT;
  32. return(TRUE);
  33. }
  34. return(FALSE);
  35. }
  36. CPListElement *
  37. CPList::Remove(CPListElement *p)
  38. // It must be safe to remove an element not actually in a list.
  39. {
  40. CMutexLock lock(&this->_lock);
  41. return( (CPListElement *)this->CList::Remove(p) );
  42. }
  43. CListElement *
  44. CPList::MaybeRemoveMin(
  45. IN CTime &when
  46. )
  47. {
  48. CMutexLock lock(&this->_lock);
  49. CPListElement *first = (CPListElement *)this->First();
  50. if (first && *first->GetTimeout() < when)
  51. {
  52. return(Remove(first));
  53. }
  54. return(0);
  55. }
  56. void
  57. CPList::Reset(
  58. IN CPListElement *p
  59. )
  60. {
  61. CMutexLock lock(&this->_lock);
  62. ASSERT(p);
  63. if (p->Next() == 0 && p->Previous() == 0 && First() != p)
  64. {
  65. ASSERT(Last() != p);
  66. return;
  67. }
  68. Remove(p);
  69. // Update timeout
  70. CTime now;
  71. now += _timeout;
  72. p->SetTimeout(now);
  73. Insert(p);
  74. return;
  75. }