Ticket #68716: patch-have_shared_mutex.diff

File patch-have_shared_mutex.diff, 2.0 KB (added by nilason (Nicklas Larsson), 6 months ago)

patch

  • cmake/template/cpl_config.h.in

    old new  
    175175/* Define to 1 if you have the `sched_getaffinity' function. */
    176176#cmakedefine HAVE_SCHED_GETAFFINITY 1
    177177
     178/* Define to 1 if you have the `std::shared_mutex' function. */
     179#cmakedefine HAVE_SHARED_MUTEX 1
     180
    178181/* Define to 1 if you have the `uselocale' function. */
    179182#cmakedefine HAVE_USELOCALE 1
    180183
  • cmake/helpers/configure.cmake

    
            
    old new  
    358358    set(DONT_DEPRECATE_SPRINTF 1)
    359359    add_definitions(-DDONT_DEPRECATE_SPRINTF)
    360360  endif ()
     361 
     362  check_cxx_source_compiles(
     363    "
     364    #include <mutex>
     365    #include <shared_mutex>
     366    int main(int argc, const char * argv[]) {
     367        std::shared_mutex smtx;
     368        int product = 0;
     369        auto writer = [&smtx, &product](int start, int end)
     370        {
     371            for (int i = start; i < end; ++i)
     372            {
     373                auto data = i;
     374                {
     375                    std::unique_lock<std::shared_mutex> lock(smtx);
     376                    product = data;
     377                }
     378            }
     379            smtx.lock();
     380            smtx.unlock();
     381        };
     382        auto reader = [&smtx, &product]()
     383        {
     384            int data = 0;
     385            std::vector<int> seen;
     386            do
     387            {
     388                {
     389                    smtx.lock_shared();
     390                    data = product;
     391                    smtx.unlock_shared();
     392                }
     393            }
     394            while (1);
     395        };
     396        return 0;
     397    }
     398    "
     399    HAVE_SHARED_MUTEX
     400  )
    361401
    362402  check_include_file("linux/userfaultfd.h" HAVE_USERFAULTFD_H)
    363403endif ()
  • port/cpl_vsi_mem.cpp

    
            
    old new  
    5050
    5151#include <mutex>
    5252// c++17 or VS2017
    53 #if __cplusplus >= 201703L || _MSC_VER >= 1910
     53#if defined(HAVE_SHARED_MUTEX) || _MSC_VER >= 1910
    5454#include <shared_mutex>
    5555#define CPL_SHARED_MUTEX_TYPE std::shared_mutex
    5656#define CPL_SHARED_LOCK std::shared_lock<std::shared_mutex>