Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: cc/ring_buffer.h

Issue 11817011: cc: add RingBuffer class for timestamp storing in FrameRateCounter (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: size_t for buffer size, index and loops Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CC_RING_BUFFER_H_
6 #define CC_RING_BUFFER_H_
7
8 #include "base/logging.h"
9
10 namespace cc {
11
12 template<typename T, size_t size>
egraether 2013/01/11 23:28:06 Used size_t for buffer size, index, parameters and
13 class RingBuffer {
14 public:
15 explicit RingBuffer()
16 : current_index_(0) {
17 }
18
19 size_t BufferSize() const {
20 return size;
21 }
22
23 size_t CurrentIndex() const {
24 return current_index_;
25 }
26
27 // tests if a value was saved to this index
28 bool IsFilledIndex(size_t n) const {
29 return BufferIndex(n) < current_index_;
30 }
31
32 // n = 0 returns the oldest value and
33 // n = bufferSize() - 1 returns the most recent value.
34 T ReadBuffer(size_t n) const {
35 DCHECK(IsFilledIndex(n));
36 return buffer_[BufferIndex(n)];
37 }
38
39 void SaveToBuffer(T value) {
40 buffer_[BufferIndex(0)] = value;
41 current_index_++;
42 }
43
44 private:
45 inline size_t BufferIndex(size_t n) const {
46 return (current_index_ + n) % size;
47 }
48
49 T buffer_[size];
50 size_t current_index_;
51 };
52
53 } // namespace cc
54
55 #endif // CC_RING_BUFFER_H_
OLDNEW
« no previous file with comments | « cc/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698