mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-11 19:29:02 +08:00
Use plain_assert in destructors to avoid throwing in CXX11 tests where main.h owerwrites eigen_assert with a throwing version.
This commit is contained in:
parent
6d6e7b7027
commit
15d4f515e2
@ -20,9 +20,7 @@ class Barrier {
|
|||||||
Barrier(unsigned int count) : state_(count << 1), notified_(false) {
|
Barrier(unsigned int count) : state_(count << 1), notified_(false) {
|
||||||
eigen_assert(((count << 1) >> 1) == count);
|
eigen_assert(((count << 1) >> 1) == count);
|
||||||
}
|
}
|
||||||
~Barrier() {
|
~Barrier() { eigen_plain_assert((state_ >> 1) == 0); }
|
||||||
eigen_assert((state_>>1) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Notify() {
|
void Notify() {
|
||||||
unsigned int v = state_.fetch_sub(2, std::memory_order_acq_rel) - 2;
|
unsigned int v = state_.fetch_sub(2, std::memory_order_acq_rel) - 2;
|
||||||
@ -52,14 +50,13 @@ class Barrier {
|
|||||||
bool notified_;
|
bool notified_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Notification is an object that allows a user to to wait for another
|
// Notification is an object that allows a user to to wait for another
|
||||||
// thread to signal a notification that an event has occurred.
|
// thread to signal a notification that an event has occurred.
|
||||||
//
|
//
|
||||||
// Multiple threads can wait on the same Notification object,
|
// Multiple threads can wait on the same Notification object,
|
||||||
// but only one caller must call Notify() on the object.
|
// but only one caller must call Notify() on the object.
|
||||||
struct Notification : Barrier {
|
struct Notification : Barrier {
|
||||||
Notification() : Barrier(1) {};
|
Notification() : Barrier(1){};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Eigen
|
} // namespace Eigen
|
||||||
|
@ -58,7 +58,7 @@ class EventCount {
|
|||||||
|
|
||||||
~EventCount() {
|
~EventCount() {
|
||||||
// Ensure there are no waiters.
|
// Ensure there are no waiters.
|
||||||
eigen_assert((state_.load() & (kStackMask | kWaiterMask)) == kStackMask);
|
eigen_plain_assert((state_.load() & (kStackMask | kWaiterMask)) == kStackMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prewait prepares for waiting.
|
// Prewait prepares for waiting.
|
||||||
@ -169,7 +169,8 @@ class EventCount {
|
|||||||
|
|
||||||
class Waiter {
|
class Waiter {
|
||||||
friend class EventCount;
|
friend class EventCount;
|
||||||
// Align to 128 byte boundary to prevent false sharing with other Waiter objects in the same vector.
|
// Align to 128 byte boundary to prevent false sharing with other Waiter
|
||||||
|
// objects in the same vector.
|
||||||
EIGEN_ALIGN_TO_BOUNDARY(128) std::atomic<Waiter*> next;
|
EIGEN_ALIGN_TO_BOUNDARY(128) std::atomic<Waiter*> next;
|
||||||
std::mutex mu;
|
std::mutex mu;
|
||||||
std::condition_variable cv;
|
std::condition_variable cv;
|
||||||
|
@ -90,8 +90,8 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Join threads explicitly to avoid destruction order issues.
|
// Join threads explicitly to avoid destruction order issues.
|
||||||
for (size_t i = 0; i < num_threads_; i++) delete threads_[i];
|
for (int i = 0; i < num_threads_; i++) delete threads_[i];
|
||||||
for (size_t i = 0; i < num_threads_; i++) delete queues_[i];
|
for (int i = 0; i < num_threads_; i++) delete queues_[i];
|
||||||
#ifndef EIGEN_THREAD_LOCAL
|
#ifndef EIGEN_THREAD_LOCAL
|
||||||
for (auto it : per_thread_map_) delete it.second;
|
for (auto it : per_thread_map_) delete it.second;
|
||||||
#endif
|
#endif
|
||||||
@ -298,7 +298,7 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
// If we are shutting down and all worker threads blocked without work,
|
// If we are shutting down and all worker threads blocked without work,
|
||||||
// that's we are done.
|
// that's we are done.
|
||||||
blocked_++;
|
blocked_++;
|
||||||
if (done_ && blocked_ == num_threads_) {
|
if (done_ && blocked_ == static_cast<unsigned>(num_threads_)) {
|
||||||
ec_.CancelWait(waiter);
|
ec_.CancelWait(waiter);
|
||||||
// Almost done, but need to re-check queues.
|
// Almost done, but need to re-check queues.
|
||||||
// Consider that all queues are empty and all worker threads are preempted
|
// Consider that all queues are empty and all worker threads are preempted
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#ifndef EIGEN_CXX11_THREADPOOL_RUNQUEUE_H_
|
#ifndef EIGEN_CXX11_THREADPOOL_RUNQUEUE_H_
|
||||||
#define EIGEN_CXX11_THREADPOOL_RUNQUEUE_H_
|
#define EIGEN_CXX11_THREADPOOL_RUNQUEUE_H_
|
||||||
|
|
||||||
|
|
||||||
namespace Eigen {
|
namespace Eigen {
|
||||||
|
|
||||||
// RunQueue is a fixed-size, partially non-blocking deque or Work items.
|
// RunQueue is a fixed-size, partially non-blocking deque or Work items.
|
||||||
@ -47,7 +46,7 @@ class RunQueue {
|
|||||||
array_[i].state.store(kEmpty, std::memory_order_relaxed);
|
array_[i].state.store(kEmpty, std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
~RunQueue() { eigen_assert(Size() == 0); }
|
~RunQueue() { eigen_plain_assert(Size() == 0); }
|
||||||
|
|
||||||
// PushFront inserts w at the beginning of the queue.
|
// PushFront inserts w at the beginning of the queue.
|
||||||
// If queue is full returns w, otherwise returns default-constructed Work.
|
// If queue is full returns w, otherwise returns default-constructed Work.
|
||||||
@ -131,9 +130,8 @@ class RunQueue {
|
|||||||
Elem* e = &array_[mid & kMask];
|
Elem* e = &array_[mid & kMask];
|
||||||
uint8_t s = e->state.load(std::memory_order_relaxed);
|
uint8_t s = e->state.load(std::memory_order_relaxed);
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
if (s != kReady ||
|
if (s != kReady || !e->state.compare_exchange_strong(
|
||||||
!e->state.compare_exchange_strong(s, kBusy,
|
s, kBusy, std::memory_order_acquire))
|
||||||
std::memory_order_acquire))
|
|
||||||
continue;
|
continue;
|
||||||
start = mid;
|
start = mid;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user