Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1 | From 3b9b8f5f6d1b99af43e95ec0868404e552a85b73 Mon Sep 17 00:00:00 2001 |
| 2 | From: Emil Velikov <emil.l.velikov@gmail.com> |
| 3 | Date: Thu, 19 Mar 2015 22:26:11 +0000 |
| 4 | Subject: [PATCH] third_party/threads: Use PTHREAD_MUTEX_RECURSIVE by default |
| 5 | |
| 6 | PTHREAD_MUTEX_RECURSIVE_NP was used for compatibility with old glibc. |
| 7 | Although due to the_GNU_SOURCES define the portable, |
| 8 | PTHREAD_MUTEX_RECURSIVE will be available for Linuxes since at least |
| 9 | 1998. Simplify things giving us compatibility with musl which |
| 10 | apparently does not provide the non-portable define. |
| 11 | |
| 12 | Inspired by almost identical commit in mesa aead7fe2e2b(c11/threads: Use |
| 13 | PTHREAD_MUTEX_RECURSIVE by default) by Felix Janda. |
| 14 | |
| 15 | Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> |
| 16 | Reviewed-by: Chad Versace <chad.versace@intel.com> |
| 17 | --- |
| 18 | Upstream-Status: Backport |
| 19 | |
| 20 | third_party/threads/threads_posix.c | 10 ++++------ |
| 21 | 1 file changed, 4 insertions(+), 6 deletions(-) |
| 22 | |
| 23 | diff --git a/third_party/threads/threads_posix.c b/third_party/threads/threads_posix.c |
| 24 | index 5835e43..e122bf9 100644 |
| 25 | --- a/third_party/threads/threads_posix.c |
| 26 | +++ b/third_party/threads/threads_posix.c |
| 27 | @@ -26,6 +26,9 @@ |
| 28 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 29 | * DEALINGS IN THE SOFTWARE. |
| 30 | */ |
| 31 | + |
| 32 | +#define _GNU_SOURCE |
| 33 | + |
| 34 | #include <stdlib.h> |
| 35 | #ifndef assert |
| 36 | #include <assert.h> |
| 37 | @@ -150,13 +153,8 @@ int mtx_init(mtx_t *mtx, int type) |
| 38 | && type != (mtx_try|mtx_recursive)) |
| 39 | return thrd_error; |
| 40 | pthread_mutexattr_init(&attr); |
| 41 | - if ((type & mtx_recursive) != 0) { |
| 42 | -#if defined(__linux__) || defined(__linux) |
| 43 | - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); |
| 44 | -#else |
| 45 | + if ((type & mtx_recursive) != 0) |
| 46 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); |
| 47 | -#endif |
| 48 | - } |
| 49 | pthread_mutex_init(mtx, &attr); |
| 50 | pthread_mutexattr_destroy(&attr); |
| 51 | return thrd_success; |
| 52 | -- |
| 53 | 2.5.2 |
| 54 | |