[Lldb-commits] [lldb] r219821 - Allow ThreadLauncher::LaunchThread() to specify a minimum stack byte size when launching threads.

Greg Clayton gclayton at apple.com
Wed Oct 15 11:03:59 PDT 2014


Author: gclayton
Date: Wed Oct 15 13:03:59 2014
New Revision: 219821

URL: http://llvm.org/viewvc/llvm-project?rev=219821&view=rev
Log:
Allow ThreadLauncher::LaunchThread() to specify a minimum stack byte size when launching threads.

This defaults to zero, which means to use the system default.

NOTE: Windows will need to implement this.

<rdar://problem/18644448>


Modified:
    lldb/trunk/include/lldb/Host/ThreadLauncher.h
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Host/common/ThreadLauncher.cpp

Modified: lldb/trunk/include/lldb/Host/ThreadLauncher.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/ThreadLauncher.h?rev=219821&r1=219820&r2=219821&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/ThreadLauncher.h (original)
+++ lldb/trunk/include/lldb/Host/ThreadLauncher.h Wed Oct 15 13:03:59 2014
@@ -22,8 +22,11 @@ namespace lldb_private
 class ThreadLauncher
 {
   public:
-    static HostThread LaunchThread(llvm::StringRef name, lldb::thread_func_t thread_function, lldb::thread_arg_t thread_arg,
-                                   Error *error_ptr);
+    static HostThread LaunchThread(llvm::StringRef name,
+                                   lldb::thread_func_t thread_function,
+                                   lldb::thread_arg_t thread_arg,
+                                   Error *error_ptr,
+                                   size_t min_stack_byte_size = 0); // Minimum stack size in bytes, set stack size to zero for default platform thread stack size
 
     struct HostThreadCreateInfo
     {

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=219821&r1=219820&r2=219821&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Oct 15 13:03:59 2014
@@ -3484,7 +3484,13 @@ bool
 Debugger::StartEventHandlerThread()
 {
     if (!m_event_handler_thread.IsJoinable())
-        m_event_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.event-handler", EventHandlerThread, this, NULL);
+    {
+        m_event_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.event-handler",
+                                                               EventHandlerThread,
+                                                               this,
+                                                               NULL,
+                                                               8*1024*1024); // Use larger 8MB stack for this thread
+    }
     return m_event_handler_thread.IsJoinable();
 }
 
@@ -3512,7 +3518,11 @@ bool
 Debugger::StartIOHandlerThread()
 {
     if (!m_io_handler_thread.IsJoinable())
-        m_io_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.io-handler", IOHandlerThread, this, NULL);
+        m_io_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.io-handler",
+                                                            IOHandlerThread,
+                                                            this,
+                                                            NULL,
+                                                            8*1024*1024); // Use larger 8MB stack for this thread
     return m_io_handler_thread.IsJoinable();
 }
 

Modified: lldb/trunk/source/Host/common/ThreadLauncher.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/ThreadLauncher.cpp?rev=219821&r1=219820&r2=219821&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/ThreadLauncher.cpp (original)
+++ lldb/trunk/source/Host/common/ThreadLauncher.cpp Wed Oct 15 13:03:59 2014
@@ -22,7 +22,7 @@ using namespace lldb;
 using namespace lldb_private;
 
 HostThread
-ThreadLauncher::LaunchThread(llvm::StringRef name, lldb::thread_func_t thread_function, lldb::thread_arg_t thread_arg, Error *error_ptr)
+ThreadLauncher::LaunchThread(llvm::StringRef name, lldb::thread_func_t thread_function, lldb::thread_arg_t thread_arg, Error *error_ptr, size_t min_stack_byte_size)
 {
     Error error;
     if (error_ptr)
@@ -36,7 +36,32 @@ ThreadLauncher::LaunchThread(llvm::Strin
     if (thread == (lldb::thread_t)(-1L))
         error.SetError(::GetLastError(), eErrorTypeWin32);
 #else
-    int err = ::pthread_create(&thread, NULL, HostNativeThread::ThreadCreateTrampoline, info_ptr);
+
+    pthread_attr_t *thread_attr_ptr = NULL;
+    pthread_attr_t thread_attr;
+    bool destroy_attr = false;
+    if (min_stack_byte_size > 0)
+    {
+        if (::pthread_attr_init (&thread_attr) == 0)
+        {
+            destroy_attr = true;
+            size_t default_min_stack_byte_size = 0;
+            if (::pthread_attr_getstacksize(&thread_attr, &default_min_stack_byte_size) == 0)
+            {
+                if (default_min_stack_byte_size < min_stack_byte_size)
+                {
+                    if (::pthread_attr_setstacksize (&thread_attr, min_stack_byte_size) == 0)
+                        thread_attr_ptr = &thread_attr;
+                }
+            }
+
+        }
+    }
+    int err = ::pthread_create(&thread, thread_attr_ptr, HostNativeThread::ThreadCreateTrampoline, info_ptr);
+
+    if (destroy_attr)
+        ::pthread_attr_destroy(&thread_attr);
+
     error.SetError(err, eErrorTypePOSIX);
 #endif
     if (error_ptr)





More information about the lldb-commits mailing list