2010-11-30 03:44:50 +08:00
|
|
|
//===-- llvm/Support/Threading.cpp- Control multithreading mode --*- C++ -*-==//
|
2009-06-17 01:33:51 +08: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 23:13:01 +08:00
|
|
|
// This file defines helper functions for running LLVM in a multi-threaded
|
|
|
|
// environment.
|
2009-06-17 01:33:51 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/Threading.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Config/config.h"
|
2016-10-14 08:13:59 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
2016-06-03 02:22:12 +08:00
|
|
|
#include "llvm/Support/thread.h"
|
2017-03-04 01:15:17 +08:00
|
|
|
|
2009-06-17 01:33:51 +08:00
|
|
|
#include <cassert>
|
2017-03-04 01:15:17 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-07-07 05:24:37 +08:00
|
|
|
|
2009-06-17 01:33:51 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2017-03-04 01:15:17 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//=== WARNING: Implementation here must contain only TRULY operating system
|
|
|
|
//=== independent code.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-06-27 23:13:01 +08:00
|
|
|
bool llvm::llvm_is_multithreaded() {
|
2011-11-28 08:48:58 +08:00
|
|
|
#if LLVM_ENABLE_THREADS != 0
|
2009-06-17 01:33:51 +08:00
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-04 01:15:17 +08: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 09:26:25 +08:00
|
|
|
unsigned RequestedStackSize) {
|
2017-03-04 01:15:17 +08:00
|
|
|
(void)RequestedStackSize;
|
|
|
|
Fn(UserData);
|
2010-11-04 09:26:25 +08:00
|
|
|
}
|
2016-06-03 02:42:23 +08:00
|
|
|
|
2017-03-04 01:15:17 +08:00
|
|
|
unsigned llvm::heavyweight_hardware_concurrency() { return 1; }
|
2010-11-04 09:26:25 +08:00
|
|
|
|
2017-03-04 01:15:17 +08:00
|
|
|
uint64_t llvm::get_threadid_np() { return 0; }
|
2011-09-19 15:41:43 +08:00
|
|
|
|
2017-03-04 01:15:17 +08:00
|
|
|
void llvm::set_thread_name(const Twine &Name) {}
|
2011-09-19 15:41:43 +08:00
|
|
|
|
2017-03-04 01:15:17 +08:00
|
|
|
void llvm::get_thread_name(SmallVectorImpl<char> &Name) { Name.clear(); }
|
2011-09-19 15:41:43 +08:00
|
|
|
|
|
|
|
#else
|
2016-10-14 08:13:59 +08:00
|
|
|
|
2016-10-17 22:56:53 +08:00
|
|
|
unsigned llvm::heavyweight_hardware_concurrency() {
|
2016-10-14 08:13:59 +08:00
|
|
|
int NumPhysical = sys::getHostNumPhysicalCores();
|
|
|
|
if (NumPhysical == -1)
|
|
|
|
return thread::hardware_concurrency();
|
|
|
|
return NumPhysical;
|
|
|
|
}
|
2017-03-04 01:15:17 +08: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
|