File no-nsync.patch of Package python-onnxruntime

commit 62a481571321e592cc612247f936b0d62bac7405
Author: Alejandro Álvarez Ayllón <a.alvarezayllon@gmail.com>
Date:   Mon Jun 5 13:08:13 2023 +0000

    Drop nsync

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index f97cc69249..2bbf6215c5 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -853,7 +853,7 @@ function(onnxruntime_set_compile_flags target_name)
         target_compile_options(${target_name} PRIVATE "-Wno-unused-parameter")
       endif()
       target_compile_definitions(${target_name} PUBLIC -DNSYNC_ATOMIC_CPP11)
-      onnxruntime_add_include_to_target(${target_name} nsync::nsync_cpp)
+#      onnxruntime_add_include_to_target(${target_name} nsync::nsync_cpp)
     endif()
     foreach(ORT_FLAG ${ORT_PROVIDER_FLAGS})
       target_compile_definitions(${target_name} PRIVATE ${ORT_FLAG})
@@ -1491,7 +1491,7 @@ if (WIN32)
   list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SYS_PATH_LIB})
   list(APPEND onnxruntime_EXTERNAL_LIBRARIES debug Dbghelp)
 else()
-  list(APPEND onnxruntime_EXTERNAL_LIBRARIES nsync::nsync_cpp)
+#  list(APPEND onnxruntime_EXTERNAL_LIBRARIES nsync::nsync_cpp)
   list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${ICONV_LIB} ${CMAKE_DL_LIBS} Threads::Threads)
 endif()
 
diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake
index f2aa9a4c46..84816f24c7 100644
--- a/cmake/external/onnxruntime_external_deps.cmake
+++ b/cmake/external/onnxruntime_external_deps.cmake
@@ -64,7 +64,7 @@ if (onnxruntime_BUILD_BENCHMARKS)
   )
 endif()
 
-if (NOT WIN32)
+if (FALSE AND NOT WIN32)
     FetchContent_Declare(
     google_nsync
     URL ${DEP_URL_google_nsync}
@@ -256,7 +256,7 @@ if (onnxruntime_BUILD_BENCHMARKS)
   onnxruntime_fetchcontent_makeavailable(google_benchmark)
 endif()
 
-if (NOT WIN32)
+if (FALSE AND NOT WIN32)
   #nsync tests failed on Mac Build
   set(NSYNC_ENABLE_TESTS OFF CACHE BOOL "" FORCE)
   onnxruntime_fetchcontent_makeavailable(google_nsync)
diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake
index 09723613e4..8e75ab7477 100644
--- a/cmake/onnxruntime_unittests.cmake
+++ b/cmake/onnxruntime_unittests.cmake
@@ -687,7 +687,7 @@ if(MSVC)
 else()
   target_compile_definitions(onnxruntime_test_utils PUBLIC -DNSYNC_ATOMIC_CPP11)
   target_include_directories(onnxruntime_test_utils PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT})
-  onnxruntime_add_include_to_target(onnxruntime_test_utils nsync::nsync_cpp)
+  #  onnxruntime_add_include_to_target(onnxruntime_test_utils nsync::nsync_cpp)
 endif()
 if (onnxruntime_USE_NCCL)
   target_include_directories(onnxruntime_test_utils PRIVATE ${NCCL_INCLUDE_DIRS})
@@ -721,7 +721,7 @@ if(MSVC)
 else()
   target_compile_definitions(onnx_test_runner_common PUBLIC -DNSYNC_ATOMIC_CPP11)
   target_include_directories(onnx_test_runner_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT})
