59-mutex.patch 2.0 KB

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