Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:14:27

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_CXX11_THREADPOOL_THREAD_ENVIRONMENT_H
0011 #define EIGEN_CXX11_THREADPOOL_THREAD_ENVIRONMENT_H
0012 
0013 namespace Eigen {
0014 
0015 struct StlThreadEnvironment {
0016   struct Task {
0017     std::function<void()> f;
0018   };
0019 
0020   // EnvThread constructor must start the thread,
0021   // destructor must join the thread.
0022   class EnvThread {
0023    public:
0024     EnvThread(std::function<void()> f) : thr_(std::move(f)) {}
0025     ~EnvThread() { thr_.join(); }
0026     // This function is called when the threadpool is cancelled.
0027     void OnCancel() { }
0028 
0029    private:
0030     std::thread thr_;
0031   };
0032 
0033   EnvThread* CreateThread(std::function<void()> f) { return new EnvThread(std::move(f)); }
0034   Task CreateTask(std::function<void()> f) { return Task{std::move(f)}; }
0035   void ExecuteTask(const Task& t) { t.f(); }
0036 };
0037 
0038 }  // namespace Eigen
0039 
0040 #endif  // EIGEN_CXX11_THREADPOOL_THREAD_ENVIRONMENT_H