summaryrefslogtreecommitdiffstats
path: root/src/include/util
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2010-06-09 16:14:11 -0500
committerPatrick Williams <iawillia@us.ibm.com>2010-06-09 16:14:11 -0500
commit165e6bed506f9fddd7e9da8ad1f4c7f186e29b00 (patch)
tree6f6f94922b87d47f7111285a5f9482b41779c92b /src/include/util
parente7a6ae9cc5b84abe63c7439005656ecc4beda8c1 (diff)
downloadtalos-hostboot-165e6bed506f9fddd7e9da8ad1f4c7f186e29b00.tar.gz
talos-hostboot-165e6bed506f9fddd7e9da8ad1f4c7f186e29b00.zip
Change scheduler to locked queue instead of stack-pair.
Diffstat (limited to 'src/include/util')
-rw-r--r--src/include/util/locked/queue.H73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/include/util/locked/queue.H b/src/include/util/locked/queue.H
new file mode 100644
index 000000000..2f230819e
--- /dev/null
+++ b/src/include/util/locked/queue.H
@@ -0,0 +1,73 @@
+#ifndef __UTIL_LOCKED_QUEUE_H
+#define __UTIL_LOCKED_QUEUE_H
+
+namespace Util
+{
+ namespace Locked
+ {
+ template <typename _T, bool locked = false, typename _S = int>
+ class Queue
+ {
+ public:
+ Queue() : head(NULL), tail(NULL), lock() {};
+ ~Queue() {};
+
+ _T* remove();
+ void insert(_T*);
+
+ private:
+ _T* head;
+ _T* tail;
+
+ _S lock;
+
+ };
+
+ template <typename _T, bool locked, typename _S>
+ _T* Queue<_T,locked,_S>::remove()
+ {
+ _T* item = NULL;
+
+ if (locked)
+ lock.lock();
+
+ if (tail != NULL)
+ {
+ item = tail;
+ if (head == tail)
+ head = tail = NULL;
+ else
+ tail = item->prev;
+ }
+
+ if (locked)
+ lock.unlock();
+
+ return item;
+ }
+
+ template <typename _T, bool locked, typename _S>
+ void Queue<_T,locked,_S>::insert(_T* item)
+ {
+ if (locked)
+ lock.lock();
+
+ if (head == NULL)
+ {
+ item->next = item->prev = NULL;
+ head = tail = item;
+ }
+ else
+ {
+ item->prev = NULL;
+ item->next = head;
+ head = head->prev = item;
+ }
+
+ if (locked)
+ lock.unlock();
+ }
+ };
+};
+
+#endif
OpenPOWER on IntegriCloud