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

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

Issue 2812223006: Replace device_sensor browsertest by service unittest. (Closed)
Patch Set: eliminate "unreachable code" warning. 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
« no previous file with comments | « content/renderer/shared_memory_seqlock_reader.h ('k') | content/test/BUILD.gn » ('j') | 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 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 "content/renderer/shared_memory_seqlock_reader.h"
6
7 namespace content {
8 namespace internal {
9
10 SharedMemorySeqLockReaderBase::SharedMemorySeqLockReaderBase() { }
11
12 SharedMemorySeqLockReaderBase::~SharedMemorySeqLockReaderBase() { }
13
14 void*
15 SharedMemorySeqLockReaderBase::InitializeSharedMemory(
16 base::SharedMemoryHandle shared_memory_handle, size_t buffer_size) {
17 renderer_shared_memory_handle_ = shared_memory_handle;
18 if (!base::SharedMemory::IsHandleValid(renderer_shared_memory_handle_))
19 return 0;
20 renderer_shared_memory_.reset(new base::SharedMemory(
21 renderer_shared_memory_handle_, true));
22
23 return (renderer_shared_memory_->Map(buffer_size))
24 ? renderer_shared_memory_->memory()
25 : 0;
26 }
27
28 bool SharedMemorySeqLockReaderBase::FetchFromBuffer(
29 device::OneWriterSeqLock* seqlock,
30 void* final,
31 void* temp,
32 void* from,
33 size_t size) {
34 if (!base::SharedMemory::IsHandleValid(renderer_shared_memory_handle_))
35 return false;
36
37 // Only try to read this many times before failing to avoid waiting here
38 // very long in case of contention with the writer.
39 int contention_count = -1;
40 base::subtle::Atomic32 version;
41 do {
42 version = seqlock->ReadBegin();
43 memcpy(temp, from, size);
44 ++contention_count;
45 if (contention_count == kMaximumContentionCount)
46 break;
47 } while (seqlock->ReadRetry(version));
48
49 if (contention_count >= kMaximumContentionCount) {
50 // We failed to successfully read, presumably because the hardware
51 // thread was taking unusually long. Don't copy the data to the output
52 // buffer, and simply leave what was there before.
53 return false;
54 }
55
56 // New data was read successfully, copy it into the output buffer.
57 memcpy(final, temp, size);
58 return true;
59 }
60
61 } // namespace internal
62 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/shared_memory_seqlock_reader.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698