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