2010-11-29 19:44:50 +00:00
|
|
|
//===-- llvm/Support/Threading.cpp- Control multithreading mode --*- C++ -*-==//
|
2009-06-16 17:33:51 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2014-06-27 15:13:01 +00:00
|
|
|
// This file defines helper functions for running LLVM in a multi-threaded
|
|
|
|
// environment.
|
2009-06-16 17:33:51 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/Threading.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Config/config.h"
|
2016-10-14 00:13:59 +00:00
|
|
|
#include "llvm/Support/Host.h"
|
2017-03-03 17:15:17 +00:00
|
|
|
|
2009-06-16 17:33:51 +00:00
|
|
|
#include <cassert>
|
2017-03-03 17:15:17 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-07-06 21:24:37 +00:00
|
|
|
|
2009-06-16 17:33:51 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2017-03-03 17:15:17 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//=== WARNING: Implementation here must contain only TRULY operating system
|
|
|
|
//=== independent code.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-06-27 15:13:01 +00:00
|
|
|
bool llvm::llvm_is_multithreaded() {
|
2011-11-28 00:48:58 +00:00
|
|
|
#if LLVM_ENABLE_THREADS != 0
|
2009-06-16 17:33:51 +00:00
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-03 17:15:17 +00:00
|
|
|
#if LLVM_ENABLE_THREADS == 0 || \
|
|
|
|
(!defined(LLVM_ON_WIN32) && !defined(HAVE_PTHREAD_H))
|
|
|
|
// Support for non-Win32, non-pthread implementation.
|
|
|
|
void llvm::llvm_execute_on_thread(void (*Fn)(void *), void *UserData,
|
2010-11-04 01:26:25 +00:00
|
|
|
unsigned RequestedStackSize) {
|
2017-03-03 17:15:17 +00:00
|
|
|
(void)RequestedStackSize;
|
|
|
|
Fn(UserData);
|
2010-11-04 01:26:25 +00:00
|
|
|
}
|
2016-06-02 18:42:23 +00:00
|
|
|
|
2017-03-03 17:15:17 +00:00
|
|
|
unsigned llvm::heavyweight_hardware_concurrency() { return 1; }
|
2010-11-04 01:26:25 +00:00
|
|
|
|
2017-03-03 21:49:38 +00:00
|
|
|
uint64_t llvm::get_threadid() { return 0; }
|
2011-09-19 07:41:43 +00:00
|
|
|
|
2017-03-04 18:53:09 +00:00
|
|
|
uint32_t llvm::get_max_thread_name_length() { return 0; }
|
|
|
|
|
2017-03-03 17:15:17 +00:00
|
|
|
void llvm::set_thread_name(const Twine &Name) {}
|
2011-09-19 07:41:43 +00:00
|
|
|
|
2017-03-03 17:15:17 +00:00
|
|
|
void llvm::get_thread_name(SmallVectorImpl<char> &Name) { Name.clear(); }
|
2011-09-19 07:41:43 +00:00
|
|
|
|
|
|
|
#else
|
2016-10-14 00:13:59 +00:00
|
|
|
|
2017-03-03 17:39:24 +00:00
|
|
|
#include <thread>
|
2016-10-17 14:56:53 +00:00
|
|
|
unsigned llvm::heavyweight_hardware_concurrency() {
|
2017-03-03 17:39:24 +00:00
|
|
|
// Since we can't get here unless LLVM_ENABLE_THREADS == 1, it is safe to use
|
|
|
|
// `std::thread` directly instead of `llvm::thread` (and indeed, doing so
|
|
|
|
// allows us to not define `thread` in the llvm namespace, which conflicts
|
|
|
|
// with some platforms such as FreeBSD whose headers also define a struct
|
|
|
|
// called `thread` in the global namespace which can cause ambiguity due to
|
|
|
|
// ADL.
|
2016-10-14 00:13:59 +00:00
|
|
|
int NumPhysical = sys::getHostNumPhysicalCores();
|
|
|
|
if (NumPhysical == -1)
|
2017-03-03 17:39:24 +00:00
|
|
|
return std::thread::hardware_concurrency();
|
2016-10-14 00:13:59 +00:00
|
|
|
return NumPhysical;
|
|
|
|
}
|
2017-03-03 17:15:17 +00:00
|
|
|
|
|
|
|
// Include the platform-specific parts of this class.
|
|
|
|
#ifdef LLVM_ON_UNIX
|
|
|
|
#include "Unix/Threading.inc"
|
|
|
|
#endif
|
|
|
|
#ifdef LLVM_ON_WIN32
|
|
|
|
#include "Windows/Threading.inc"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|