ThreadPoolInterface.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_POOL_INTERFACE_H
11 #define EIGEN_CXX11_THREADPOOL_THREAD_POOL_INTERFACE_H
12 
13 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 // This defines an interface that ThreadPoolDevice can take to use
18 // custom thread pools underneath.
20  public:
21  // Submits a closure to be run by a thread in the pool.
22  virtual void Schedule(std::function<void()> fn) = 0;
23 
24  // Submits a closure to be run by threads in the range [start, end) in the
25  // pool.
26  virtual void ScheduleWithHint(std::function<void()> fn, int /*start*/,
27  int /*end*/) {
28  // Just defer to Schedule in case sub-classes aren't interested in
29  // overriding this functionality.
30  Schedule(fn);
31  }
32 
33  // If implemented, stop processing the closures that have been enqueued.
34  // Currently running closures may still be processed.
35  // If not implemented, does nothing.
36  virtual void Cancel() {}
37 
38  // Returns the number of threads in the pool.
39  virtual int NumThreads() const = 0;
40 
41  // Returns a logical thread index between 0 and NumThreads() - 1 if called
42  // from one of the threads in the pool. Returns -1 otherwise.
43  virtual int CurrentThreadId() const = 0;
44 
45  virtual ~ThreadPoolInterface() {}
46 };
47 
48 } // namespace Eigen
49 
50 #endif // EIGEN_CXX11_THREADPOOL_THREAD_POOL_INTERFACE_H
virtual void ScheduleWithHint(std::function< void()> fn, int, int)
virtual int CurrentThreadId() const =0
virtual void Schedule(std::function< void()> fn)=0
virtual int NumThreads() const =0
: InteropHeaders
Definition: Core:139