Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: components/shared_memory_seqlock/shared_memory_seqlock_reader.h

Issue 1164563003: Extract device_sensors to /device via Mojofication (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 COMPONENTS_SHARED_MEMORY_SEQLOCK_SHARED_MEMORY_SEQLOCK_READER_H_
6 #define CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ 6 #define COMPONENTS_SHARED_MEMORY_SEQLOCK_SHARED_MEMORY_SEQLOCK_READER_H_
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
11 #include "content/common/shared_memory_seqlock_buffer.h" 11 #include "components/shared_memory_seqlock/shared_memory_seqlock_buffer.h"
12 12
13 namespace content { 13 namespace shared_memory_seqlock {
14 namespace internal { 14 namespace internal {
15 15
16 class SharedMemorySeqLockReaderBase { 16 class SharedMemorySeqLockReaderBase {
17 protected: 17 protected:
18 SharedMemorySeqLockReaderBase(); 18 SharedMemorySeqLockReaderBase();
19 virtual ~SharedMemorySeqLockReaderBase(); 19 virtual ~SharedMemorySeqLockReaderBase();
20 20
21 void* InitializeSharedMemory( 21 void* InitializeSharedMemory(base::SharedMemoryHandle shared_memory_handle,
22 base::SharedMemoryHandle shared_memory_handle, 22 size_t buffer_size);
23 size_t buffer_size);
24 23
25 bool FetchFromBuffer(content::OneWriterSeqLock* seqlock, void* final, 24 bool FetchFromBuffer(shared_memory_seqlock::OneWriterSeqLock* seqlock,
26 void* temp, void* from, size_t size); 25 void* final,
26 void* temp,
27 void* from,
28 size_t size);
27 29
28 static const int kMaximumContentionCount = 10; 30 static const int kMaximumContentionCount = 10;
29 base::SharedMemoryHandle renderer_shared_memory_handle_; 31 base::SharedMemoryHandle renderer_shared_memory_handle_;
30 scoped_ptr<base::SharedMemory> renderer_shared_memory_; 32 scoped_ptr<base::SharedMemory> renderer_shared_memory_;
31 }; 33 };
32 34
33 } // namespace internal 35 } // namespace internal
34 36
35 // Template argument Data should be a pod-like structure only containing 37 // Template argument Data should be a pod-like structure only containing
36 // data fields, such that it is copyable by memcpy method. 38 // data fields, such that it is copyable by memcpy method.
37 template<typename Data> 39 template <typename Data>
38 class SharedMemorySeqLockReader 40 class SharedMemorySeqLockReader
39 : private internal::SharedMemorySeqLockReaderBase { 41 : private internal::SharedMemorySeqLockReaderBase {
40 public: 42 public:
41 SharedMemorySeqLockReader() : buffer_(0) { } 43 SharedMemorySeqLockReader() : buffer_(0) {}
42 virtual ~SharedMemorySeqLockReader() { } 44 virtual ~SharedMemorySeqLockReader() {}
43 45
44 bool GetLatestData(Data* data) { 46 bool GetLatestData(Data* data) {
45 DCHECK(buffer_); 47 DCHECK(buffer_);
46 DCHECK(sizeof(*data) == sizeof(*temp_buffer_)); 48 DCHECK(sizeof(*data) == sizeof(*temp_buffer_));
47 return FetchFromBuffer(&buffer_->seqlock, data, temp_buffer_.get(), 49 return FetchFromBuffer(&buffer_->seqlock, data, temp_buffer_.get(),
48 &buffer_->data, sizeof(*temp_buffer_)); 50 &buffer_->data, sizeof(*temp_buffer_));
49 } 51 }
50 52
51 bool Initialize(base::SharedMemoryHandle shared_memory_handle) { 53 bool Initialize(base::SharedMemoryHandle shared_memory_handle) {
52 if (void* memory = InitializeSharedMemory( 54 if (void* memory = InitializeSharedMemory(
53 shared_memory_handle, sizeof(SharedMemorySeqLockBuffer<Data>))) { 55 shared_memory_handle, sizeof(SharedMemorySeqLockBuffer<Data>))) {
54 buffer_ = static_cast<SharedMemorySeqLockBuffer<Data>*>(memory); 56 buffer_ = static_cast<SharedMemorySeqLockBuffer<Data>*>(memory);
55 temp_buffer_.reset(new Data); 57 temp_buffer_.reset(new Data);
56 return true; 58 return true;
57 } 59 }
58 return false; 60 return false;
59 } 61 }
60 62
61 private: 63 private:
62 SharedMemorySeqLockBuffer<Data>* buffer_; 64 SharedMemorySeqLockBuffer<Data>* buffer_;
63 scoped_ptr<Data> temp_buffer_; 65 scoped_ptr<Data> temp_buffer_;
64 66
65 DISALLOW_COPY_AND_ASSIGN(SharedMemorySeqLockReader); 67 DISALLOW_COPY_AND_ASSIGN(SharedMemorySeqLockReader);
66 }; 68 };
67 69
68 } // namespace content 70 } // namespace shared_memory_seqlock
69 71
70 #endif // CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_ 72 #endif // COMPONENTS_SHARED_MEMORY_SEQLOCK_SHARED_MEMORY_SEQLOCK_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698