qsv: Update SDK version to v2022.2.4
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / qsv / libmfx / dispatcher / windows / mfx_critical_section.cpp
1 /*############################################################################
2   # Copyright (C) Intel Corporation
3   #
4   # SPDX-License-Identifier: MIT
5   ############################################################################*/
6
7 #include "windows/mfx_critical_section.h"
8
9 #include <windows.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
16 #include <intrin.h>
17
18 #define MFX_WAIT() SwitchToThread()
19
20 // static section of the file
21 namespace {
22
23 enum { MFX_SC_IS_FREE = 0, MFX_SC_IS_TAKEN = 1 };
24
25 } // namespace
26
27 namespace MFX {
28
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);
33 }
34
35 mfxU32 mfxInterlockedXchg32(mfxCriticalSection *pCSection, mfxU32 value) {
36     return _InterlockedExchange(pCSection, value);
37 }
38
39 void mfxEnterCriticalSection(mfxCriticalSection *pCSection) {
40     while (MFX_SC_IS_TAKEN == mfxInterlockedCas32(pCSection, MFX_SC_IS_TAKEN, MFX_SC_IS_FREE)) {
41         MFX_WAIT();
42     }
43 } // void mfxEnterCriticalSection(mfxCriticalSection *pCSection)
44
45 void mfxLeaveCriticalSection(mfxCriticalSection *pCSection) {
46     mfxInterlockedXchg32(pCSection, MFX_SC_IS_FREE);
47 } // void mfxLeaveCriticalSection(mfxCriticalSection *pCSection)
48
49 } // namespace MFX