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

Unified Diff: content/renderer/shared_memory_seqlock_reader.h

Issue 14678012: Implement the content/renderer and content/browser part of the Device Motion API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: factored out as much code as possible from the templated reader Created 7 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/shared_memory_seqlock_reader.h
diff --git a/content/renderer/shared_memory_seqlock_reader.h b/content/renderer/shared_memory_seqlock_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..9b268e3db00331a93b80c15aaff87547d0edd0d4
--- /dev/null
+++ b/content/renderer/shared_memory_seqlock_reader.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_
+#define CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_
+
+#include "shared_memory_seqlock_reader_base.h"
+
+namespace content {
+
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.
+// Template argument Data should be a pod-like structure only containing
+// data fields, such that it is copyable by memcpy method.
+template<typename Data>
+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
+ public:
+ SharedMemorySeqLockReader() : buffer_(0) { }
+ virtual ~SharedMemorySeqLockReader() { }
+
+ bool GetLatestData(Data* data) {
+ DCHECK(buffer_);
+ DCHECK(sizeof(*data) == sizeof(*temp_buffer_));
+ return FetchFromBuffer(data, temp_buffer_.get(), &buffer_->data,
+ sizeof(*temp_buffer_));
+ }
+
+ bool Initialize(base::SharedMemoryHandle shared_memory_handle) {
+ SharedMemorySeqLockBufferBase* memory = InitializeSharedMemory(
+ shared_memory_handle, sizeof(SharedMemorySeqLockBuffer<Data>));
+ if (memory) {
+ buffer_ = static_cast<SharedMemorySeqLockBuffer<Data>*>(memory);
+ temp_buffer_.reset(new Data);
+ return true;
+ }
+ return false;
+ }
+
+ private:
+ SharedMemorySeqLockBuffer<Data>* buffer_;
+ scoped_ptr<Data> temp_buffer_;
+
+ DISALLOW_COPY_AND_ASSIGN(SharedMemorySeqLockReader);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_SHARED_MEMORY_SEQLOCK_READER_H_

Powered by Google App Engine
This is Rietveld 408576698