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

Unified Diff: content/browser/gamepad/gamepad_provider_unittest.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/gamepad/gamepad_provider.cc ('k') | content/common/gamepad_hardware_buffer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/gamepad/gamepad_provider_unittest.cc
===================================================================
--- content/browser/gamepad/gamepad_provider_unittest.cc (revision 146895)
+++ content/browser/gamepad/gamepad_provider_unittest.cc (working copy)
@@ -6,7 +6,6 @@
#include "base/process_util.h"
#include "base/synchronization/waitable_event.h"
#include "base/system_monitor/system_monitor.h"
-#include "base/threading/platform_thread.h"
#include "content/browser/gamepad/data_fetcher.h"
#include "content/browser/gamepad/gamepad_provider.h"
#include "content/common/gamepad_hardware_buffer.h"
@@ -23,14 +22,19 @@
class MockDataFetcher : public GamepadDataFetcher {
public:
explicit MockDataFetcher(const WebGamepads& test_data)
- : test_data_(test_data) {
+ : test_data_(test_data),
+ read_data_(false, false) {
}
virtual void GetGamepadData(WebGamepads* pads,
bool devices_changed_hint) OVERRIDE {
*pads = test_data_;
+ read_data_.Signal();
}
+ void WaitForDataRead() { return read_data_.Wait(); }
+
WebGamepads test_data_;
+ base::WaitableEvent read_data_;
};
// Main test fixture
@@ -73,6 +77,8 @@
main_message_loop_.RunAllPending();
+ mock_data_fetcher_->WaitForDataRead();
+
// Renderer-side, pull data out of poll buffer.
base::SharedMemoryHandle handle =
provider->GetRendererSharedMemoryHandle(base::GetCurrentProcessHandle());
@@ -82,14 +88,15 @@
void* mem = shared_memory->memory();
GamepadHardwareBuffer* hwbuf = static_cast<GamepadHardwareBuffer*>(mem);
+ // See gamepad_hardware_buffer.h for details on the read discipline.
WebGamepads output;
- output.length = 0;
- for (;;) {
- hwbuf->gamepads.ReadTo(&output);
- if (output.length == 1)
- break;
- base::PlatformThread::YieldCurrentThread();
- }
+
+ base::subtle::Atomic32 version;
+ do {
+ version = hwbuf->sequence.ReadBegin();
+ memcpy(&output, &hwbuf->buffer, sizeof(output));
+ } while (hwbuf->sequence.ReadRetry(version));
+
EXPECT_EQ(1u, output.length);
EXPECT_EQ(1u, output.items[0].buttonsLength);
EXPECT_EQ(1.f, output.items[0].buttons[0]);
« no previous file with comments | « content/browser/gamepad/gamepad_provider.cc ('k') | content/common/gamepad_hardware_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698