| OLD | NEW |
| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 100 |
| 101 // Start polling. | 101 // Start polling. |
| 102 ScheduleDoPoll(); | 102 ScheduleDoPoll(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void GamepadProvider::DoPoll() { | 105 void GamepadProvider::DoPoll() { |
| 106 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); | 106 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); |
| 107 bool changed; | 107 bool changed; |
| 108 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); | 108 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); |
| 109 | 109 |
| 110 ANNOTATE_BENIGN_RACE_SIZED( | |
| 111 &hwbuf->buffer, | |
| 112 sizeof(WebKit::WebGamepads), | |
| 113 "Racey reads are discarded"); | |
| 114 | |
| 115 { | 110 { |
| 116 base::AutoLock lock(devices_changed_lock_); | 111 base::AutoLock lock(devices_changed_lock_); |
| 117 changed = devices_changed_; | 112 changed = devices_changed_; |
| 118 devices_changed_ = false; | 113 devices_changed_ = false; |
| 119 } | 114 } |
| 120 | 115 |
| 121 // Acquire the SeqLock. There is only ever one writer to this data. | 116 // Acquire the SeqLock. There is only ever one writer to this data. |
| 122 // See gamepad_hardware_buffer.h. | 117 // See gamepad_hardware_buffer.h. |
| 123 hwbuf->sequence.WriteBegin(); | 118 WebKit::WebGamepads tmp; |
| 124 data_fetcher_->GetGamepadData(&hwbuf->buffer, changed); | 119 data_fetcher_->GetGamepadData(&tmp, changed); |
| 125 hwbuf->sequence.WriteEnd(); | 120 hwbuf->gamepads.Write(tmp); |
| 126 | 121 |
| 127 // Schedule our next interval of polling. | 122 // Schedule our next interval of polling. |
| 128 ScheduleDoPoll(); | 123 ScheduleDoPoll(); |
| 129 } | 124 } |
| 130 | 125 |
| 131 void GamepadProvider::ScheduleDoPoll() { | 126 void GamepadProvider::ScheduleDoPoll() { |
| 132 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); | 127 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); |
| 133 | 128 |
| 134 { | 129 { |
| 135 base::AutoLock lock(is_paused_lock_); | 130 base::AutoLock lock(is_paused_lock_); |
| 136 if (is_paused_) | 131 if (is_paused_) |
| 137 return; | 132 return; |
| 138 } | 133 } |
| 139 | 134 |
| 140 MessageLoop::current()->PostDelayedTask( | 135 MessageLoop::current()->PostDelayedTask( |
| 141 FROM_HERE, | 136 FROM_HERE, |
| 142 base::Bind(&GamepadProvider::DoPoll, weak_factory_.GetWeakPtr()), | 137 base::Bind(&GamepadProvider::DoPoll, weak_factory_.GetWeakPtr()), |
| 143 kDesiredSamplingIntervalMs); | 138 kDesiredSamplingIntervalMs); |
| 144 } | 139 } |
| 145 | 140 |
| 146 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { | 141 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { |
| 147 void* mem = gamepad_shared_memory_.memory(); | 142 void* mem = gamepad_shared_memory_.memory(); |
| 148 DCHECK(mem); | 143 DCHECK(mem); |
| 149 return static_cast<GamepadHardwareBuffer*>(mem); | 144 return static_cast<GamepadHardwareBuffer*>(mem); |
| 150 } | 145 } |
| 151 | 146 |
| 152 } // namespace content | 147 } // namespace content |
| OLD | NEW |