mfx_critical_section.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* ****************************************************************************** *\
  2. Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. - Redistributions of source code must retain the above copyright notice,
  6. this list of conditions and the following disclaimer.
  7. - Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation
  9. and/or other materials provided with the distribution.
  10. - Neither the name of Intel Corporation nor the names of its contributors
  11. may be used to endorse or promote products derived from this software
  12. without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
  14. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. File Name: mfx_critical_section.h
  24. \* ****************************************************************************** */
  25. #if !defined(__MFX_CRITICAL_SECTION_H)
  26. #define __MFX_CRITICAL_SECTION_H
  27. #include <mfxdefs.h>
  28. namespace MFX
  29. {
  30. // Just set "critical section" instance to zero for initialization.
  31. typedef volatile mfxL32 mfxCriticalSection;
  32. // Enter the global critical section.
  33. void mfxEnterCriticalSection(mfxCriticalSection *pCSection);
  34. // Leave the global critical section.
  35. void mfxLeaveCriticalSection(mfxCriticalSection *pCSection);
  36. class MFXAutomaticCriticalSection
  37. {
  38. public:
  39. // Constructor
  40. explicit MFXAutomaticCriticalSection(mfxCriticalSection *pCSection)
  41. {
  42. m_pCSection = pCSection;
  43. mfxEnterCriticalSection(m_pCSection);
  44. }
  45. // Destructor
  46. ~MFXAutomaticCriticalSection()
  47. {
  48. mfxLeaveCriticalSection(m_pCSection);
  49. }
  50. protected:
  51. // Pointer to a critical section
  52. mfxCriticalSection *m_pCSection;
  53. private:
  54. // unimplemented by intent to make this class non-copyable
  55. MFXAutomaticCriticalSection(const MFXAutomaticCriticalSection &);
  56. void operator=(const MFXAutomaticCriticalSection &);
  57. };
  58. } // namespace MFX
  59. #endif // __MFX_CRITICAL_SECTION_H