-  onnxruntime_add_include_to_target(onnx_test_runner_common nsync::nsync_cpp)
+  #  onnxruntime_add_include_to_target(onnx_test_runner_common nsync::nsync_cpp)
 endif()
 if (MSVC AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
   #TODO: fix the warnings, they are dangerous
@@ -1088,7 +1088,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
       # "Global initializer calls a non-constexpr function." BENCHMARK_CAPTURE macro needs this.
       target_compile_options(onnxruntime_mlas_benchmark PRIVATE /wd26426)
     else()
-      target_link_libraries(onnxruntime_mlas_benchmark PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS})
+#      target_link_libraries(onnxruntime_mlas_benchmark PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS})
     endif()
     if (CPUINFO_SUPPORTED AND NOT onnxruntime_BUILD_WEBASSEMBLY)
       target_link_libraries(onnxruntime_mlas_benchmark PRIVATE cpuinfo)
@@ -1165,7 +1165,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
             ${onnxruntime_EXTERNAL_LIBRARIES}
             ${GETOPT_LIB_WIDE} ${SYS_PATH_LIB} ${CMAKE_DL_LIBS})
     if(NOT WIN32)
-      list(APPEND onnxruntime_perf_test_libs nsync::nsync_cpp)
+      #list(APPEND onnxruntime_perf_test_libs nsync::nsync_cpp)
       if(onnxruntime_USE_SNPE)
         list(APPEND onnxruntime_perf_test_libs onnxruntime_providers_snpe)
       endif()
@@ -1209,7 +1209,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
     # test inference using shared lib
     set(onnxruntime_shared_lib_test_LIBS onnxruntime_mocked_allocator onnxruntime_test_utils onnxruntime_common onnx_proto)
     if(NOT WIN32)
-      list(APPEND onnxruntime_shared_lib_test_LIBS nsync::nsync_cpp)
+      #list(APPEND onnxruntime_shared_lib_test_LIBS nsync::nsync_cpp)
       if(onnxruntime_USE_SNPE)
         list(APPEND onnxruntime_shared_lib_test_LIBS onnxruntime_providers_snpe)
       endif()
@@ -1333,9 +1333,9 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
   if (CPUINFO_SUPPORTED AND NOT onnxruntime_BUILD_WEBASSEMBLY)
     target_link_libraries(onnxruntime_mlas_test PRIVATE cpuinfo)
   endif()
-  if(NOT WIN32)
-    target_link_libraries(onnxruntime_mlas_test PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS})
-  endif()
+  # if(NOT WIN32)
+  #    target_link_libraries(onnxruntime_mlas_test PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS})
+  # endif()
   if (CMAKE_SYSTEM_NAME STREQUAL "Android")
     target_link_libraries(onnxruntime_mlas_test PRIVATE ${android_shared_libs})
   endif()
