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

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 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 data_fetcher_.swap(provided_fetcher_); 111 data_fetcher_.swap(provided_fetcher_);
112 112
113 // Start polling. 113 // Start polling.
114 ScheduleDoPoll(); 114 ScheduleDoPoll();
115 } 115 }
116 116
117 void GamepadProvider::DoPoll() { 117 void GamepadProvider::DoPoll() {
118 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); 118 DCHECK(MessageLoop::current() == polling_thread_->message_loop());
119 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); 119 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer();
120 120
121 ANNOTATE_BENIGN_RACE_SIZED( 121 WebKit::WebGamepads tmp;
122 &hwbuf->buffer, 122 data_fetcher_->GetGamepadData(&tmp, devices_changed_);
123 sizeof(WebKit::WebGamepads), 123 hwbuf->gamepads.Write(tmp);
124 "Racey reads are discarded");
125
126 // Acquire the SeqLock. There is only ever one writer to this data.
127 // See gamepad_hardware_buffer.h.
128 hwbuf->sequence.WriteBegin();
129 data_fetcher_->GetGamepadData(&hwbuf->buffer, devices_changed_);
130 hwbuf->sequence.WriteEnd();
131 devices_changed_ = false; 124 devices_changed_ = false;
132 // Schedule our next interval of polling. 125 // Schedule our next interval of polling.
133 ScheduleDoPoll(); 126 ScheduleDoPoll();
134 } 127 }
135 128
136 void GamepadProvider::ScheduleDoPoll() { 129 void GamepadProvider::ScheduleDoPoll() {
137 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); 130 DCHECK(MessageLoop::current() == polling_thread_->message_loop());
138 131
139 MessageLoop::current()->PostDelayedTask( 132 MessageLoop::current()->PostDelayedTask(
140 FROM_HERE, 133 FROM_HERE,
141 base::Bind(&GamepadProvider::DoPoll, weak_factory_.GetWeakPtr()), 134 base::Bind(&GamepadProvider::DoPoll, weak_factory_.GetWeakPtr()),
142 kDesiredSamplingIntervalMs); 135 kDesiredSamplingIntervalMs);
143 } 136 }
144 137
145 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { 138 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() {
146 void* mem = gamepad_shared_memory_.memory(); 139 void* mem = gamepad_shared_memory_.memory();
147 DCHECK(mem); 140 DCHECK(mem);
148 return static_cast<GamepadHardwareBuffer*>(mem); 141 return static_cast<GamepadHardwareBuffer*>(mem);
149 } 142 }
150 143
151 } // namespace content 144 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_provider_unittest.cc » ('j') | content/common/gamepad_seqlock.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698