Deleted Added
sdiff udiff text old ( 12334:e0ab29a34764 ) new ( 13483:0d5d061d974f )
full compact
1/*
2 * Copyright (c) 2015,2017-2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated

--- 28 unchanged lines hidden (view full) ---

39
40#ifndef __BASE_CIRCLEBUF_HH__
41#define __BASE_CIRCLEBUF_HH__
42
43#include <algorithm>
44#include <cassert>
45#include <vector>
46
47#include "base/circular_queue.hh"
48#include "base/logging.hh"
49#include "sim/serialize.hh"
50
51/**
52 * Circular buffer backed by a vector though a CircularQueue.
53 *
54 * The data in the cricular buffer is stored in a standard
55 * vector.
56 *
57 */
58template<typename T>
59class CircleBuf : public CircularQueue<T>
60{
61 public:
62 explicit CircleBuf(size_t size)
63 : CircularQueue<T>(size) {}
64 using CircularQueue<T>::empty;
65 using CircularQueue<T>::size;
66 using CircularQueue<T>::capacity;
67 using CircularQueue<T>::begin;
68 using CircularQueue<T>::end;
69 using CircularQueue<T>::pop_front;
70 using CircularQueue<T>::advance_tail;
71
72 /**
73 * Copy buffer contents without advancing the read pointer
74 *
75 * @param out Output iterator/pointer
76 * @param len Number of elements to copy
77 */
78 template <class OutputIterator>
79 void peek(OutputIterator out, size_t len) const {
80 peek(out, 0, len);

--- 6 unchanged lines hidden (view full) ---

87 * @param offset Offset into the ring buffer
88 * @param len Number of elements to copy
89 */
90 template <class OutputIterator>
91 void peek(OutputIterator out, off_t offset, size_t len) const {
92 panic_if(offset + len > size(),
93 "Trying to read past end of circular buffer.\n");
94
95 std::copy(begin() + offset, begin() + offset + len, out);
96 }
97
98 /**
99 * Copy buffer contents and advance the read pointer
100 *
101 * @param out Output iterator/pointer
102 * @param len Number of elements to read
103 */
104 template <class OutputIterator>
105 void read(OutputIterator out, size_t len) {
106 peek(out, len);
107 pop_front(len);
108 }
109
110 /**
111 * Add elements to the end of the ring buffers and advance.
112 *
113 * @param in Input iterator/pointer
114 * @param len Number of elements to read
115 */
116 template <class InputIterator>
117 void write(InputIterator in, size_t len) {
118 // Writes that are larger than the backing store are allowed,
119 // but only the last part of the buffer will be written.
120 if (len > capacity()) {
121 in += len - capacity();
122 len = capacity();
123 }
124
125 std::copy(in, in + len, end());
126 advance_tail(len);
127 }
128};
129
130/**
131 * Simple FIFO implementation backed by a circular buffer.
132 *
133 * This class provides the same basic functionallity as the circular
134 * buffer with the folling differences:
135 * <ul>
136 * <li>Writes are checked to ensure that overflows can't happen.
137 * <li>Unserialization ensures that the data in the checkpoint fits

--- 84 unchanged lines hidden ---