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

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

Issue 8772004: Improve GamepadSeqLock impl Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 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 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
129 { 124 {
130 base::AutoLock lock(devices_changed_lock_); 125 base::AutoLock lock(devices_changed_lock_);
131 changed = devices_changed_; 126 changed = devices_changed_;
132 devices_changed_ = false; 127 devices_changed_ = false;
133 } 128 }
134 129
135 // Acquire the SeqLock. There is only ever one writer to this data. 130 // Acquire the SeqLock. There is only ever one writer to this data.
136 // See gamepad_hardware_buffer.h. 131 // See gamepad_hardware_buffer.h.
137 hwbuf->sequence.WriteBegin(); 132 WebKit::WebGamepads tmp;
138 data_fetcher_->GetGamepadData(&hwbuf->buffer, changed); 133 data_fetcher_->GetGamepadData(&tmp, changed);
139 hwbuf->sequence.WriteEnd(); 134 hwbuf->gamepads.Write(tmp);
140 135
141 // Schedule our next interval of polling. 136 // Schedule our next interval of polling.
142 ScheduleDoPoll(); 137 ScheduleDoPoll();
143 } 138 }
144 139
145 void GamepadProvider::ScheduleDoPoll() { 140 void GamepadProvider::ScheduleDoPoll() {
146 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); 141 DCHECK(MessageLoop::current() == polling_thread_->message_loop());
147 142
148 { 143 {
149 base::AutoLock lock(is_paused_lock_); 144 base::AutoLock lock(is_paused_lock_);
150 if (is_paused_) 145 if (is_paused_)
151 return; 146 return;
152 } 147 }
153 148
154 MessageLoop::current()->PostDelayedTask( 149 MessageLoop::current()->PostDelayedTask(
155 FROM_HERE, 150 FROM_HERE,
156 base::Bind(&GamepadProvider::DoPoll, Unretained(this)), 151 base::Bind(&GamepadProvider::DoPoll, Unretained(this)),
157 base::TimeDelta::FromMilliseconds(kDesiredSamplingIntervalMs)); 152 base::TimeDelta::FromMilliseconds(kDesiredSamplingIntervalMs));
158 } 153 }
159 154
160 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { 155 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() {
161 void* mem = gamepad_shared_memory_.memory(); 156 void* mem = gamepad_shared_memory_.memory();
162 CHECK(mem); 157 CHECK(mem);
163 return static_cast<GamepadHardwareBuffer*>(mem); 158 return static_cast<GamepadHardwareBuffer*>(mem);
164 } 159 }
165 160
166 } // namespace content 161 } // 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