Mutex and AutoLock are not member of CV

ago_cv
Thu, 30 Nov 2023 02:40:45 +0000
C++

I set up a pretty simple project to understand if I could move to C++20 with my C++/CLI project using opencv.
Compiling with C++17 is not a problem, but if I try to compile in C++20 I get two errors:

Mutex is not a member of 'cv'
AutoiLock is not a member of 'cv'

The two culprits are in the following lines of code:

#if !defined(_M_CEE)
#ifndef OPENCV_DISABLE_THREAD_SUPPORT
typedef std::recursive_mutex Mutex;
typedef std::lock_guard<cv::Mutex> AutoLock;
#else // OPENCV_DISABLE_THREAD_SUPPORT
// Custom (failing) implementation of `std::recursive_mutex`.
struct Mutex {
    void lock(){
        CV_Error(cv::Error::StsNotImplemented,
                 "cv::Mutex is disabled by OPENCV_DISABLE_THREAD_SUPPORT=ON");
    }
    void unlock(){
        CV_Error(cv::Error::StsNotImplemented,
                 "cv::Mutex is disabled by OPENCV_DISABLE_THREAD_SUPPORT=ON");
    }
};
// Stub for cv::AutoLock when threads are disabled.
struct AutoLock {
    AutoLock(Mutex &) { }
};
#endif // OPENCV_DISABLE_THREAD_SUPPORT
#endif // !defined(_M_CEE)

Now for both C++17 and C++20 the macro _M_CEE is defined, so it never gets in here to define both Mutex and AutoLock, but still compiles without any errors. I don’t understand where these two structures are defined in C++17.

OpenCV Version: 4.5.5
OS: Windows 10 Version 22H2 build 19045.3693
Compiler: Visual C++ 2022 v143 - ISO C++20 - .NET 7.0

Could you guys help me out understanding what is happening here?

5 posts - 4 participants