rtpsw commented on code in PR #34311:
URL: https://github.com/apache/arrow/pull/34311#discussion_r1116168128


##########
cpp/src/arrow/compute/exec/aggregate_node.cc:
##########
@@ -43,7 +44,45 @@ namespace compute {
 
 namespace {
 
-namespace {
+/// \brief A gated shared mutex is similar to a shared mutex, in that it 
allows either
+/// multiple shared readers or a unique writer access to the mutex, except 
that a waiting
+/// writer gates future readers by preventing them from reacquiring shared 
access until it
+/// has acquired and released the mutex. This is useful for ensuring a writer 
is never
+/// starved by readers.
+struct GatedSharedMutex {
+  std::mutex gate;
+  std::shared_mutex mutex;
+};
+
+/// \brief Acquires unique access to a gatex mutex. This is useful for a 
unique writer.
+class GatedUniqueLock {
+ public:
+  // acquires the gate first, to ensure future readers will wait for its 
release
+  explicit GatedUniqueLock(GatedSharedMutex& gated_shared_mutex)
+      : lock_gate_(gated_shared_mutex.gate), 
lock_mutex_(gated_shared_mutex.mutex) {}
+
+ private:
+  std::unique_lock<std::mutex> lock_gate_;
+  std::unique_lock<std::shared_mutex> lock_mutex_;
+};
+
+/// \brief Acquires shared access to a gatex mutex. This is useful for a 
shared reader.
+class GatedSharedLock {

Review Comment:
   It's from [an earlier phase of working on this 
PR](https://github.com/apache/arrow/pull/14352#issuecomment-1279750410) and is 
only needed for multi-threaded segmented aggregation, which we decided not to 
support for now, so it can (and will) be removed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to