Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
ThreadEnvironment.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2014 Benoit Steiner <[email protected]>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_CXX11_THREADPOOL_THREAD_ENVIRONMENT_H
11#define EIGEN_CXX11_THREADPOOL_THREAD_ENVIRONMENT_H
12
13// IWYU pragma: private
14#include "./InternalHeaderCheck.h"
15
16namespace Eigen {
17
18struct StlThreadEnvironment {
19 struct Task {
20 std::function<void()> f;
21 };
22
23 // EnvThread constructor must start the thread,
24 // destructor must join the thread.
25 class EnvThread {
26 public:
27 EnvThread(std::function<void()> f) : thr_(std::move(f)) {}
28 ~EnvThread() { thr_.join(); }
29 // This function is called when the threadpool is cancelled.
30 void OnCancel() {}
31
32 private:
33 std::thread thr_;
34 };
35
36 EnvThread* CreateThread(std::function<void()> f) { return new EnvThread(std::move(f)); }
37 Task CreateTask(std::function<void()> f) { return Task{std::move(f)}; }
38 void ExecuteTask(const Task& t) { t.f(); }
39};
40
41} // namespace Eigen
42
43#endif // EIGEN_CXX11_THREADPOOL_THREAD_ENVIRONMENT_H
Namespace containing all symbols from the Eigen library.
Definition Core:137