TR-mbed 1.0
Loading...
Searching...
No Matches
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
13namespace Eigen {
14
16 struct Task {
17 std::function<void()> f;
18 };
19
20 // EnvThread constructor must start the thread,
21 // destructor must join the thread.
22 class EnvThread {
23 public:
24 EnvThread(std::function<void()> f) : thr_(std::move(f)) {}
25 ~EnvThread() { thr_.join(); }
26 // This function is called when the threadpool is cancelled.
27 void OnCancel() { }
28
29 private:
30 std::thread thr_;
31 };
32
33 EnvThread* CreateThread(std::function<void()> f) { return new EnvThread(std::move(f)); }
34 Task CreateTask(std::function<void()> f) { return Task{std::move(f)}; }
35 void ExecuteTask(const Task& t) { t.f(); }
36};
37
38} // namespace Eigen
39
40#endif // EIGEN_CXX11_THREADPOOL_THREAD_ENVIRONMENT_H
Definition ThreadEnvironment.h:22
~EnvThread()
Definition ThreadEnvironment.h:25
EnvThread(std::function< void()> f)
Definition ThreadEnvironment.h:24
void OnCancel()
Definition ThreadEnvironment.h:27
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
Definition BFloat16.h:88
Definition ThreadEnvironment.h:16
std::function< void()> f
Definition ThreadEnvironment.h:17
Definition ThreadEnvironment.h:15
Task CreateTask(std::function< void()> f)
Definition ThreadEnvironment.h:34
void ExecuteTask(const Task &t)
Definition ThreadEnvironment.h:35
EnvThread * CreateThread(std::function< void()> f)
Definition ThreadEnvironment.h:33