]> git.proxmox.com Git - ceph.git/blob - ceph/src/log/EntryQueue.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / log / EntryQueue.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef __CEPH_LOG_ENTRYQUEUE_H
5 #define __CEPH_LOG_ENTRYQUEUE_H
6
7 #include "Entry.h"
8
9 namespace ceph {
10 namespace logging {
11
12 struct EntryQueue {
13 int m_len;
14 struct Entry *m_head, *m_tail;
15
16 bool empty() const {
17 return m_len == 0;
18 }
19
20 void swap(EntryQueue& other) {
21 int len = m_len;
22 struct Entry *h = m_head, *t = m_tail;
23 m_len = other.m_len;
24 m_head = other.m_head;
25 m_tail = other.m_tail;
26 other.m_len = len;
27 other.m_head = h;
28 other.m_tail = t;
29 }
30
31 void enqueue(Entry *e) {
32 if (m_tail) {
33 m_tail->m_next = e;
34 m_tail = e;
35 } else {
36 m_head = m_tail = e;
37 }
38 m_len++;
39 }
40
41 Entry *dequeue() {
42 if (!m_head)
43 return NULL;
44 Entry *e = m_head;
45 m_head = m_head->m_next;
46 if (!m_head)
47 m_tail = NULL;
48 m_len--;
49 e->m_next = NULL;
50 return e;
51 }
52
53 EntryQueue()
54 : m_len(0),
55 m_head(NULL),
56 m_tail(NULL)
57 {}
58 ~EntryQueue() {
59 Entry *t;
60 while (m_head) {
61 t = m_head->m_next;
62 delete m_head;
63 m_head = t;
64 }
65 }
66 };
67
68 }
69 }
70
71 #endif