2016-04-14 15:23:10 -07:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
|
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
|
|
#ifndef EIGEN_CXX11_THREADPOOL_THREAD_POOL_INTERFACE_H
|
|
|
|
|
#define EIGEN_CXX11_THREADPOOL_THREAD_POOL_INTERFACE_H
|
|
|
|
|
|
2023-08-21 16:25:22 +00:00
|
|
|
// IWYU pragma: private
|
2021-09-10 19:12:26 +00:00
|
|
|
#include "./InternalHeaderCheck.h"
|
|
|
|
|
|
2016-04-14 15:23:10 -07:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
|
|
|
|
// This defines an interface that ThreadPoolDevice can take to use
|
|
|
|
|
// custom thread pools underneath.
|
|
|
|
|
class ThreadPoolInterface {
|
|
|
|
|
public:
|
2016-12-08 14:03:25 -08:00
|
|
|
// Submits a closure to be run by a thread in the pool.
|
2016-04-14 15:23:10 -07:00
|
|
|
virtual void Schedule(std::function<void()> fn) = 0;
|
|
|
|
|
|
2018-09-17 18:29:12 -07:00
|
|
|
// Submits a closure to be run by threads in the range [start, end) in the
|
|
|
|
|
// pool.
|
2018-09-19 11:11:04 -07:00
|
|
|
virtual void ScheduleWithHint(std::function<void()> fn, int /*start*/, int /*end*/) {
|
2018-09-17 18:29:12 -07:00
|
|
|
// Just defer to Schedule in case sub-classes aren't interested in
|
|
|
|
|
// overriding this functionality.
|
|
|
|
|
Schedule(fn);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-12 11:58:38 -08:00
|
|
|
// If implemented, stop processing the closures that have been enqueued.
|
2016-12-09 13:05:14 -08:00
|
|
|
// Currently running closures may still be processed.
|
2016-12-12 11:58:38 -08:00
|
|
|
// If not implemented, does nothing.
|
|
|
|
|
virtual void Cancel() {}
|
2016-12-08 14:03:25 -08:00
|
|
|
|
2016-06-03 16:28:58 -07:00
|
|
|
// Returns the number of threads in the pool.
|
2016-06-03 18:06:37 -07:00
|
|
|
virtual int NumThreads() const = 0;
|
2016-06-03 16:28:58 -07:00
|
|
|
|
|
|
|
|
// Returns a logical thread index between 0 and NumThreads() - 1 if called
|
2016-06-23 16:40:07 -07:00
|
|
|
// from one of the threads in the pool. Returns -1 otherwise.
|
2016-06-03 18:06:37 -07:00
|
|
|
virtual int CurrentThreadId() const = 0;
|
2016-06-03 16:28:58 -07:00
|
|
|
|
2016-04-14 15:23:10 -07:00
|
|
|
virtual ~ThreadPoolInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Eigen
|
|
|
|
|
|
|
|
|
|
#endif // EIGEN_CXX11_THREADPOOL_THREAD_POOL_INTERFACE_H
|