| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_IMPL_H_ |
| 6 #define MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_H_ | 6 #define MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/aligned_memory.h" | 9 #include "base/memory/aligned_memory.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "mojo/edk/system/data_pipe.h" | 12 #include "mojo/edk/system/data_pipe.h" |
| 13 #include "mojo/edk/system/system_impl_export.h" | 13 #include "mojo/edk/system/system_impl_export.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 namespace system { | 16 namespace system { |
| 17 | 17 |
| 18 // |LocalDataPipe| is a subclass that "implements" |DataPipe| for data pipes | 18 // |LocalDataPipeImpl| is a subclass that "implements" |DataPipe| for data pipes |
| 19 // whose producer and consumer are both local. This class is thread-safe (with | 19 // whose producer and consumer are both local. This class is thread-safe (with |
| 20 // protection provided by |DataPipe|'s |lock_|. | 20 // protection provided by |DataPipe|'s |lock_|. |
| 21 class MOJO_SYSTEM_IMPL_EXPORT LocalDataPipe : public DataPipe { | 21 class MOJO_SYSTEM_IMPL_EXPORT LocalDataPipeImpl : public DataPipe { |
| 22 public: | 22 public: |
| 23 // |validated_options| should be the output of |DataPipe::ValidateOptions()|. | 23 // |validated_options| should be the output of |DataPipe::ValidateOptions()|. |
| 24 // In particular: |struct_size| is ignored (so |validated_options| must be the | 24 // In particular: |struct_size| is ignored (so |validated_options| must be the |
| 25 // current version of the struct) and |capacity_num_bytes| must be nonzero. | 25 // current version of the struct) and |capacity_num_bytes| must be nonzero. |
| 26 explicit LocalDataPipe(const MojoCreateDataPipeOptions& validated_options); | 26 explicit LocalDataPipeImpl( |
| 27 const MojoCreateDataPipeOptions& validated_options); |
| 27 | 28 |
| 28 private: | 29 private: |
| 29 friend class base::RefCountedThreadSafe<LocalDataPipe>; | 30 friend class base::RefCountedThreadSafe<LocalDataPipeImpl>; |
| 30 ~LocalDataPipe() override; | 31 ~LocalDataPipeImpl() override; |
| 31 | 32 |
| 32 // |DataPipe| implementation: | 33 // |DataPipe| implementation: |
| 33 void ProducerCloseImplNoLock() override; | 34 void ProducerCloseImplNoLock() override; |
| 34 MojoResult ProducerWriteDataImplNoLock( | 35 MojoResult ProducerWriteDataImplNoLock( |
| 35 UserPointer<const void> elements, | 36 UserPointer<const void> elements, |
| 36 UserPointer<uint32_t> num_bytes, | 37 UserPointer<uint32_t> num_bytes, |
| 37 uint32_t max_num_bytes_to_write, | 38 uint32_t max_num_bytes_to_write, |
| 38 uint32_t min_num_bytes_to_write) override; | 39 uint32_t min_num_bytes_to_write) override; |
| 39 MojoResult ProducerBeginWriteDataImplNoLock( | 40 MojoResult ProducerBeginWriteDataImplNoLock( |
| 40 UserPointer<void*> buffer, | 41 UserPointer<void*> buffer, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // Marks the given number of bytes as consumed/discarded. |num_bytes| must be | 90 // Marks the given number of bytes as consumed/discarded. |num_bytes| must be |
| 90 // greater than |current_num_bytes_|. | 91 // greater than |current_num_bytes_|. |
| 91 void MarkDataAsConsumedNoLock(size_t num_bytes); | 92 void MarkDataAsConsumedNoLock(size_t num_bytes); |
| 92 | 93 |
| 93 // The members below are protected by |DataPipe|'s |lock_|: | 94 // The members below are protected by |DataPipe|'s |lock_|: |
| 94 scoped_ptr<char, base::AlignedFreeDeleter> buffer_; | 95 scoped_ptr<char, base::AlignedFreeDeleter> buffer_; |
| 95 // Circular buffer. | 96 // Circular buffer. |
| 96 size_t start_index_; | 97 size_t start_index_; |
| 97 size_t current_num_bytes_; | 98 size_t current_num_bytes_; |
| 98 | 99 |
| 99 DISALLOW_COPY_AND_ASSIGN(LocalDataPipe); | 100 DISALLOW_COPY_AND_ASSIGN(LocalDataPipeImpl); |
| 100 }; | 101 }; |
| 101 | 102 |
| 102 } // namespace system | 103 } // namespace system |
| 103 } // namespace mojo | 104 } // namespace mojo |
| 104 | 105 |
| 105 #endif // MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_H_ | 106 #endif // MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_IMPL_H_ |
| OLD | NEW |