summaryrefslogtreecommitdiffstats
path: root/src/usr/trace/tracebuffer.C
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2011-04-08 12:25:37 -0500
committerPatrick Williams <iawillia@us.ibm.com>2011-04-08 12:25:37 -0500
commit770f2f7e5d826b11c6e65d929dcc44a203833abc (patch)
tree7b389798264f36fbc5b3e5bebc8e1a7fc9dc8ea0 /src/usr/trace/tracebuffer.C
parent7088cec37222610a2e45838550dc7bf30f0f8d81 (diff)
downloadblackbird-hostboot-770f2f7e5d826b11c6e65d929dcc44a203833abc.tar.gz
blackbird-hostboot-770f2f7e5d826b11c6e65d929dcc44a203833abc.zip
Rename trace buffer to match coding conventions.
Diffstat (limited to 'src/usr/trace/tracebuffer.C')
-rw-r--r--src/usr/trace/tracebuffer.C53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/usr/trace/tracebuffer.C b/src/usr/trace/tracebuffer.C
new file mode 100644
index 000000000..5e5b697a1
--- /dev/null
+++ b/src/usr/trace/tracebuffer.C
@@ -0,0 +1,53 @@
+#include <limits.h>
+#include "tracebuffer.H"
+
+TracePage* TracePage::setNext(TracePage* new_next)
+{
+ return __sync_val_compare_and_swap(&this->next, NULL, new_next);
+}
+
+traceEntry* TracePage::claimEntry(size_t size)
+{
+ size_t position = __sync_fetch_and_add(&this->size, size);
+ if (position > (PAGE_SIZE - sizeof(TracePage)))
+ {
+ return NULL;
+ }
+ else
+ {
+ return (traceEntry*)&((uint8_t*)this)[sizeof(TracePage) + position];
+ }
+}
+
+traceEntry* TraceBuffer::claimEntry(size_t size)
+{
+ traceEntry* result = NULL;
+ TracePage* page = last;
+
+ while (result == NULL)
+ {
+ result = page->claimEntry(size);
+
+ if (NULL == result)
+ {
+ if (NULL != page->getNext())
+ {
+ __sync_bool_compare_and_swap(&this->last,
+ page, page->getNext());
+ page = page->getNext();
+ }
+ else
+ {
+ TracePage* new_page = new (malloc(PAGE_SIZE)) TracePage();
+ TracePage* prev = page;
+
+ while(prev != NULL)
+ {
+ prev = prev->setNext(new_page);
+ }
+ }
+ }
+ }
+
+ return result;
+}
OpenPOWER on IntegriCloud