summaryrefslogtreecommitdiffstats
path: root/src/include/util
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2010-10-04 17:48:47 -0500
committerPatrick Williams <iawillia@us.ibm.com>2010-10-04 17:48:47 -0500
commit3e9ed72a3b6442eaebadf26294e448862c3a4400 (patch)
treef3745143af3f1f87d99f3dec1256549195bf7fe1 /src/include/util
parent706838262ce47efeb8f983920a218460b81f2dc3 (diff)
downloadtalos-hostboot-3e9ed72a3b6442eaebadf26294e448862c3a4400.tar.gz
talos-hostboot-3e9ed72a3b6442eaebadf26294e448862c3a4400.zip
Add nanosleep syscall.
Diffstat (limited to 'src/include/util')
-rw-r--r--src/include/util/locked/pqueue.H112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/include/util/locked/pqueue.H b/src/include/util/locked/pqueue.H
new file mode 100644
index 000000000..c32e4e718
--- /dev/null
+++ b/src/include/util/locked/pqueue.H
@@ -0,0 +1,112 @@
+#ifndef __UTIL_LOCKED_PQUEUE_H
+#define __UTIL_LOCKED_PQUEUE_H
+
+#include <util/locked/queue.H>
+
+namespace Util
+{
+ namespace Locked
+ {
+ template <typename _T, typename _K,
+ bool locked = false, typename _S = int>
+ class PQueue : public Queue<_T, locked, _S>
+ {
+ public:
+ void insert(_T*);
+ _T* remove_if(_K&);
+
+ private:
+ void bubbleUp(_T*);
+ };
+
+ template <typename _T, typename _K, bool locked, typename _S>
+ void PQueue<_T,_K,locked,_S>::insert(_T* item)
+ {
+ this->__lock();
+
+ if (this->head == NULL)
+ {
+ item->next = item->prev = NULL;
+ this->head = this->tail = item;
+ }
+ else
+ {
+ item->prev = NULL;
+ item->next = this->head;
+ this->head = this->head->prev = item;
+
+ bubbleUp(item);
+ }
+
+ this->__unlock();
+ }
+
+ template <typename _T, typename _K, bool locked, typename _S>
+ _T* PQueue<_T,_K,locked,_S>::remove_if(_K& key)
+ {
+ _T* item = NULL;
+
+ this->__lock();
+
+ if ((this->tail != NULL) && (this->tail->key <= key))
+ {
+ item = this->tail;
+ if (this->head == this->tail)
+ this->head = this->tail = NULL;
+ else
+ this->tail = item->prev;
+ }
+
+ this->__unlock();
+
+ return item;
+ }
+
+
+ template <typename _T, typename _K, bool locked, typename _S>
+ void PQueue<_T,_K,locked,_S>::bubbleUp(_T* item)
+ {
+ if (!item->next)
+ return;
+
+ if (item->next->key <= item->key)
+ return;
+
+ if (this->head == item)
+ this->head = item->next;
+ if (this->tail == item->next)
+ this->tail = item;
+
+ _T* temp = item->next;
+
+ if (temp->next)
+ {
+ temp->next->prev = item;
+ item->next = item->next->next;
+ }
+ else
+ {
+ item->next = NULL;
+ }
+
+ if (item->prev)
+ {
+ item->prev->next = temp;
+ temp->prev = item->prev;
+ }
+ else
+ {
+ temp->prev = NULL;
+ }
+
+ temp->next = item;
+ item->prev = temp;
+
+ bubbleUp(item);
+ }
+
+
+ };
+};
+
+#endif
OpenPOWER on IntegriCloud