blob: af6d5a93e5040b20215b79d77151e7a2c4c5e07a [file] [log] [blame]
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2016 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_THREADPOOL_MODULE_H
#define EIGEN_THREADPOOL_MODULE_H
#include "Core"
#include "src/Core/util/DisableStupidWarnings.h"
/** \defgroup ThreadPool_Module ThreadPool Module
*
* This module provides 2 threadpool implementations
* - a simple reference implementation
* - a faster non blocking implementation
*
* \code
* #include <Eigen/ThreadPool>
* \endcode
*/
#include <cstddef>
#include <cstring>
#include <time.h>
#include <vector>
#include <atomic>
#include <condition_variable>
#include <deque>
#include <mutex>
#include <thread>
#include <functional>
#include <memory>
#include <utility>
// There are non-parenthesized calls to "max" in the <unordered_map> header,
// which trigger a check in test/main.h causing compilation to fail.
// We work around the check here by removing the check for max in
// the case where we have to emulate thread_local.
#ifdef max
#undef max
#endif
#include <unordered_map>
#include "src/Core/util/Meta.h"
#include "src/Core/util/MaxSizeVector.h"
// Use ABSL synchronization primitives, unless it's explicitly disabled with
// EIGEN_USE_STD_SYNCHRONIZATION for platforms that can't compile ABSL headers
#if !defined(EIGEN_USE_STD_SYNCHRONIZATION)
#include "third_party/absl/base/thread_annotations.h"
#include "third_party/absl/synchronization/mutex.h"
#else
#define EIGEN_MUTEX std::mutex
#define EIGEN_MUTEX_LOCK std::unique_lock<std::mutex>
#define EIGEN_CONDVAR std::condition_variable
#endif
#ifndef EIGEN_MUTEX
namespace Eigen {
struct ABSL_LOCKABLE Mutex {
absl::Mutex mu;
};
} // namespace Eigen
#define EIGEN_MUTEX ::Eigen::Mutex
#endif
#ifndef EIGEN_MUTEX_LOCK
namespace Eigen {
struct ABSL_SCOPED_LOCKABLE MutexLock {
explicit MutexLock(Mutex& mutex) ABSL_EXCLUSIVE_LOCK_FUNCTION(mutex)
: mu(&mutex.mu), lock(mu) {}
~MutexLock() ABSL_UNLOCK_FUNCTION() = default;
absl::Mutex* mu;
absl::MutexLock lock;
};
} // namespace Eigen
#define EIGEN_MUTEX_LOCK ::Eigen::MutexLock
#endif
#ifndef EIGEN_CONDVAR
namespace Eigen {
struct CondVar {
void wait(MutexLock& lock) { cv.Wait(lock.mu); }
void notify_one() { cv.Signal(); }
void notify_all() { cv.SignalAll(); }
absl::CondVar cv;
};
} // namespace Eigen
#define EIGEN_CONDVAR ::Eigen::CondVar
#endif
// IWYU pragma: begin_exports
#include "src/ThreadPool/ThreadLocal.h"
#include "src/ThreadPool/ThreadYield.h"
#include "src/ThreadPool/ThreadCancel.h"
#include "src/ThreadPool/EventCount.h"
#include "src/ThreadPool/RunQueue.h"
#include "src/ThreadPool/ThreadPoolInterface.h"
#include "src/ThreadPool/ThreadEnvironment.h"
#include "src/ThreadPool/Barrier.h"
#include "src/ThreadPool/NonBlockingThreadPool.h"
#include "src/ThreadPool/CoreThreadPoolDevice.h"
// IWYU pragma: end_exports
#include "src/Core/util/ReenableStupidWarnings.h"
#endif // EIGEN_CXX11_THREADPOOL_MODULE_H