blob: e524fd4ace34e87b7f2206a62343d2b38e9e2c95 [file] [log] [blame]
Zachary Turner39de3112014-09-09 20:54:56 +00001//===-- ThisThread.cpp ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Zachary Turner9daf1a62014-09-09 22:11:10 +000010#include "lldb/Host/HostNativeThread.h"
Zachary Turner39de3112014-09-09 20:54:56 +000011#include "lldb/Host/ThisThread.h"
12
13#include "llvm/ADT/SmallVector.h"
14
15#include <pthread.h>
Sylvestre Ledru57958b52015-02-10 17:16:13 +000016#if defined (__FreeBSD__)
Ed Maste39677642014-09-10 13:38:47 +000017#include <pthread_np.h>
Sylvestre Ledru57958b52015-02-10 17:16:13 +000018#endif
Zachary Turner39de3112014-09-09 20:54:56 +000019
20using namespace lldb_private;
21
22void
23ThisThread::SetName(llvm::StringRef name)
24{
Sylvestre Ledru57958b52015-02-10 17:16:13 +000025#if defined (__FreeBSD__) // Kfreebsd does not have a simple alternative
Ed Maste3b7382d2014-09-10 17:09:46 +000026 ::pthread_set_name_np(::pthread_self(), name.data());
Sylvestre Ledru57958b52015-02-10 17:16:13 +000027#endif
Zachary Turner39de3112014-09-09 20:54:56 +000028}
29
30void
31ThisThread::GetName(llvm::SmallVectorImpl<char> &name)
32{
Sylvestre Ledru57958b52015-02-10 17:16:13 +000033#if defined (__FreeBSD__)
Ed Maste39677642014-09-10 13:38:47 +000034 HostNativeThread::GetName(::pthread_getthreadid_np(), name);
Sylvestre Ledru57958b52015-02-10 17:16:13 +000035#else
36// Kfreebsd
37 HostNativeThread::GetName((unsigned)pthread_self(), name);
38#endif
Zachary Turner39de3112014-09-09 20:54:56 +000039}