This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] Unify max stacksize handling between __pthread_attr_setstacksize and __pthread_initialize_manager


Hi!

If pthread_attr_setstacksize is called before manager thread is kicked in,
pthread_attr_setstacksize will usually have different upper limit than when
it is called after starting up manager, which seem pretty inconsistent to
me.

2001-02-23  Jakub Jelinek  <jakub@redhat.com>

	* internals.h (__pthread_init_max_stacksize): New prototype.
	* attr.c (__pthread_attr_setstacksize): Call
	__pthread_init_max_stacksize if not yet initialized.
	* pthread.c (__pthread_init_max_stacksize): New function.
	(__pthread_initialize_manager): Call it.
	Patch by <dtc@cmucl.cons.org>.

--- libc/linuxthreads/internals.h.jj	Wed Feb  7 13:57:05 2001
+++ libc/linuxthreads/internals.h	Fri Feb 23 17:05:10 2001
@@ -429,6 +429,7 @@ static inline pthread_descr thread_self 
 
 extern void __pthread_destroy_specifics (void);
 extern void __pthread_perform_cleanup (void);
+extern void __pthread_init_max_stacksize (void);
 extern int __pthread_initialize_manager (void);
 extern void __pthread_message (char * fmt, ...);
 extern int __pthread_manager (void *reqfd);
--- libc/linuxthreads/attr.c.jj	Tue Jan  2 14:17:38 2001
+++ libc/linuxthreads/attr.c	Fri Feb 23 17:31:29 2001
@@ -193,16 +193,7 @@ int __pthread_attr_setstacksize(pthread_
      problem if the manager is already started and we determined it.  If
      this hasn't happened, we have to find the limit outself.  */
   if (__pthread_max_stacksize == 0)
-    {
-      struct rlimit limit;
-
-      getrlimit(RLIMIT_STACK, &limit);
-# ifdef NEED_SEPARATE_REGISTER_STACK
-      __pthread_max_stacksize = limit.rlim_max / 2;
-# else
-      __pthread_max_stacksize = limit.rlim_max;
-# endif
-    }
+    __pthread_init_max_stacksize ();
 
   if (stacksize > __pthread_max_stacksize)
     return EINVAL;
--- libc/linuxthreads/pthread.c.jj	Sat Feb  3 12:03:21 2001
+++ libc/linuxthreads/pthread.c	Fri Feb 23 17:49:51 2001
@@ -456,19 +456,10 @@ void __pthread_initialize(void)
   pthread_initialize();
 }
 
-int __pthread_initialize_manager(void)
+void __pthread_init_max_stacksize(void)
 {
-  int manager_pipe[2];
-  int pid;
-  struct pthread_request request;
   struct rlimit limit;
-  int max_stack;
-
-#ifndef HAVE_Z_NODELETE
-  if (__builtin_expect (&__dso_handle != NULL, 1))
-    __cxa_atexit ((void (*) (void *)) pthread_atexit_retcode, NULL,
-		  __dso_handle);
-#endif
+  size_t max_stack;
 
   getrlimit(RLIMIT_STACK, &limit);
 #ifdef FLOATING_STACKS
@@ -478,9 +469,7 @@ int __pthread_initialize_manager(void)
   max_stack = limit.rlim_cur / 2;
 # else
   max_stack = limit.rlim_cur;
-#endif
-
-  __pthread_max_stacksize = max_stack;
+# endif
 #else
   /* Play with the stack size limit to make sure that no stack ever grows
      beyond STACK_SIZE minus one page (to act as a guard page). */
@@ -496,6 +485,23 @@ int __pthread_initialize_manager(void)
     setrlimit(RLIMIT_STACK, &limit);
   }
 #endif
+  __pthread_max_stacksize = max_stack;
+}
+
+int __pthread_initialize_manager(void)
+{
+  int manager_pipe[2];
+  int pid;
+  struct pthread_request request;
+
+#ifndef HAVE_Z_NODELETE
+  if (__builtin_expect (&__dso_handle != NULL, 1))
+    __cxa_atexit ((void (*) (void *)) pthread_atexit_retcode, NULL,
+		  __dso_handle);
+#endif
+
+  if (__pthread_max_stacksize == 0)
+    __pthread_init_max_stacksize ();
   /* If basic initialization not done yet (e.g. we're called from a
      constructor run before our constructor), do it now */
   if (__pthread_initial_thread_bos == NULL) pthread_initialize();

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]