Source code of Windows XP (NT5)
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.

53 lines
1.7 KiB

  1. /*M*
  2. // INTEL CORPORATION PROPRIETARY INFORMATION
  3. // This software is supplied under the terms of a licence agreement or
  4. // nondisclosure agreement with Intel Corporation and may not be copied
  5. // or disclosed except in accordance with the terms of that agreement.
  6. // Copyright (c) 1996 Intel Corporation. All Rights Reserved.
  7. //
  8. // Filename : AutoLock.cpp
  9. // Purpose : Implementation file for the auto-locking C++
  10. // object which uses scoping to cleanly handle
  11. // entrance and exiting of critical sections.
  12. // Contents : CAutoLock Class
  13. *M*/
  14. #ifndef _AUTOLOCK_H_
  15. #define _AUTOLOCK_H_
  16. /*C*
  17. // Name : CAutoLock
  18. // Purpose : Uses scoping rules to automatically enter and leave
  19. // a critical section.
  20. // Context : Enters a specified critical section upon construction.
  21. // Leaves the critical section upon destruction.
  22. // Params :
  23. // pcs Parameter passed to constructor specifying CS to acquire.
  24. // Members :
  25. // m_pcs Stores critical section for use in leaving upon destructions.
  26. // Notes :
  27. // Copied wholesale from ActiveMovie SDK, modified to use CRITICAL_SECTIONs
  28. // directly instead of the CCritSec construct used in ActiveMovie.
  29. *C*/
  30. #if !defined(PPM_IN_DXMRTP)
  31. struct CAutoLock {
  32. #else
  33. #define CAutoLock PPMCAutoLock
  34. struct PPMCAutoLock {
  35. #endif
  36. public:
  37. // make copy constructor and assignment operator inaccessible
  38. CAutoLock(const CAutoLock &refThreadAutoLock);
  39. CAutoLock &operator=(const CAutoLock &refThreadAutoLock);
  40. CAutoLock(CRITICAL_SECTION * pcs) : m_pcs(pcs)
  41. {
  42. EnterCriticalSection(pcs);
  43. };
  44. ~CAutoLock() {
  45. LeaveCriticalSection(m_pcs);
  46. };
  47. private:
  48. CRITICAL_SECTION * m_pcs;
  49. }; /* struct CAutoLock */
  50. #endif _AUTOLOCK_H_