Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ | |
| 6 #define CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ | |
| 7 | |
| 8 #include "shared_memory_seqlock_reader_base.h" | |
| 9 | |
| 10 namespace content { | |
| 11 | |
|
darin (slow to review)
2013/06/24 23:40:34
nit: it is common to put the *Base class here insi
timvolodine
2013/06/25 03:36:07
Done.
| |
| 12 // Template argument Data should be a pod-like structure only containing | |
| 13 // data fields, such that it is copyable by memcpy method. | |
| 14 template<typename Data> | |
| 15 class SharedMemorySeqLockReader : private SharedMemorySeqLockReaderBase { | |
|
scottmg
2013/06/24 23:24:38
was the intention that this be the generic reader?
timvolodine
2013/06/25 03:36:07
The new reader class largely implements the origin
| |
| 16 public: | |
| 17 SharedMemorySeqLockReader() : buffer_(0) { } | |
| 18 virtual ~SharedMemorySeqLockReader() { } | |
| 19 | |
| 20 bool GetLatestData(Data* data) { | |
| 21 DCHECK(buffer_); | |
| 22 DCHECK(sizeof(*data) == sizeof(*temp_buffer_)); | |
| 23 return FetchFromBuffer(data, temp_buffer_.get(), &buffer_->data, | |
| 24 sizeof(*temp_buffer_)); | |
| 25 } | |
| 26 | |
| 27 bool Initialize(base::SharedMemoryHandle shared_memory_handle) { | |
| 28 SharedMemorySeqLockBufferBase* memory = InitializeSharedMemory( | |
| 29 shared_memory_handle, sizeof(SharedMemorySeqLockBuffer<Data>)); | |
| 30 if (memory) { | |
| 31 buffer_ = static_cast<SharedMemorySeqLockBuffer<Data>*>(memory); | |
| 32 temp_buffer_.reset(new Data); | |
| 33 return true; | |
| 34 } | |
| 35 return false; | |
| 36 } | |
| 37 | |
| 38 private: | |
| 39 SharedMemorySeqLockBuffer<Data>* buffer_; | |
| 40 scoped_ptr<Data> temp_buffer_; | |
| 41 | |
| 42 DISALLOW_COPY_AND_ASSIGN(SharedMemorySeqLockReader); | |
| 43 }; | |
| 44 | |
| 45 } // namespace content | |
| 46 | |
| 47 #endif // CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ | |
| OLD | NEW |