This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Use default_attr to store default pthread attributes
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Thu, 14 Mar 2013 17:19:31 +0530
- Subject: [PATCH] Use default_attr to store default pthread attributes
Hi,
This is a preparatory patch for the upcoming patch to add a new API
function to set default pthread attributes for a process[1][2]. These
attributes would be used to create all threads in that process that do
not provide their own pthread_attr_t. This patch moves the
__default_stacksize into default_attr, which is now shared within
libpthread.so and is not just static to pthread_create.c. Verified on
x86_64 to verify that there were no regressions due to this change.
OK to commit?
Siddhesh
[1] http://sourceware.org/ml/libc-alpha/2013-03/msg00300.html
[2] Code is on siddhesh/pthread_attr_default
nptl/ChangeLog:
* allocatestack.c (allocate_stack): Use DEFAULT_ATTR.
* nptl-init.c (__pthread_initialize_minimal_internal):
Likewise.
* pthreadP.h (default_attr): Declare.
* pthread_attr_getstacksize.c (__pthread_attr_getstacksize):
Use DEFAULT_ATTR.
* pthread_barrier_init.c (default_attr); Rename to
default_barrierattr.
(pthread_barrier_init): Adjust for the rename.
* pthread_create.c (default_attr): Move definition...
* vars.c: ... here.
(default_attr): Initialize member STACKSIZE.
* pthread_mutex_init.c (default_attr): Rename to
default_mutexattr.
(__pthread_mutex_init): Adjust for the rename.
* pthread_rwlock_init.c )default_attr_: Rename to
default_rwlockattr.
(__pthread_rwlock_init): Adjust for the rename.
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 31c8829..d617262 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -358,7 +358,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
/* Get the stack size from the attribute if it is set. Otherwise we
use the default we determined at start time. */
- size = attr->stacksize ?: __default_stacksize;
+ size = attr->stacksize ?: default_attr.stacksize;
/* Get memory for the stack. */
if (__builtin_expect (attr->flags & ATTR_FLAG_STACKADDR, 0))
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 19e6616..23d3430 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -423,7 +423,7 @@ __pthread_initialize_minimal_internal (void)
/* Round the resource limit up to page size. */
limit.rlim_cur = (limit.rlim_cur + pagesz - 1) & -pagesz;
- __default_stacksize = limit.rlim_cur;
+ default_attr.stacksize = limit.rlim_cur;
#ifdef SHARED
/* Transfer the old value from the dynamic linker's internal location. */
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index d08b219..73dfba6 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -147,8 +147,9 @@ enum
/* Internal variables. */
-/* Default stack size. */
-extern size_t __default_stacksize attribute_hidden;
+/* Default pthread attributes. */
+extern struct pthread_attr default_attr;
+hidden_proto (default_attr);
/* Size and alignment of static TLS block. */
extern size_t __static_tls_size attribute_hidden;
diff --git a/nptl/pthread_attr_getstacksize.c b/nptl/pthread_attr_getstacksize.c
index 6df7062..915cbb7 100644
--- a/nptl/pthread_attr_getstacksize.c
+++ b/nptl/pthread_attr_getstacksize.c
@@ -32,7 +32,7 @@ __pthread_attr_getstacksize (attr, stacksize)
/* If the user has not set a stack size we return what the system
will use as the default. */
- *stacksize = iattr->stacksize ?: __default_stacksize;
+ *stacksize = iattr->stacksize ?: default_attr.stacksize;
return 0;
}
diff --git a/nptl/pthread_barrier_init.c b/nptl/pthread_barrier_init.c
index d5891fd..6d2910e 100644
--- a/nptl/pthread_barrier_init.c
+++ b/nptl/pthread_barrier_init.c
@@ -22,7 +22,7 @@
#include <kernel-features.h>
-static const struct pthread_barrierattr default_attr =
+static const struct pthread_barrierattr default_barrierattr =
{
.pshared = PTHREAD_PROCESS_PRIVATE
};
@@ -42,7 +42,7 @@ pthread_barrier_init (barrier, attr, count)
const struct pthread_barrierattr *iattr
= (attr != NULL
? iattr = (struct pthread_barrierattr *) attr
- : &default_attr);
+ : &default_barrierattr);
if (iattr->pshared != PTHREAD_PROCESS_PRIVATE
&& __builtin_expect (iattr->pshared != PTHREAD_PROCESS_SHARED, 0))
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index c6f2fdd..f81dcce 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -435,15 +435,6 @@ start_thread (void *arg)
}
-/* Default thread attributes for the case when the user does not
- provide any. */
-static const struct pthread_attr default_attr =
- {
- /* Just some value > 0 which gets rounded to the nearest page size. */
- .guardsize = 1,
- };
-
-
int
__pthread_create_2_1 (newthread, attr, start_routine, arg)
pthread_t *newthread;
diff --git a/nptl/pthread_mutex_init.c b/nptl/pthread_mutex_init.c
index 36da3f8..174d900 100644
--- a/nptl/pthread_mutex_init.c
+++ b/nptl/pthread_mutex_init.c
@@ -24,7 +24,7 @@
#include <stap-probe.h>
-static const struct pthread_mutexattr default_attr =
+static const struct pthread_mutexattr default_mutexattr =
{
/* Default is a normal mutex, not shared between processes. */
.mutexkind = PTHREAD_MUTEX_NORMAL
@@ -45,7 +45,8 @@ __pthread_mutex_init (mutex, mutexattr)
assert (sizeof (pthread_mutex_t) <= __SIZEOF_PTHREAD_MUTEX_T);
- imutexattr = (const struct pthread_mutexattr *) mutexattr ?: &default_attr;
+ imutexattr = ((const struct pthread_mutexattr *) mutexattr
+ ?: &default_mutexattr);
/* Sanity checks. */
switch (__builtin_expect (imutexattr->mutexkind
diff --git a/nptl/pthread_rwlock_init.c b/nptl/pthread_rwlock_init.c
index 16bfe2d..29bef71 100644
--- a/nptl/pthread_rwlock_init.c
+++ b/nptl/pthread_rwlock_init.c
@@ -21,7 +21,7 @@
#include <kernel-features.h>
-static const struct pthread_rwlockattr default_attr =
+static const struct pthread_rwlockattr default_rwlockattr =
{
.lockkind = PTHREAD_RWLOCK_DEFAULT_NP,
.pshared = PTHREAD_PROCESS_PRIVATE
@@ -35,7 +35,7 @@ __pthread_rwlock_init (rwlock, attr)
{
const struct pthread_rwlockattr *iattr;
- iattr = ((const struct pthread_rwlockattr *) attr) ?: &default_attr;
+ iattr = ((const struct pthread_rwlockattr *) attr) ?: &default_rwlockattr;
memset (rwlock, '\0', sizeof (*rwlock));
diff --git a/nptl/vars.c b/nptl/vars.c
index 2bcd1f8..727c570 100644
--- a/nptl/vars.c
+++ b/nptl/vars.c
@@ -20,13 +20,17 @@
#include <tls.h>
#include <unistd.h>
-/* Default stack size. */
-size_t __default_stacksize attribute_hidden
-#ifdef SHARED
-;
-#else
- = PTHREAD_STACK_MIN;
+/* Default thread attributes for the case when the user does not
+ provide any. */
+struct pthread_attr default_attr =
+ {
+ /* Just some value > 0 which gets rounded to the nearest page size. */
+ .guardsize = 1,
+#ifndef SHARED
+ .stacksize = PTHREAD_STACK_MIN,
#endif
+ };
+hidden_data_def (default_attr)
/* Flag whether the machine is SMP or not. */
int __is_smp attribute_hidden;