59-mutex.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. diff --git a/src/mutex.cpp b/src/mutex.cpp
  2. index b165b1b..e8637f9 100644
  3. --- a/src/mutex.cpp
  4. +++ b/src/mutex.cpp
  5. @@ -12,7 +12,9 @@
  6. #include <limits>
  7. #include <mutex>
  8. +#if !defined(_LIBCPP_ABI_MICROSOFT)
  9. #include "include/atomic_support.h"
  10. +#endif
  11. #ifndef _LIBCPP_HAS_NO_THREADS
  12. # if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
  13. @@ -202,8 +204,13 @@ static constinit __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
  14. static constinit __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
  15. #endif
  16. +#ifdef _LIBCPP_ABI_MICROSOFT
  17. +void __call_once(volatile std::atomic<once_flag::_State_type>& flag, void* arg,
  18. + void (*func)(void*))
  19. +#else
  20. void __call_once(volatile once_flag::_State_type& flag, void* arg,
  21. void (*func)(void*))
  22. +#endif
  23. {
  24. #if defined(_LIBCPP_HAS_NO_THREADS)
  25. @@ -223,16 +230,28 @@ void __call_once(volatile once_flag::_State_type& flag, void* arg,
  26. if (flag == once_flag::_Unset) {
  27. auto guard = std::__make_exception_guard([&flag] {
  28. __libcpp_mutex_lock(&mut);
  29. +#ifdef _LIBCPP_ABI_MICROSOFT
  30. + flag.store(once_flag::_Unset);
  31. +#else
  32. __libcpp_relaxed_store(&flag, once_flag::_Unset);
  33. +#endif
  34. __libcpp_mutex_unlock(&mut);
  35. __libcpp_condvar_broadcast(&cv);
  36. });
  37. +#ifdef _LIBCPP_ABI_MICROSOFT
  38. + flag.store(once_flag::_Pending, memory_order_relaxed);
  39. +#else
  40. __libcpp_relaxed_store(&flag, once_flag::_Pending);
  41. +#endif
  42. __libcpp_mutex_unlock(&mut);
  43. func(arg);
  44. __libcpp_mutex_lock(&mut);
  45. +#ifdef _LIBCPP_ABI_MICROSOFT
  46. + flag.store(once_flag::_Complete, memory_order_release);
  47. +#else
  48. __libcpp_atomic_store(&flag, once_flag::_Complete, _AO_Release);
  49. +#endif
  50. __libcpp_mutex_unlock(&mut);
  51. __libcpp_condvar_broadcast(&cv);
  52. guard.__complete();