blob: a0c826ed93309e8d4016581ba998c13cbcb38aca [file] [log] [blame]
Patrick Williamsf1e5d692016-03-30 15:21:19 -05001From 3b9b8f5f6d1b99af43e95ec0868404e552a85b73 Mon Sep 17 00:00:00 2001
2From: Emil Velikov <emil.l.velikov@gmail.com>
3Date: Thu, 19 Mar 2015 22:26:11 +0000
4Subject: [PATCH] third_party/threads: Use PTHREAD_MUTEX_RECURSIVE by default
5
6PTHREAD_MUTEX_RECURSIVE_NP was used for compatibility with old glibc.
7Although due to the_GNU_SOURCES define the portable,
8PTHREAD_MUTEX_RECURSIVE will be available for Linuxes since at least
91998. Simplify things giving us compatibility with musl which
10apparently does not provide the non-portable define.
11
12Inspired by almost identical commit in mesa aead7fe2e2b(c11/threads: Use
13PTHREAD_MUTEX_RECURSIVE by default) by Felix Janda.
14
15Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
16Reviewed-by: Chad Versace <chad.versace@intel.com>
17---
18Upstream-Status: Backport
19
20 third_party/threads/threads_posix.c | 10 ++++------
21 1 file changed, 4 insertions(+), 6 deletions(-)
22
23diff --git a/third_party/threads/threads_posix.c b/third_party/threads/threads_posix.c
24index 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--
532.5.2
54