mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-15 18:49:51 +01:00
Big mutex overhaul - remove our custom ones, make them non-recursive where possible
This commit is contained in:
1 parent
54f862cda6
commit
26a2d42731
75 files changed
+561
-882
No files matched your search
@@ -12,19 +12,19 @@ PrioritizedWorkQueue::~PrioritizedWorkQueue() {
|
||||
}
|
||||
|
||||
void PrioritizedWorkQueue::Add(PrioritizedWorkQueueItem *item) {
|
||||
lock_guard guard(mutex_);
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
queue_.push_back(item);
|
||||
notEmpty_.notify_one();
|
||||
}
|
||||
|
||||
void PrioritizedWorkQueue::Stop() {
|
||||
lock_guard guard(mutex_);
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
done_ = true;
|
||||
notEmpty_.notify_one();
|
||||
}
|
||||
|
||||
void PrioritizedWorkQueue::Flush() {
|
||||
lock_guard guard(mutex_);
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
int flush_count = 0;
|
||||
for (auto iter = queue_.begin(); iter != queue_.end(); ++iter) {
|
||||
delete *iter;
|
||||
@@ -36,13 +36,13 @@ void PrioritizedWorkQueue::Flush() {
|
||||
|
||||
bool PrioritizedWorkQueue::WaitUntilDone(bool all) {
|
||||
// We'll lock drain this entire time, so make sure you follow that lock ordering.
|
||||
lock_guard guard(drainMutex_);
|
||||
std::unique_lock<std::mutex> guard(drainMutex_);
|
||||
if (AllItemsDone()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
while (!AllItemsDone()) {
|
||||
drain_.wait(drainMutex_);
|
||||
drain_.wait(guard);
|
||||
if (!all) {
|
||||
// Return whether empty or not, something just drained.
|
||||
return AllItemsDone();
|
||||
@@ -53,32 +53,32 @@ bool PrioritizedWorkQueue::WaitUntilDone(bool all) {
|
||||
}
|
||||
|
||||
void PrioritizedWorkQueue::NotifyDrain() {
|
||||
lock_guard guard(drainMutex_);
|
||||
std::lock_guard<std::mutex> guard(drainMutex_);
|
||||
drain_.notify_one();
|
||||
}
|
||||
|
||||
bool PrioritizedWorkQueue::AllItemsDone() {
|
||||
lock_guard guard(mutex_);
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
return queue_.empty() && !working_;
|
||||
}
|
||||
|
||||
// The worker should simply call this in a loop. Will block when appropriate.
|
||||
PrioritizedWorkQueueItem *PrioritizedWorkQueue::Pop() {
|
||||
{
|
||||
lock_guard guard(mutex_);
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
working_ = false; // The thread only calls Pop if it's done.
|
||||
}
|
||||
|
||||
// Important: make sure mutex_ is not locked while draining.
|
||||
NotifyDrain();
|
||||
|
||||
lock_guard guard(mutex_);
|
||||
std::unique_lock<std::mutex> guard(mutex_);
|
||||
if (done_) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (queue_.empty()) {
|
||||
notEmpty_.wait(mutex_);
|
||||
notEmpty_.wait(guard);
|
||||
if (done_) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user