mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 09:35:09 +02:00
Fix misuses of cond.wait (should return true when you want to stop waiting!)
This commit is contained in:
@@ -7,12 +7,15 @@
|
||||
|
||||
struct Event : public Waitable {
|
||||
public:
|
||||
Event() {
|
||||
triggered_ = false;
|
||||
}
|
||||
|
||||
void Wait() override {
|
||||
if (triggered_) {
|
||||
return;
|
||||
if (!triggered_) {
|
||||
std::unique_lock<std::mutex> lock;
|
||||
cond_.wait(lock, [&] { return triggered_.load(); });
|
||||
}
|
||||
std::unique_lock<std::mutex> lock;
|
||||
cond_.wait(lock, [&] { return !triggered_; });
|
||||
}
|
||||
|
||||
void Notify() {
|
||||
@@ -24,5 +27,5 @@ public:
|
||||
private:
|
||||
std::condition_variable cond_;
|
||||
std::mutex mutex_;
|
||||
bool triggered_ = false;
|
||||
std::atomic<bool> triggered_;
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
void Wait() override {
|
||||
if (!triggered_) {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
cond_.wait(lock, [&] { return !triggered_; });
|
||||
cond_.wait(lock, [&] { return triggered_.load(); });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
if (us == 0)
|
||||
return false;
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
cond_.wait_for(lock, std::chrono::microseconds(us), [&] { return !triggered_; });
|
||||
cond_.wait_for(lock, std::chrono::microseconds(us), [&] { return triggered_.load(); });
|
||||
}
|
||||
return triggered_;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <thread>
|
||||
|
||||
#include "Common/Log.h"
|
||||
#include "Common/TimeUtil.h"
|
||||
#include "Common/Thread/Barrier.h"
|
||||
@@ -62,7 +64,7 @@ bool TestParallelLoop(ThreadManager *threadMan) {
|
||||
|
||||
// This is some ugly stuff but realistic.
|
||||
const size_t THREAD_COUNT = 6; // Must match the number of threads in TestMultithreadedScheduling
|
||||
const size_t ITERATIONS = 1000;
|
||||
const size_t ITERATIONS = 40000;
|
||||
|
||||
static std::atomic<int> g_atomicCounter;
|
||||
static ThreadManager *g_threadMan;
|
||||
|
||||
Reference in New Issue
Block a user