| 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 CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ | 5 #ifndef CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ |
| 6 #define CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ | 6 #define CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> |
| 11 |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
| 14 #include "content/common/shared_memory_seqlock_buffer.h" | 15 #include "content/common/shared_memory_seqlock_buffer.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 namespace internal { | 18 namespace internal { |
| 18 | 19 |
| 19 class SharedMemorySeqLockReaderBase { | 20 class SharedMemorySeqLockReaderBase { |
| 20 protected: | 21 protected: |
| 21 SharedMemorySeqLockReaderBase(); | 22 SharedMemorySeqLockReaderBase(); |
| 22 virtual ~SharedMemorySeqLockReaderBase(); | 23 virtual ~SharedMemorySeqLockReaderBase(); |
| 23 | 24 |
| 24 void* InitializeSharedMemory( | 25 void* InitializeSharedMemory( |
| 25 base::SharedMemoryHandle shared_memory_handle, | 26 base::SharedMemoryHandle shared_memory_handle, |
| 26 size_t buffer_size); | 27 size_t buffer_size); |
| 27 | 28 |
| 28 bool FetchFromBuffer(content::OneWriterSeqLock* seqlock, void* final, | 29 bool FetchFromBuffer(content::OneWriterSeqLock* seqlock, void* final, |
| 29 void* temp, void* from, size_t size); | 30 void* temp, void* from, size_t size); |
| 30 | 31 |
| 31 static const int kMaximumContentionCount = 10; | 32 static const int kMaximumContentionCount = 10; |
| 32 base::SharedMemoryHandle renderer_shared_memory_handle_; | 33 base::SharedMemoryHandle renderer_shared_memory_handle_; |
| 33 scoped_ptr<base::SharedMemory> renderer_shared_memory_; | 34 std::unique_ptr<base::SharedMemory> renderer_shared_memory_; |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 } // namespace internal | 37 } // namespace internal |
| 37 | 38 |
| 38 // Template argument Data should be a pod-like structure only containing | 39 // Template argument Data should be a pod-like structure only containing |
| 39 // data fields, such that it is copyable by memcpy method. | 40 // data fields, such that it is copyable by memcpy method. |
| 40 template<typename Data> | 41 template<typename Data> |
| 41 class SharedMemorySeqLockReader | 42 class SharedMemorySeqLockReader |
| 42 : private internal::SharedMemorySeqLockReaderBase { | 43 : private internal::SharedMemorySeqLockReaderBase { |
| 43 public: | 44 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 56 shared_memory_handle, sizeof(SharedMemorySeqLockBuffer<Data>))) { | 57 shared_memory_handle, sizeof(SharedMemorySeqLockBuffer<Data>))) { |
| 57 buffer_ = static_cast<SharedMemorySeqLockBuffer<Data>*>(memory); | 58 buffer_ = static_cast<SharedMemorySeqLockBuffer<Data>*>(memory); |
| 58 temp_buffer_.reset(new Data); | 59 temp_buffer_.reset(new Data); |
| 59 return true; | 60 return true; |
| 60 } | 61 } |
| 61 return false; | 62 return false; |
| 62 } | 63 } |
| 63 | 64 |
| 64 private: | 65 private: |
| 65 SharedMemorySeqLockBuffer<Data>* buffer_; | 66 SharedMemorySeqLockBuffer<Data>* buffer_; |
| 66 scoped_ptr<Data> temp_buffer_; | 67 std::unique_ptr<Data> temp_buffer_; |
| 67 | 68 |
| 68 DISALLOW_COPY_AND_ASSIGN(SharedMemorySeqLockReader); | 69 DISALLOW_COPY_AND_ASSIGN(SharedMemorySeqLockReader); |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 } // namespace content | 72 } // namespace content |
| 72 | 73 |
| 73 #endif // CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ | 74 #endif // CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ |
| OLD | NEW |