ThreadEnvironment.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
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 
16 namespace Eigen {
17 
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
Definition: ThreadEnvironment.h:25
std::thread thr_
Definition: ThreadEnvironment.h:33
~EnvThread()
Definition: ThreadEnvironment.h:28
EnvThread(std::function< void()> f)
Definition: ThreadEnvironment.h:27
void OnCancel()
Definition: ThreadEnvironment.h:30
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
t
Definition: plotPSD.py:36
Definition: ThreadEnvironment.h:19
std::function< void()> f
Definition: ThreadEnvironment.h:20
Definition: ThreadEnvironment.h:18
Task CreateTask(std::function< void()> f)
Definition: ThreadEnvironment.h:37
void ExecuteTask(const Task &t)
Definition: ThreadEnvironment.h:38
EnvThread * CreateThread(std::function< void()> f)
Definition: ThreadEnvironment.h:36