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.

76 lines
2.0 KiB

  1. /*
  2. *
  3. * NOTES:
  4. *
  5. * ProtectedList:
  6. *
  7. * Wraps the List class with a mutex lock. Each public method is
  8. * protected first by accessing the mutex. The entire list can
  9. * be grabbed by using Access, ungrabbed by calling Release.
  10. * You would want to Access the list almost always when using it,
  11. * otherwise other threads could change the list without your
  12. * knowledge, exactly what this class is trying to prevent
  13. *
  14. * REVISIONS:
  15. * pcy29Nov92: Use PObj rather than PNode for return values
  16. * pcy21Apr93: OS2 FE merge
  17. * cad09Jul93: using new semaphores
  18. * cad31Aug93: removing compiler warnings
  19. * pcy08Apr94: Trim size, use static iterators, dead code removal
  20. * mwh05May94: #include file madness , part 2
  21. * mwh08Apr97: add Access,Release methods & NOTES section
  22. */
  23. #ifndef _PROTLIST_H
  24. #define _PROTLIST_H
  25. #include "list.h"
  26. _CLASSDEF(ProtectedList)
  27. _CLASSDEF(MutexLock)
  28. class ProtectedList : public List {
  29. private:
  30. PMutexLock accessLock;
  31. protected:
  32. VOID Request() const;
  33. VOID Clear() const;
  34. public:
  35. ProtectedList ();
  36. ProtectedList(ProtectedList*);
  37. virtual ~ProtectedList();
  38. virtual VOID Add( RObj );
  39. virtual VOID Detach( RObj );
  40. virtual VOID Flush();
  41. virtual VOID FlushAll();
  42. virtual INT GetItemsInContainer() const;
  43. virtual RListIterator InitIterator() const;
  44. virtual VOID Append(PObj);
  45. virtual PObj GetHead();
  46. virtual PObj Find(PObj);
  47. //
  48. // Use Access to lock the entire list object
  49. // useful to block access completely to any other thread
  50. // while one thread uses the list - don't forget to
  51. // call Release when you're done - NOTE: although it
  52. // is possible to still access this object w/o calling
  53. // Access first, all of the public calls are protected
  54. // by first trying to gain Access to the object first
  55. //
  56. VOID Access() const;
  57. //
  58. // Unlocks a list object that has been locked
  59. // by a thread
  60. //
  61. VOID Release() const;
  62. };
  63. #endif