summaryrefslogtreecommitdiffstats
path: root/src/include/util
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2011-03-27 16:14:39 -0500
committerPatrick Williams <iawillia@us.ibm.com>2011-03-27 16:15:50 -0500
commitd6570a2964cca62323ac6ca19b5d25973f73f45b (patch)
tree40a5252b2ff96e84394572f364394f7a88b07af6 /src/include/util
parentb814aa6f09053fc1dc41d3c3048119c6133419f2 (diff)
downloadtalos-hostboot-d6570a2964cca62323ac6ca19b5d25973f73f45b.tar.gz
talos-hostboot-d6570a2964cca62323ac6ca19b5d25973f73f45b.zip
Add size function to queue container.
Diffstat (limited to 'src/include/util')
-rw-r--r--src/include/util/locked/queue.H23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/include/util/locked/queue.H b/src/include/util/locked/queue.H
index 651e24a80..f4791ed7b 100644
--- a/src/include/util/locked/queue.H
+++ b/src/include/util/locked/queue.H
@@ -1,6 +1,7 @@
#ifndef __UTIL_LOCKED_QUEUE_H
#define __UTIL_LOCKED_QUEUE_H
+#include <stddef.h>
#include <util/locked/lock.H>
namespace Util
@@ -11,16 +12,20 @@ namespace Util
class Queue
{
public:
- Queue() : head(NULL), tail(NULL), lock() {};
+ Queue() : head(NULL), tail(NULL), count(0), lock() {};
~Queue() {};
_T* remove();
void insert(_T*);
+ size_t size();
+
protected:
_T* head;
_T* tail;
+ size_t count;
+
_S lock;
void __lock();
@@ -44,6 +49,8 @@ namespace Util
tail = item->prev;
}
+ count--;
+
__unlock();
return item;
@@ -65,11 +72,25 @@ namespace Util
item->next = head;
head = head->prev = item;
}
+
+ count++;
__unlock();
}
template <typename _T, bool locked, typename _S>
+ size_t Queue<_T,locked,_S>::size()
+ {
+ size_t sz = 0;
+
+ __lock();
+ sz = count;
+ __unlock();
+
+ return sz;
+ }
+
+ template <typename _T, bool locked, typename _S>
void Queue<_T,locked,_S>::__lock()
{
Util::Locked::LockHelper<locked,_S>(lock).lock();
OpenPOWER on IntegriCloud