OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_PARTIAL_CIRCULAR_BUFFER_H_ | 5 #ifndef CHROME_COMMON_PARTIAL_CIRCULAR_BUFFER_H_ |
6 #define CONTENT_COMMON_PARTIAL_CIRCULAR_BUFFER_H_ | 6 #define CHROME_COMMON_PARTIAL_CIRCULAR_BUFFER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "content/common/content_export.h" | |
11 | |
12 namespace content { | |
13 | 10 |
14 // A wrapper around a memory buffer that allows circular read and write with a | 11 // A wrapper around a memory buffer that allows circular read and write with a |
15 // selectable wrapping position. Buffer layout (after wrap; H is header): | 12 // selectable wrapping position. Buffer layout (after wrap; H is header): |
16 // ----------------------------------------------------------- | 13 // ----------------------------------------------------------- |
17 // | H | Beginning | End | Middle | | 14 // | H | Beginning | End | Middle | |
18 // ----------------------------------------------------------- | 15 // ----------------------------------------------------------- |
19 // ^---- Non-wrapping -----^ ^--------- Wrapping ----------^ | 16 // ^---- Non-wrapping -----^ ^--------- Wrapping ----------^ |
20 // The non-wrapping part is never overwritten. The wrapping part will be | 17 // The non-wrapping part is never overwritten. The wrapping part will be |
21 // circular. The very first part is the header (see the BufferData struct | 18 // circular. The very first part is the header (see the BufferData struct |
22 // below). It consists of the following information: | 19 // below). It consists of the following information: |
23 // - Length written to the buffer (not including header). | 20 // - Length written to the buffer (not including header). |
24 // - Wrapping position. | 21 // - Wrapping position. |
25 // - End position of buffer. (If the last byte is at x, this will be x + 1.) | 22 // - End position of buffer. (If the last byte is at x, this will be x + 1.) |
26 // Users of wrappers around the same underlying buffer must ensure that writing | 23 // Users of wrappers around the same underlying buffer must ensure that writing |
27 // is finished before reading is started. | 24 // is finished before reading is started. |
28 class CONTENT_EXPORT PartialCircularBuffer { | 25 class PartialCircularBuffer { |
29 public: | 26 public: |
30 // Use for reading. |buffer_size| is in bytes and must be larger than the | 27 // Use for reading. |buffer_size| is in bytes and must be larger than the |
31 // header size (see above). | 28 // header size (see above). |
32 PartialCircularBuffer(void* buffer, uint32 buffer_size); | 29 PartialCircularBuffer(void* buffer, uint32 buffer_size); |
33 | 30 |
34 // Use for writing. |buffer_size| is in bytes and must be larger than the | 31 // Use for writing. |buffer_size| is in bytes and must be larger than the |
35 // header size (see above). | 32 // header size (see above). |
36 PartialCircularBuffer(void* buffer, | 33 PartialCircularBuffer(void* buffer, |
37 uint32 buffer_size, | 34 uint32 buffer_size, |
38 uint32 wrap_position); | 35 uint32 wrap_position); |
(...skipping 19 matching lines...) Expand all Loading... |
58 // Used for reading and writing. | 55 // Used for reading and writing. |
59 BufferData* buffer_data_; | 56 BufferData* buffer_data_; |
60 uint32 memory_buffer_size_; | 57 uint32 memory_buffer_size_; |
61 uint32 data_size_; | 58 uint32 data_size_; |
62 uint32 position_; | 59 uint32 position_; |
63 | 60 |
64 // Used for reading. | 61 // Used for reading. |
65 uint32 total_read_; | 62 uint32 total_read_; |
66 }; | 63 }; |
67 | 64 |
68 } // namespace content | 65 #endif // CHROME_COMMON_PARTIAL_CIRCULAR_BUFFER_H_ |
69 | |
70 #endif // CONTENT_COMMON_PARTIAL_CIRCULAR_BUFFER_H_ | |
OLD | NEW |