X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Flog%2FEntryQueue.h;fp=src%2Fceph%2Fsrc%2Flog%2FEntryQueue.h;h=8170dcb11b7c42dd700a13ad96f62775148d4d01;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/log/EntryQueue.h b/src/ceph/src/log/EntryQueue.h new file mode 100644 index 0000000..8170dcb --- /dev/null +++ b/src/ceph/src/log/EntryQueue.h @@ -0,0 +1,71 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef __CEPH_LOG_ENTRYQUEUE_H +#define __CEPH_LOG_ENTRYQUEUE_H + +#include "Entry.h" + +namespace ceph { +namespace logging { + +struct EntryQueue { + int m_len; + struct Entry *m_head, *m_tail; + + bool empty() const { + return m_len == 0; + } + + void swap(EntryQueue& other) { + int len = m_len; + struct Entry *h = m_head, *t = m_tail; + m_len = other.m_len; + m_head = other.m_head; + m_tail = other.m_tail; + other.m_len = len; + other.m_head = h; + other.m_tail = t; + } + + void enqueue(Entry *e) { + if (m_tail) { + m_tail->m_next = e; + m_tail = e; + } else { + m_head = m_tail = e; + } + m_len++; + } + + Entry *dequeue() { + if (!m_head) + return NULL; + Entry *e = m_head; + m_head = m_head->m_next; + if (!m_head) + m_tail = NULL; + m_len--; + e->m_next = NULL; + return e; + } + + EntryQueue() + : m_len(0), + m_head(NULL), + m_tail(NULL) + {} + ~EntryQueue() { + Entry *t; + while (m_head) { + t = m_head->m_next; + delete m_head; + m_head = t; + } + } +}; + +} +} + +#endif