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

Side by Side Diff: content/renderer/shared_memory_seqlock_reader.cc

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: fix compilation: peer_handle -> PeerHandle() Created 7 years, 5 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
« no previous file with comments | « content/renderer/shared_memory_seqlock_reader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "shared_memory_seqlock_reader.h"
6
7 namespace internal {
8
9 SharedMemorySeqLockReaderBase::SharedMemorySeqLockReaderBase() { }
10
11 SharedMemorySeqLockReaderBase::~SharedMemorySeqLockReaderBase() { }
12
13 void*
14 SharedMemorySeqLockReaderBase::InitializeSharedMemory(
15 base::SharedMemoryHandle shared_memory_handle, size_t buffer_size) {
16 renderer_shared_memory_handle_ = shared_memory_handle;
17 if (!base::SharedMemory::IsHandleValid(renderer_shared_memory_handle_))
18 return 0;
19 renderer_shared_memory_.reset(new base::SharedMemory(
20 renderer_shared_memory_handle_, true));
21
22 return (renderer_shared_memory_->Map(buffer_size))
23 ? renderer_shared_memory_->memory()
24 : 0;
25 }
26
27 bool SharedMemorySeqLockReaderBase::FetchFromBuffer(
28 content::OneWriterSeqLock* seqlock, void* final, void* temp, void* from,
29 size_t size) {
30
31 if (!base::SharedMemory::IsHandleValid(renderer_shared_memory_handle_))
32 return false;
33
34 // Only try to read this many times before failing to avoid waiting here
35 // very long in case of contention with the writer.
36 int contention_count = -1;
37 base::subtle::Atomic32 version;
38 do {
39 version = seqlock->ReadBegin();
40 memcpy(temp, from, size);
41 ++contention_count;
42 if (contention_count == kMaximumContentionCount)
43 break;
44 } while (seqlock->ReadRetry(version));
45
46 if (contention_count >= kMaximumContentionCount) {
47 // We failed to successfully read, presumably because the hardware
48 // thread was taking unusually long. Don't copy the data to the output
49 // buffer, and simply leave what was there before.
50 return false;
51 }
52
53 // New data was read successfully, copy it into the output buffer.
54 memcpy(final, temp, size);
55 return true;
56 }
57
58 } // namespace internal
OLDNEW
« no previous file with comments | « content/renderer/shared_memory_seqlock_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698