2014-09-10 04:54:56 +08:00
|
|
|
//===-- HostNativeThreadBase.cpp --------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Host/HostNativeThreadBase.h"
|
2014-09-10 04:54:56 +08:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
|
|
|
#include "lldb/Host/ThreadLauncher.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-03-04 09:31:06 +08:00
|
|
|
|
2014-09-10 04:54:56 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2017-03-04 09:31:06 +08:00
|
|
|
#include "llvm/Support/Threading.h"
|
2014-09-10 04:54:56 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
HostNativeThreadBase::HostNativeThreadBase()
|
2016-09-07 04:57:50 +08:00
|
|
|
: m_thread(LLDB_INVALID_HOST_THREAD), m_result(0) {}
|
2014-09-10 04:54:56 +08:00
|
|
|
|
|
|
|
HostNativeThreadBase::HostNativeThreadBase(thread_t thread)
|
2016-09-07 04:57:50 +08:00
|
|
|
: m_thread(thread), m_result(0) {}
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::thread_t HostNativeThreadBase::GetSystemHandle() const {
|
|
|
|
return m_thread;
|
2014-09-10 04:54:56 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::thread_result_t HostNativeThreadBase::GetResult() const {
|
|
|
|
return m_result;
|
2014-09-10 04:54:56 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool HostNativeThreadBase::IsJoinable() const {
|
|
|
|
return m_thread != LLDB_INVALID_HOST_THREAD;
|
2014-09-24 02:32:09 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void HostNativeThreadBase::Reset() {
|
|
|
|
m_thread = LLDB_INVALID_HOST_THREAD;
|
|
|
|
m_result = 0;
|
2014-09-10 04:54:56 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::thread_t HostNativeThreadBase::Release() {
|
|
|
|
lldb::thread_t result = m_thread;
|
|
|
|
m_thread = LLDB_INVALID_HOST_THREAD;
|
|
|
|
m_result = 0;
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return result;
|
2014-09-10 04:54:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::thread_result_t
|
2016-09-07 04:57:50 +08:00
|
|
|
HostNativeThreadBase::ThreadCreateTrampoline(lldb::thread_arg_t arg) {
|
|
|
|
ThreadLauncher::HostThreadCreateInfo *info =
|
|
|
|
(ThreadLauncher::HostThreadCreateInfo *)arg;
|
2017-03-04 09:31:06 +08:00
|
|
|
llvm::set_thread_name(info->thread_name);
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
thread_func_t thread_fptr = info->thread_fptr;
|
|
|
|
thread_arg_t thread_arg = info->thread_arg;
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
|
|
|
|
if (log)
|
|
|
|
log->Printf("thread created");
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
delete info;
|
|
|
|
return thread_fptr(thread_arg);
|
2014-09-10 04:54:56 +08:00
|
|
|
}
|