Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 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 PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_ | |
| 6 #define PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "ppapi/shared_impl/ppapi_shared_export.h" | |
| 10 | |
| 11 namespace ppapi { | |
| 12 | |
| 13 class PPAPI_SHARED_EXPORT CircularBuffer { | |
| 14 public: | |
| 15 // Construct a CircularBuffer by given underlying buffer and size. | |
|
yzshen1
2014/01/03 21:51:41
Construct*s*
| |
| 16 CircularBuffer(void* buffer, uint32_t size); | |
| 17 | |
| 18 ~CircularBuffer(); | |
| 19 | |
| 20 // Remaining buffer size for reading or writing. | |
|
dmichael (off chromium)
2014/01/03 18:05:29
nit: size in bytes? Same above.
| |
| 21 uint32_t remaining() const { | |
|
dmichael (off chromium)
2014/01/03 18:05:29
I'm worried this might get confusing for users of
| |
| 22 return remaining_; | |
| 23 } | |
| 24 | |
| 25 // Moves position forward by given offset. | |
| 26 void MovePosition(uint32_t offset); | |
| 27 | |
| 28 // Moves limit forward by given offset. | |
| 29 void MoveLimit(uint32_t offset); | |
|
dmichael (off chromium)
2014/01/03 18:05:29
Should these be private or protected? Doesn't seem
| |
| 30 | |
| 31 // Reads data and move position forward. The actual read size will be | |
|
yzshen1
2014/01/03 21:51:41
move*s*
| |
| 32 // returned. | |
| 33 int32_t Read(void* buffer, uint32_t size); | |
|
yzshen1
2014/01/03 21:51:41
The uint32_t and int32_t mismatch seems a little w
| |
| 34 | |
| 35 // Similar to |Read()|, but it will fail, if the circular buffer does not have | |
|
dmichael (off chromium)
2014/01/03 18:05:29
nit: no comma after fail (same for WriteAll)
| |
| 36 // enough data. | |
| 37 int32_t ReadAll(void* buffer, uint32_t size); | |
| 38 | |
| 39 // Writes data and move position forward. The actual write size will be | |
|
yzshen1
2014/01/03 21:51:41
move*s*
| |
| 40 // returned. | |
| 41 int32_t Write(const void* buffer, uint32_t size); | |
| 42 | |
| 43 // Similar to |Write()|, but it will fail, if the circular buffer does not | |
| 44 // have enough space for the given size of data. | |
| 45 int32_t WriteAll(const void* buffer, uint32_t size); | |
|
dmichael (off chromium)
2014/01/03 18:05:29
Should WriteAll and ReadAll return bool instead of
| |
| 46 | |
| 47 // Locks the given size of underlying buffer for direct accessing. | |
| 48 int32_t Lock(void** buffer, uint32_t size); | |
|
yzshen1
2014/01/03 21:51:41
What is the meaning of the return value? Do you me
| |
| 49 | |
| 50 // Relocks underlying buffer. It is used for adjusting locked block size; | |
|
dmichael (off chromium)
2014/01/03 18:05:29
nit: semicolon should be a period. Please also not
| |
| 51 int32_t Relock(void* buffer, uint32_t size); | |
| 52 | |
| 53 // Unlocks buffer which is locked by previous |Lock()| call. The locked block | |
|
yzshen1
2014/01/03 21:51:41
Is it still necessary to return the block size?
| |
| 54 // size will be returned. | |
|
dmichael (off chromium)
2014/01/03 18:05:29
You should also note that the position is moved by
| |
| 55 int32_t Unlock(const void* buffer); | |
|
yzshen1
2014/01/03 21:51:41
Now that it is only allow to lock one block at a t
| |
| 56 | |
| 57 // Returns true if the circular buffer is locked. | |
| 58 bool IsLocked() const { return locked_buffer_; } | |
| 59 | |
| 60 private: | |
| 61 int32_t ReadInternal(void* buffer, uint32_t size); | |
| 62 | |
| 63 int32_t WriteInternal(const void* buffer, uint32_t size); | |
| 64 | |
| 65 // Underlying buffer pointer. | |
| 66 uint8_t* buffer_; | |
|
dmichael (off chromium)
2014/01/03 18:05:29
You should probably note that this is unowned (it
| |
| 67 | |
| 68 // Underlying buffer size. | |
| 69 uint32_t buffer_size_; | |
| 70 | |
| 71 // Current position for reading or writing. | |
| 72 uint32_t position_; | |
| 73 | |
| 74 // The limit position for reading or writing. | |
| 75 uint32_t limit_; | |
| 76 | |
| 77 // Remaining buffer size for reading or writing. | |
| 78 uint32_t remaining_; | |
| 79 | |
| 80 // Locked buffer pointer returned by |Lock()|. It will be reset to NULL, | |
| 81 // When |Unlock()| is called. | |
|
dmichael (off chromium)
2014/01/03 18:05:29
nit: no comma after NULL, "When" should not be cap
| |
| 82 uint8_t* locked_buffer_; | |
| 83 | |
| 84 // Locked buffer size. | |
| 85 uint32_t locked_buffer_size_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(CircularBuffer); | |
| 88 }; | |
| 89 | |
| 90 } // namespace ppapi | |
| 91 | |
| 92 #endif // PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_ | |
| OLD | NEW |