1 //===-- ThreadLauncher.cpp ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "lldb/Core/Log.h"
12 #include "lldb/Host/HostNativeThread.h"
13 #include "lldb/Host/HostThread.h"
14 #include "lldb/Host/ThisThread.h"
15 #include "lldb/Host/ThreadLauncher.h"
18 #include "lldb/Host/windows/windows.h"
22 using namespace lldb_private;
25 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)
31 // Host::ThreadCreateTrampoline will delete this pointer for us.
32 HostThreadCreateInfo *info_ptr = new HostThreadCreateInfo(name.data(), thread_function, thread_arg);
33 lldb::thread_t thread;
36 (lldb::thread_t)::_beginthreadex(0, (unsigned)min_stack_byte_size, HostNativeThread::ThreadCreateTrampoline, info_ptr, 0, NULL);
37 if (thread == (lldb::thread_t)(-1L))
38 error.SetError(::GetLastError(), eErrorTypeWin32);
41 pthread_attr_t *thread_attr_ptr = NULL;
42 pthread_attr_t thread_attr;
43 bool destroy_attr = false;
44 if (min_stack_byte_size > 0)
46 if (::pthread_attr_init (&thread_attr) == 0)
49 size_t default_min_stack_byte_size = 0;
50 if (::pthread_attr_getstacksize(&thread_attr, &default_min_stack_byte_size) == 0)
52 if (default_min_stack_byte_size < min_stack_byte_size)
54 if (::pthread_attr_setstacksize (&thread_attr, min_stack_byte_size) == 0)
55 thread_attr_ptr = &thread_attr;
61 int err = ::pthread_create(&thread, thread_attr_ptr, HostNativeThread::ThreadCreateTrampoline, info_ptr);
64 ::pthread_attr_destroy(&thread_attr);
66 error.SetError(err, eErrorTypePOSIX);
71 thread = LLDB_INVALID_HOST_THREAD;
73 return HostThread(thread);