summaryrefslogtreecommitdiffstats
path: root/src/include
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
parentd9d7e6c7247aaf5d2721d08a365e9c51ec18c870 (diff)
downloadtalos-hostboot-b9652b36ff9bfa429ff3e9756e7e43f0da4ea1a7.tar.gz
talos-hostboot-b9652b36ff9bfa429ff3e9756e7e43f0da4ea1a7.zip
Move pagemgr to generic lock free structure.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/kernel/pagemgr.H5
-rw-r--r--src/include/util/lockfree/stack.H47
2 files changed, 50 insertions, 2 deletions
diff --git a/src/include/kernel/pagemgr.H b/src/include/kernel/pagemgr.H
index 1d7193b22..b99cedff2 100644
--- a/src/include/kernel/pagemgr.H
+++ b/src/include/kernel/pagemgr.H
@@ -2,6 +2,7 @@
#define __KERNEL_PAGEMGR_H
#include <stdint.h>
+#include <util/lockfree/stack.H>
/** @class PageManager
* @brief Manages the allocation of memory pages.
@@ -31,9 +32,9 @@ class PageManager
struct page_t
{
- page_t* next_page;
+ page_t* next;
};
- page_t* first_page[BUCKETS];
+ Util::Lockfree::Stack<page_t> first_page[BUCKETS];
page_t* pop_bucket(size_t);
void push_bucket(page_t*, size_t);
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