blob: 084ed16166feccae798036d9992d365ba6ea0984 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- llvm/Support/thread.h - Wrapper for <thread> ------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8//
9// This header is a wrapper for <thread> that works around problems with the
10// MSVC headers when exceptions are disabled. It also provides llvm::thread,
11// which is either a typedef of std::thread or a replacement that calls the
12// function synchronously depending on the value of LLVM_ENABLE_THREADS.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_SUPPORT_THREAD_H
17#define LLVM_SUPPORT_THREAD_H
18
19#include "llvm/Config/llvm-config.h"
20
21#if LLVM_ENABLE_THREADS
22
23#include <thread>
24
25namespace llvm {
26typedef std::thread thread;
27}
28
29#else // !LLVM_ENABLE_THREADS
30
31#include <utility>
32
33namespace llvm {
34
35struct thread {
36 thread() {}
37 thread(thread &&other) {}
38 template <class Function, class... Args>
39 explicit thread(Function &&f, Args &&... args) {
40 f(std::forward<Args>(args)...);
41 }
42 thread(const thread &) = delete;
43
44 void join() {}
45 static unsigned hardware_concurrency() { return 1; };
46};
47
48}
49
50#endif // LLVM_ENABLE_THREADS
51
52#endif