From df8e17d8e851c34a83de6c508aba07f6bde12a10 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Wed, 10 Nov 2021 10:13:38 -0500
Subject: [PATCH] SL-16094: Add WorkQueue::size() method to support changeset
 08336bb.

We want to skip calling PostMessage() to bump the window thread out of
GetMessage() in any frame with no work functions pending for that thread. That
test depends on being able to sense the size() of the queue. Having converted
to WorkQueue, we need that queue to support size().
---
 indra/llcommon/workqueue.cpp |  5 +++++
 indra/llcommon/workqueue.h   | 15 +++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/indra/llcommon/workqueue.cpp b/indra/llcommon/workqueue.cpp
index 14ae4c4ab82..633594ceea7 100644
--- a/indra/llcommon/workqueue.cpp
+++ b/indra/llcommon/workqueue.cpp
@@ -39,6 +39,11 @@ void LL::WorkQueue::close()
     mQueue.close();
 }
 
+size_t LL::WorkQueue::size()
+{
+    return mQueue.size();
+}
+
 bool LL::WorkQueue::isClosed()
 {
     return mQueue.isClosed();
diff --git a/indra/llcommon/workqueue.h b/indra/llcommon/workqueue.h
index 5987883829b..c25d7874254 100644
--- a/indra/llcommon/workqueue.h
+++ b/indra/llcommon/workqueue.h
@@ -64,6 +64,21 @@ namespace LL
          */
         void close();
 
+        /**
+         * WorkQueue supports multiple producers and multiple consumers. In
+         * the general case it's misleading to test size(), since any other
+         * thread might change it the nanosecond the lock is released. On that
+         * basis, some might argue against publishing a size() method at all.
+         *
+         * But there are two specific cases in which a test based on size()
+         * might be reasonable:
+         *
+         * * If you're the only producer, noticing that size() == 0 is
+         *   meaningful.
+         * * If you're the only consumer, noticing that size() > 0 is
+         *   meaningful.
+         */
+        size_t size();
         /// producer end: are we prevented from pushing any additional items?
         bool isClosed();
         /// consumer end: are we done, is the queue entirely drained?
-- 
GitLab