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

Side by Side Diff: device/sensors/public/cpp/shared_memory_seqlock_reader.h

Issue 2819273006: Move //device/sensor impl to be part of the internal implemenation of the Device Service. (Closed)
Patch Set: Move //device/sensor impl to be part of the internal implemenation of the Device Service Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef DEVICE_SENSORS_PUBLIC_CPP_SHARED_MEMORY_SEQLOCK_READER_H_
6 #define DEVICE_SENSORS_PUBLIC_CPP_SHARED_MEMORY_SEQLOCK_READER_H_
7
8 #include <stddef.h>
9
10 #include <memory>
11
12 #include "base/macros.h"
13 #include "base/memory/shared_memory.h"
14 #include "device/base/synchronization/shared_memory_seqlock_buffer.h"
15
16 namespace device {
17 namespace internal {
18
19 class SharedMemorySeqLockReaderBase {
20 protected:
21 SharedMemorySeqLockReaderBase();
22 virtual ~SharedMemorySeqLockReaderBase();
23
24 void* InitializeSharedMemory(base::SharedMemoryHandle shared_memory_handle,
25 size_t buffer_size);
26
27 bool FetchFromBuffer(device::OneWriterSeqLock* seqlock,
28 void* final,
29 void* temp,
30 void* from,
31 size_t size);
32
33 static const int kMaximumContentionCount = 10;
34 base::SharedMemoryHandle renderer_shared_memory_handle_;
35 std::unique_ptr<base::SharedMemory> renderer_shared_memory_;
36 };
37
38 } // namespace internal
39
40 // Template argument Data should be a pod-like structure only containing
41 // data fields, such that it is copyable by memcpy method.
42 template <typename Data>
43 class SharedMemorySeqLockReader
44 : private internal::SharedMemorySeqLockReaderBase {
45 public:
46 SharedMemorySeqLockReader() : buffer_(0) {}
47 virtual ~SharedMemorySeqLockReader() {}
48
49 bool GetLatestData(Data* data) {
50 DCHECK(buffer_);
51 DCHECK(sizeof(*data) == sizeof(*temp_buffer_));
52 return FetchFromBuffer(&buffer_->seqlock, data, temp_buffer_.get(),
53 &buffer_->data, sizeof(*temp_buffer_));
54 }
55
56 bool Initialize(base::SharedMemoryHandle shared_memory_handle) {
57 if (void* memory = InitializeSharedMemory(
58 shared_memory_handle,
59 sizeof(device::SharedMemorySeqLockBuffer<Data>))) {
60 buffer_ = static_cast<device::SharedMemorySeqLockBuffer<Data>*>(memory);
61 temp_buffer_.reset(new Data);
62 return true;
63 }
64 return false;
65 }
66
67 private:
68 device::SharedMemorySeqLockBuffer<Data>* buffer_;
69 std::unique_ptr<Data> temp_buffer_;
70
71 DISALLOW_COPY_AND_ASSIGN(SharedMemorySeqLockReader);
72 };
73
74 } // namespace device
75
76 #endif // DEVICE_SENSORS_PUBLIC_CPP_SHARED_MEMORY_SEQLOCK_READER_H_
OLDNEW
« no previous file with comments | « device/sensors/public/cpp/orientation_data.cc ('k') | device/sensors/public/cpp/shared_memory_seqlock_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698