From c9281603de4b1516dea0bea8593856d4f731aa79 Mon Sep 17 00:00:00 2001
From: kevin <kevin@larke.org>
Date: Mon, 25 Mar 2024 14:29:25 -0400
Subject: [PATCH] cwNbMpScQueue.h/cpp: Added count().

---
 cwNbMpScQueue.cpp | 12 ++++++++++++
 cwNbMpScQueue.h   |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/cwNbMpScQueue.cpp b/cwNbMpScQueue.cpp
index 2940b8f..70fbb1d 100644
--- a/cwNbMpScQueue.cpp
+++ b/cwNbMpScQueue.cpp
@@ -408,6 +408,18 @@ bool cw::nbmpscq::is_empty( handle_t h )
   return next == nullptr;
 }
 
+unsigned cw::nbmpscq::count( handle_t h )
+{
+  nbmpscq_t* p = _handleToPtr(h);
+
+  block_t* b = p->blockL;
+  int eleN = 0;
+  for(; b!=nullptr; b=b->link)
+    eleN += b->eleN.load(std::memory_order_acquire);
+
+  return eleN;
+}
+
 cw::rc_t cw::nbmpscq::test( const object_t* cfg )
 {
   rc_t rc=kOkRC,rc0,rc1;
diff --git a/cwNbMpScQueue.h b/cwNbMpScQueue.h
index ac3dbf2..fe6c13e 100644
--- a/cwNbMpScQueue.h
+++ b/cwNbMpScQueue.h
@@ -71,6 +71,8 @@ namespace cw
     
     bool is_empty( handle_t h );
 
+    unsigned count( handle_t h );
+
     rc_t test( const object_t* cfg );
     
   }