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

Side by Side Diff: content/common/gamepad_seqlock.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/common/gamepad_seqlock.h ('k') | content/common/one_writer_seqlock.h » ('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 (c) 2011 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/common/gamepad_seqlock.h"
6
7 namespace content {
8
9 GamepadSeqLock::GamepadSeqLock()
10 : sequence_(0) {
11 }
12
13 base::subtle::Atomic32 GamepadSeqLock::ReadBegin() {
14 base::subtle::Atomic32 version;
15 for (;;) {
16 version = base::subtle::NoBarrier_Load(&sequence_);
17
18 // If the counter is even, then the associated data might be in a
19 // consistent state, so we can try to read.
20 if ((version & 1) == 0)
21 break;
22
23 // Otherwise, the writer is in the middle of an update. Retry the read.
24 base::PlatformThread::YieldCurrentThread();
25 }
26 return version;
27 }
28
29 bool GamepadSeqLock::ReadRetry(base::subtle::Atomic32 version) {
30 // If the sequence number was updated then a read should be re-attempted.
31 // -- Load fence, read membarrier
32 return base::subtle::Release_Load(&sequence_) != version;
33 }
34
35 void GamepadSeqLock::WriteBegin() {
36 // Increment the sequence number to odd to indicate the beginning of a write
37 // update.
38 base::subtle::Barrier_AtomicIncrement(&sequence_, 1);
39 // -- Store fence, write membarrier
40 }
41
42 void GamepadSeqLock::WriteEnd() {
43 // Increment the sequence to an even number to indicate the completion of
44 // a write update.
45 // -- Store fence, write membarrier
46 base::subtle::Barrier_AtomicIncrement(&sequence_, 1);
47 }
48
49 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gamepad_seqlock.h ('k') | content/common/one_writer_seqlock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698