diff options
author | glider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-25 15:51:30 +0000 |
---|---|---|
committer | glider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-25 15:51:30 +0000 |
commit | 4dd8c3e74a97deb3edf31f1ddf1195ea0ca27295 (patch) | |
tree | c432fab0ee34d85cab5766fd21f285969648c0be /content/renderer/gamepad_shared_memory_reader.cc | |
parent | 26eddafcdc87ef012c77f6ec4edecdef6f900f74 (diff) | |
download | chromium_src-4dd8c3e74a97deb3edf31f1ddf1195ea0ca27295.zip chromium_src-4dd8c3e74a97deb3edf31f1ddf1195ea0ca27295.tar.gz chromium_src-4dd8c3e74a97deb3edf31f1ddf1195ea0ca27295.tar.bz2 |
Revert 143903 - Lock-free GamepadSeqLock
The change
- provides an improved lock-free SeqLock implementation which eliminates any potential blocking of readers.
- provides a higher-level and simpler API as was suggested by Darin.
- ThreadSanitizer report suppressions are replaced with correct synchronization.
- eliminates nasty kMaximumContentionCount and associated histogram.
Review URL: https://chromiumcodereview.appspot.com/8772004
TBR=dvyukov@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10656020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/gamepad_shared_memory_reader.cc')
-rw-r--r-- | content/renderer/gamepad_shared_memory_reader.cc | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/content/renderer/gamepad_shared_memory_reader.cc b/content/renderer/gamepad_shared_memory_reader.cc index 0d249a7..55c6f62 100644 --- a/content/renderer/gamepad_shared_memory_reader.cc +++ b/content/renderer/gamepad_shared_memory_reader.cc @@ -41,7 +41,31 @@ void GamepadSharedMemoryReader::SampleGamepads(WebKit::WebGamepads& gamepads) { if (!base::SharedMemory::IsHandleValid(renderer_shared_memory_handle_)) return; - gamepad_hardware_buffer_->gamepads.ReadTo(&gamepads); + // Only try to read this many times before failing to avoid waiting here + // very long in case of contention with the writer. TODO(scottmg) Tune this + // number (as low as 1?) if histogram shows distribution as mostly + // 0-and-maximum. + const int kMaximumContentionCount = 10; + int contention_count = -1; + base::subtle::Atomic32 version; + do { + version = gamepad_hardware_buffer_->sequence.ReadBegin(); + memcpy(&read_into, &gamepad_hardware_buffer_->buffer, sizeof(read_into)); + ++contention_count; + if (contention_count == kMaximumContentionCount) + break; + } while (gamepad_hardware_buffer_->sequence.ReadRetry(version)); + UMA_HISTOGRAM_COUNTS("Gamepad.ReadContentionCount", contention_count); + + if (contention_count >= kMaximumContentionCount) { + // We failed to successfully read, presumably because the hardware + // thread was taking unusually long. Don't copy the data to the output + // buffer, and simply leave what was there before. + return; + } + + // New data was read successfully, copy it into the output buffer. + memcpy(&gamepads, &read_into, sizeof(gamepads)); // Override the "connected" with false until the user has interacted // with the gamepad. This is to prevent fingerprinting on drive-by pages. |