diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b54f7a77..445c441a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ - Add option to set debug log level. ([#1107](https://github.com/getsentry/sentry-native/pull/1107)) - Provide support for C++17 compilers when using the `crashpad` backend. ([#1110](https://github.com/getsentry/sentry-native/pull/1110), [crashpad#116](https://github.com/getsentry/crashpad/pull/116), [mini_chromium#1](https://github.com/getsentry/mini_chromium/pull/1)) +**Fixes**: + +- Provide a mutex-initializer on platforms that have no static pthread initializer for recursive mutexes. ([#1113](https://github.com/getsentry/sentry-native/pull/1113)) + ## 0.7.17 **Features**: diff --git a/src/sentry_sync.h b/src/sentry_sync.h index 0b7bc033a..9650d3d6d 100644 --- a/src/sentry_sync.h +++ b/src/sentry_sync.h @@ -262,14 +262,29 @@ typedef pthread_cond_t sentry_cond_t; PTHREAD_MUTEX_RECURSIVE \ } \ } +# elif defined(__FreeBSD__) +// Don't define `SENTRY__MUTEX_INIT` but instead provide a new definition that +// can be used by platforms requiring dynamic recursive mutex initialization. +# define SENTRY__MUTEX_INIT_DYN # else # define SENTRY__MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER # endif -# define sentry__mutex_init(Mutex) \ - do { \ - sentry_mutex_t tmp = SENTRY__MUTEX_INIT; \ - *(Mutex) = tmp; \ - } while (0) +# ifdef SENTRY__MUTEX_INIT_DYN +# define sentry__mutex_init(Mutex) \ + do { \ + pthread_mutexattr_t attr; \ + pthread_mutexattr_init(&attr); \ + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \ + pthread_mutex_init(Mutex, &attr); \ + pthread_mutexattr_destroy(&attr); \ + } while (0) +# else +# define sentry__mutex_init(Mutex) \ + do { \ + sentry_mutex_t tmp = SENTRY__MUTEX_INIT; \ + *(Mutex) = tmp; \ + } while (0) +# endif # define sentry__mutex_lock(Mutex) \ do { \ if (sentry__block_for_signal_handler()) { \