Simplify sw::Chan
Remove the 'removed' condition_variable field. It is not used.
Don't bother copying and unlocking before returning a field - this is not required.
Bug: b/133127573
Change-Id: Ic8e29e6b6008e16b6abd043ccfa9014e203ce69a
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31678
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Ben Clayton <headlessclayton@gmail.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/System/Synchronization.hpp b/src/System/Synchronization.hpp
index 797af8e..ac9b652 100644
--- a/src/System/Synchronization.hpp
+++ b/src/System/Synchronization.hpp
@@ -52,7 +52,6 @@
std::queue<T> queue;
std::mutex mutex;
std::condition_variable added;
- std::condition_variable removed;
};
template <typename T>
@@ -62,15 +61,10 @@
T Chan<T>::take()
{
std::unique_lock<std::mutex> lock(mutex);
- if (queue.size() == 0)
- {
- // Chan empty. Wait for item to be added.
- added.wait(lock, [this] { return queue.size() > 0; });
- }
+ // Wait for item to be added.
+ added.wait(lock, [this] { return queue.size() > 0; });
T out = queue.front();
queue.pop();
- lock.unlock();
- removed.notify_one();
return out;
}
@@ -84,8 +78,6 @@
}
T out = queue.front();
queue.pop();
- lock.unlock();
- removed.notify_one();
return std::make_pair(out, true);
}
@@ -102,9 +94,7 @@
size_t Chan<T>::count()
{
std::unique_lock<std::mutex> lock(mutex);
- auto out = queue.size();
- lock.unlock();
- return out;
+ return queue.size();
}
} // namespace sw