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

Side by Side Diff: content/browser/gamepad/gamepad_provider.cc

Issue 10785024: Revert 146792 - Lock-free GamepadSeqLock (try 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cmath> 5 #include <cmath>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); 114 DCHECK(MessageLoop::current() == polling_thread_->message_loop());
115 if (data_fetcher_.get()) 115 if (data_fetcher_.get())
116 data_fetcher_->PauseHint(paused); 116 data_fetcher_->PauseHint(paused);
117 } 117 }
118 118
119 void GamepadProvider::DoPoll() { 119 void GamepadProvider::DoPoll() {
120 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); 120 DCHECK(MessageLoop::current() == polling_thread_->message_loop());
121 bool changed; 121 bool changed;
122 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); 122 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer();
123 123
124 ANNOTATE_BENIGN_RACE_SIZED(
125 &hwbuf->buffer,
126 sizeof(WebKit::WebGamepads),
127 "Racey reads are discarded");
128
124 { 129 {
125 base::AutoLock lock(devices_changed_lock_); 130 base::AutoLock lock(devices_changed_lock_);
126 changed = devices_changed_; 131 changed = devices_changed_;
127 devices_changed_ = false; 132 devices_changed_ = false;
128 } 133 }
129 134
130 // Acquire the SeqLock. There is only ever one writer to this data. 135 // Acquire the SeqLock. There is only ever one writer to this data.
131 // See gamepad_hardware_buffer.h. 136 // See gamepad_hardware_buffer.h.
132 WebKit::WebGamepads tmp; 137 hwbuf->sequence.WriteBegin();
133 data_fetcher_->GetGamepadData(&tmp, changed); 138 data_fetcher_->GetGamepadData(&hwbuf->buffer, changed);
134 hwbuf->gamepads.Write(tmp); 139 hwbuf->sequence.WriteEnd();
135 140
136 // Schedule our next interval of polling. 141 // Schedule our next interval of polling.
137 ScheduleDoPoll(); 142 ScheduleDoPoll();
138 } 143 }
139 144
140 void GamepadProvider::ScheduleDoPoll() { 145 void GamepadProvider::ScheduleDoPoll() {
141 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); 146 DCHECK(MessageLoop::current() == polling_thread_->message_loop());
142 147
143 { 148 {
144 base::AutoLock lock(is_paused_lock_); 149 base::AutoLock lock(is_paused_lock_);
145 if (is_paused_) 150 if (is_paused_)
146 return; 151 return;
147 } 152 }
148 153
149 MessageLoop::current()->PostDelayedTask( 154 MessageLoop::current()->PostDelayedTask(
150 FROM_HERE, 155 FROM_HERE,
151 base::Bind(&GamepadProvider::DoPoll, Unretained(this)), 156 base::Bind(&GamepadProvider::DoPoll, Unretained(this)),
152 base::TimeDelta::FromMilliseconds(kDesiredSamplingIntervalMs)); 157 base::TimeDelta::FromMilliseconds(kDesiredSamplingIntervalMs));
153 } 158 }
154 159
155 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { 160 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() {
156 void* mem = gamepad_shared_memory_.memory(); 161 void* mem = gamepad_shared_memory_.memory();
157 CHECK(mem); 162 CHECK(mem);
158 return static_cast<GamepadHardwareBuffer*>(mem); 163 return static_cast<GamepadHardwareBuffer*>(mem);
159 } 164 }
160 165
161 } // namespace content 166 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698