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.

74 lines
1.6 KiB

  1. /***************************************************************************\
  2. *
  3. * File: Locks.h
  4. *
  5. * Description:
  6. * Locks.h defines a collection wrappers used to maintain critical sections
  7. * and other locking devices.
  8. *
  9. *
  10. * History:
  11. * 3/30/2000: JStall: Created
  12. *
  13. * Copyright (C) 2000 by Microsoft Corporation. All rights reserved.
  14. *
  15. \***************************************************************************/
  16. #if !defined(BASE__Locks_h__INCLUDED)
  17. #define BASE__Locks_h__INCLUDED
  18. #pragma once
  19. #include "List.h"
  20. class CritLock
  21. {
  22. // Construction
  23. public:
  24. inline CritLock();
  25. inline ~CritLock();
  26. // Operations
  27. public:
  28. inline void Enter();
  29. inline void Leave();
  30. inline BOOL GetThreadSafe() const;
  31. inline void SetThreadSafe(BOOL fThreadSafe);
  32. // Data
  33. protected:
  34. CRITICAL_SECTION m_cs;
  35. BOOL m_fThreadSafe;
  36. };
  37. template <class base>
  38. class AutoCleanup
  39. {
  40. public:
  41. ~AutoCleanup();
  42. void Link(base * pItem);
  43. void Delete(base * pItem);
  44. void DeleteAll();
  45. protected:
  46. GList<base> m_lstItems;
  47. CritLock m_lock;
  48. };
  49. template <class base, class derived>
  50. inline derived * New(AutoCleanup<base> & lstItems);
  51. inline BOOL IsMultiThreaded();
  52. #if 1
  53. inline long SafeIncrement(volatile long * pl);
  54. inline long SafeDecrement(volatile long * pl);
  55. inline void SafeEnter(volatile CRITICAL_SECTION * pcs);
  56. inline void SafeLeave(volatile CRITICAL_SECTION * pcs);
  57. #endif
  58. #include "Locks.inl"
  59. #endif // BASE__Locks_h__INCLUDED