aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/1001-add-support-for-pthread_-get-set-attr_default_np-GNU.patch
blob: 4fb120451588dfb71727ed404a30bf466d764b1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
From b699fff6d0d5765d0008dce8628305b8e26cf4d0 Mon Sep 17 00:00:00 2001
From: Leonardo Arena <rnalrd@alpinelinux.org>
Date: Tue, 1 Nov 2016 13:01:42 +0000
Subject: [PATCH] main/musl: add pthread_set_attr_default_np

---
 include/pthread.h                       |  2 ++
 src/thread/pthread_create.c             |  7 +++++++
 src/thread/pthread_setattr_default_np.c | 31 +++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+)
 create mode 100644 src/thread/pthread_setattr_default_np.c

diff --git a/include/pthread.h b/include/pthread.h
index af70b73..bbcf1d7 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -214,6 +214,8 @@ struct cpu_set_t;
 int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
 int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *);
 int pthread_getattr_np(pthread_t, pthread_attr_t *);
+int pthread_getattr_default_np(pthread_attr_t *);
+int pthread_setattr_default_np(const pthread_attr_t *);
 #endif
 
 #ifdef __cplusplus
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index e7df34a..613d7c4 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -163,6 +163,8 @@ static void *dummy_tsd[1] = { 0 };
 weak_alias(dummy_tsd, __pthread_tsd_main);
 
 volatile int __block_new_threads = 0;
+size_t __default_stacksize = 0;
+size_t __default_guardsize = 0;
 
 static FILE *volatile dummy_file = 0;
 weak_alias(dummy_file, __stdin_used);
@@ -204,6 +206,11 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
 	if (attrp && !c11) attr = *attrp;
 
 	__acquire_ptc();
+	if (!attrp || c11) {
+		attr._a_stacksize = __default_stacksize;
+		attr._a_guardsize = __default_guardsize;
+	}
+
 	if (__block_new_threads) __wait(&__block_new_threads, 0, 1, 1);
 
 	if (attr._a_stackaddr) {
diff --git a/src/thread/pthread_setattr_default_np.c b/src/thread/pthread_setattr_default_np.c
new file mode 100644
index 0000000..21cd0f3
--- /dev/null
+++ b/src/thread/pthread_setattr_default_np.c
@@ -0,0 +1,31 @@
+#include "pthread_impl.h"
+
+extern size_t __default_stacksize;
+extern size_t __default_guardsize;
+
+int pthread_setattr_default_np(const pthread_attr_t *attrp)
+{
+	if (attrp->_a_stackaddr || attrp->_a_detach ||
+	    attrp->_a_sched || attrp->_a_policy || attrp->_a_prio)
+		return EINVAL;
+
+	__inhibit_ptc();
+	if (DEFAULT_STACK_SIZE+attrp->_a_stacksize >= DEFAULT_STACK_SIZE+__default_stacksize)
+		__default_stacksize = attrp->_a_stacksize;
+	if (DEFAULT_GUARD_SIZE+attrp->_a_guardsize >= DEFAULT_GUARD_SIZE+__default_guardsize)
+		__default_guardsize = attrp->_a_guardsize;
+	__release_ptc();
+
+	return 0;
+}
+
+int pthread_getattr_default_np(pthread_attr_t *attrp)
+{
+	__acquire_ptc();
+	*attrp = (pthread_attr_t) {
+		._a_stacksize = __default_stacksize,
+		._a_guardsize = __default_guardsize,
+	};
+	__release_ptc();
+	return 0;
+}
-- 
2.8.3