@@ -1569,9 +1569,9 @@ if (onnxruntime_BUILD_SHARED_LIB AND NOT onnxruntime_BUILD_WEBASSEMBLY AND NOT o
 
   set(onnxruntime_logging_apis_test_LIBS onnxruntime_common onnxruntime_test_utils)
 
-  if(NOT WIN32)
-    list(APPEND onnxruntime_logging_apis_test_LIBS nsync::nsync_cpp ${CMAKE_DL_LIBS})
-  endif()
+  #if(NOT WIN32)
+  #  list(APPEND onnxruntime_logging_apis_test_LIBS nsync::nsync_cpp ${CMAKE_DL_LIBS})
+  #endif()
 
   AddTest(DYN
           TARGET onnxruntime_logging_apis_test
diff --git a/include/onnxruntime/core/platform/ort_mutex.h b/include/onnxruntime/core/platform/ort_mutex.h
index e24665f514..2ea727284c 100644
--- a/include/onnxruntime/core/platform/ort_mutex.h
+++ b/include/onnxruntime/core/platform/ort_mutex.h
@@ -102,13 +102,13 @@ std::cv_status OrtCondVar::wait_for(std::unique_lock<OrtMutex>& cond_mutex,
 }
 }  // namespace onnxruntime
 #else
-#include "nsync.h"
+#include <pthread.h>
 #include <mutex>               //for unique_lock
 #include <condition_variable>  //for cv_status
 namespace onnxruntime {
 
 class OrtMutex {
-  nsync::nsync_mu data_ = NSYNC_MU_INIT;
+  pthread_mutex_t data_ = PTHREAD_MUTEX_INITIALIZER;
 
  public:
   constexpr OrtMutex() = default;
@@ -116,16 +116,16 @@ class OrtMutex {
   OrtMutex(const OrtMutex&) = delete;
   OrtMutex& operator=(const OrtMutex&) = delete;
 
-  void lock() { nsync::nsync_mu_lock(&data_); }
-  bool try_lock() noexcept { return nsync::nsync_mu_trylock(&data_) == 0; }
-  void unlock() noexcept { nsync::nsync_mu_unlock(&data_); }
+  void lock() { pthread_mutex_lock(&data_); }
+  bool try_lock() noexcept { return pthread_mutex_lock(&data_) == 0; }
+  void unlock() noexcept { pthread_mutex_unlock(&data_); }
 
-  using native_handle_type = nsync::nsync_mu*;
+  using native_handle_type = pthread_mutex_t*;
   native_handle_type native_handle() { return &data_; }
 };
 
 class OrtCondVar {
-  nsync::nsync_cv native_cv_object = NSYNC_CV_INIT;
+  pthread_cond_t native_cv_object = PTHREAD_COND_INITIALIZER;
 
  public:
   constexpr OrtCondVar() noexcept = default;
@@ -134,8 +134,8 @@ class OrtCondVar {
   OrtCondVar(const OrtCondVar&) = delete;
   OrtCondVar& operator=(const OrtCondVar&) = delete;
 
-  void notify_one() noexcept { nsync::nsync_cv_signal(&native_cv_object); }
-  void notify_all() noexcept { nsync::nsync_cv_broadcast(&native_cv_object); }
+  void notify_one() noexcept { pthread_cond_signal(&native_cv_object); }
+  void notify_all() noexcept { pthread_cond_broadcast(&native_cv_object); }
 
   void wait(std::unique_lock<OrtMutex>& lk);
   template <class _Predicate>
@@ -151,7 +151,7 @@ class OrtCondVar {
    */
   template <class Rep, class Period>
   std::cv_status wait_for(std::unique_lock<OrtMutex>& cond_mutex, const std::chrono::duration<Rep, Period>& rel_time);
-  using native_handle_type = nsync::nsync_cv*;
+  using native_handle_type = pthread_cond_t*;
   native_handle_type native_handle() { return &native_cv_object; }
 
  private:
diff --git a/onnxruntime/core/platform/posix/ort_mutex.cc b/onnxruntime/core/platform/posix/ort_mutex.cc
index e124ce1680..53977938f4 100644
--- a/onnxruntime/core/platform/posix/ort_mutex.cc
+++ b/onnxruntime/core/platform/posix/ort_mutex.cc
@@ -27,7 +27,7 @@ void OrtCondVar::timed_wait_impl(std::unique_lock<OrtMutex>& lk,
     abs_deadline.tv_sec = ts_sec_max;
     abs_deadline.tv_nsec = 999999999;
   }
-  nsync::nsync_cv_wait_with_deadline(&native_cv_object, lk.mutex()->native_handle(), abs_deadline, nullptr);
+  pthread_cond_timedwait(&native_cv_object, lk.mutex()->native_handle(), &abs_deadline);
 }
 
 void OrtCondVar::wait(std::unique_lock<OrtMutex>& lk) {
@@ -36,7 +36,7 @@ void OrtCondVar::wait(std::unique_lock<OrtMutex>& lk) {
     ORT_THROW("OrtCondVar wait failed: mutex not locked");
   }
 #endif
-  nsync::nsync_cv_wait(&native_cv_object, lk.mutex()->native_handle());
+  pthread_cond_wait(&native_cv_object, lk.mutex()->native_handle());
 }
 
-}  // namespace onnxruntime
\ No newline at end of file
+}  // namespace onnxruntime
openSUSE Build Service is sponsored by