1 /*############################################################################
2 # Copyright (C) Intel Corporation
4 # SPDX-License-Identifier: MIT
5 ############################################################################*/
7 #include "windows/mfx_critical_section.h"
10 // SDK re-declares the following functions with different call declarator.
11 // We don't need them. Just redefine them to nothing.
12 #define _interlockedbittestandset fake_set
13 #define _interlockedbittestandreset fake_reset
14 #define _interlockedbittestandset64 fake_set64
15 #define _interlockedbittestandreset64 fake_reset64
18 #define MFX_WAIT() SwitchToThread()
20 // static section of the file
23 enum { MFX_SC_IS_FREE = 0, MFX_SC_IS_TAKEN = 1 };
29 mfxU32 mfxInterlockedCas32(mfxCriticalSection *pCSection,
30 mfxU32 value_to_exchange,
31 mfxU32 value_to_compare) {
32 return _InterlockedCompareExchange(pCSection, value_to_exchange, value_to_compare);
35 mfxU32 mfxInterlockedXchg32(mfxCriticalSection *pCSection, mfxU32 value) {
36 return _InterlockedExchange(pCSection, value);
39 void mfxEnterCriticalSection(mfxCriticalSection *pCSection) {
40 while (MFX_SC_IS_TAKEN == mfxInterlockedCas32(pCSection, MFX_SC_IS_TAKEN, MFX_SC_IS_FREE)) {
43 } // void mfxEnterCriticalSection(mfxCriticalSection *pCSection)
45 void mfxLeaveCriticalSection(mfxCriticalSection *pCSection) {
46 mfxInterlockedXchg32(pCSection, MFX_SC_IS_FREE);
47 } // void mfxLeaveCriticalSection(mfxCriticalSection *pCSection)