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>

llvm-svn: 219821
This commit is contained in:
Greg Clayton 2014-10-15 18:03:59 +00:00
parent ab61e702bd
commit 807b6b326d
3 changed files with 44 additions and 6 deletions

View File

@ -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
{

View File

@ -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();
}

View File

@ -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::StringRef name, lldb::thread_func_t thread_fu
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)