mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Fix race condition in LimitedWaitable between Notify and Wait
This commit is contained in:
parent
bde54ccdc0
commit
adfce57d9e
2 changed files with 3 additions and 3 deletions
|
@ -12,8 +12,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wait() override {
|
void Wait() override {
|
||||||
|
std::unique_lock<std::mutex> lock;
|
||||||
if (!triggered_) {
|
if (!triggered_) {
|
||||||
std::unique_lock<std::mutex> lock;
|
|
||||||
cond_.wait(lock, [&] { return triggered_.load(); });
|
cond_.wait(lock, [&] { return triggered_.load(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,18 +12,18 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wait() override {
|
void Wait() override {
|
||||||
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
if (!triggered_) {
|
if (!triggered_) {
|
||||||
std::unique_lock<std::mutex> lock(mutex_);
|
|
||||||
cond_.wait(lock, [&] { return triggered_.load(); });
|
cond_.wait(lock, [&] { return triggered_.load(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaitFor(double budget) {
|
bool WaitFor(double budget) {
|
||||||
uint32_t us = budget > 0 ? (uint32_t)(budget * 1000000.0) : 0;
|
uint32_t us = budget > 0 ? (uint32_t)(budget * 1000000.0) : 0;
|
||||||
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
if (!triggered_) {
|
if (!triggered_) {
|
||||||
if (us == 0)
|
if (us == 0)
|
||||||
return false;
|
return false;
|
||||||
std::unique_lock<std::mutex> lock(mutex_);
|
|
||||||
cond_.wait_for(lock, std::chrono::microseconds(us), [&] { return triggered_.load(); });
|
cond_.wait_for(lock, std::chrono::microseconds(us), [&] { return triggered_.load(); });
|
||||||
}
|
}
|
||||||
return triggered_;
|
return triggered_;
|
||||||
|
|
Loading…
Add table
Reference in a new issue