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.

77 lines
1.8 KiB

  1. #ifndef NAC_LIST_H
  2. #define NAC_LIST_H
  3. #include <wtypes.h>
  4. // generic List template to be used as
  5. // a Queue or Stack
  6. template <class T> class NacList
  7. {
  8. private:
  9. typedef T *PTR_T;
  10. typedef T **PTR_PTR_T;
  11. T *m_aElements; // array of pointers
  12. int m_nSize; // number of Appended elements
  13. int m_nHeadIndex;
  14. int m_nTotalSize; // total size of queue (used+unsed slots)
  15. int m_nGrowthRate;
  16. int Grow();
  17. public:
  18. NacList(int nInitialSize, int nGrowthRate);
  19. ~NacList();
  20. bool PeekFront(T *ptr); // returns list's front (doesn't remove)
  21. bool PeekRear(T *ptr); // returns list's rear (doesn't remove)
  22. bool PushFront(const T &t); // adds to the front of the list
  23. bool PushRear(const T &t); // adds to the rear of the list
  24. bool PopFront(T *ptr); // returns and removes list's front
  25. bool PopRear(T *ptr); // returns and removes list's rear
  26. void Flush(); // marks as list empty
  27. inline int Size() {return m_nSize;}
  28. };
  29. // Thread safe version of above
  30. template <class T> class ThreadSafeList : public NacList<T>
  31. {
  32. private:
  33. CRITICAL_SECTION m_cs;
  34. public:
  35. ThreadSafeList(int nInitialSize, int nGrowthRate);
  36. ~ThreadSafeList();
  37. bool PeekFront(T *ptr); // returns list's front (doesn't remove)
  38. bool PeekRear(T *ptr); // returns list's rear (doesn't remove)
  39. bool PushFront(const T &t); // adds to the front of the list
  40. bool PushRear(const T &t); // adds to the rear of the list
  41. bool PopFront(T *ptr); // returns and removes list's front
  42. bool PopRear(T *ptr); // returns and removes list's rear
  43. void Flush();
  44. int Size();
  45. // note: we don't inherit "Grow" because it will only get
  46. // called while we are in the Critical SEction
  47. };
  48. #endif