summaryrefslogtreecommitdiffstats
path: root/src/include/util
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2010-05-21 07:37:12 -0500
committerPatrick Williams <iawillia@us.ibm.com>2010-05-21 07:37:12 -0500
commitb9652b36ff9bfa429ff3e9756e7e43f0da4ea1a7 (patch)
tree6e4ad709b3c9ad1cf45905d1c420751429284634 /src/include/util
parentd9d7e6c7247aaf5d2721d08a365e9c51ec18c870 (diff)
downloadtalos-hostboot-b9652b36ff9bfa429ff3e9756e7e43f0da4ea1a7.tar.gz
talos-hostboot-b9652b36ff9bfa429ff3e9756e7e43f0da4ea1a7.zip
Move pagemgr to generic lock free structure.
Diffstat (limited to 'src/include/util')
-rw-r--r--src/include/util/lockfree/stack.H47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/include/util/lockfree/stack.H b/src/include/util/lockfree/stack.H
new file mode 100644
index 000000000..8f884e072
--- /dev/null
+++ b/src/include/util/lockfree/stack.H
@@ -0,0 +1,47 @@
+#ifndef __UTIL_LOCKFREE_STACK_H
+#define __UTIL_LOCKFREE_STACK_H
+
+#include <stddef.h>
+
+namespace Util
+{
+ namespace Lockfree
+ {
+ template <typename _T>
+ class Stack
+ {
+ public:
+ Stack() : head(NULL) {};
+
+ _T* pop();
+ void push(_T*);
+
+ private:
+ _T* head;
+ };
+
+ template <typename _T>
+ _T* Stack<_T>::pop()
+ {
+ _T * h = head;
+ if (NULL == h) return h;
+ if (!__sync_bool_compare_and_swap(&head,
+ h,
+ h->next))
+ return pop();
+ return h;
+ }
+
+ template <typename _T>
+ void Stack<_T>::push(_T* p)
+ {
+ p->next = head;
+ if (!__sync_bool_compare_and_swap(&head,
+ p->next,
+ p))
+ push(p);
+ }
+ }
+}
+
+#endif
OpenPOWER on IntegriCloud