| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/edk/system/dispatcher.h" | 5 #include "mojo/edk/system/dispatcher.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/threading/simple_thread.h" | |
| 13 #include "mojo/edk/embedder/platform_shared_buffer.h" | 12 #include "mojo/edk/embedder/platform_shared_buffer.h" |
| 14 #include "mojo/edk/system/memory.h" | 13 #include "mojo/edk/system/memory.h" |
| 15 #include "mojo/edk/system/waiter.h" | 14 #include "mojo/edk/system/waiter.h" |
| 15 #include "mojo/edk/test/simple_test_thread.h" |
| 16 #include "mojo/public/cpp/system/macros.h" | 16 #include "mojo/public/cpp/system/macros.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace mojo { | 19 namespace mojo { |
| 20 namespace system { | 20 namespace system { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Trivial subclass that makes the constructor public. | 23 // Trivial subclass that makes the constructor public. |
| 24 class TrivialDispatcher final : public Dispatcher { | 24 class TrivialDispatcher final : public Dispatcher { |
| 25 public: | 25 public: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 108 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 109 d->AddAwakable(&w, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss)); | 109 d->AddAwakable(&w, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss)); |
| 110 EXPECT_EQ(0u, hss.satisfied_signals); | 110 EXPECT_EQ(0u, hss.satisfied_signals); |
| 111 EXPECT_EQ(0u, hss.satisfiable_signals); | 111 EXPECT_EQ(0u, hss.satisfiable_signals); |
| 112 hss = HandleSignalsState(); | 112 hss = HandleSignalsState(); |
| 113 d->RemoveAwakable(&w, &hss); | 113 d->RemoveAwakable(&w, &hss); |
| 114 EXPECT_EQ(0u, hss.satisfied_signals); | 114 EXPECT_EQ(0u, hss.satisfied_signals); |
| 115 EXPECT_EQ(0u, hss.satisfiable_signals); | 115 EXPECT_EQ(0u, hss.satisfiable_signals); |
| 116 } | 116 } |
| 117 | 117 |
| 118 class ThreadSafetyStressThread : public base::SimpleThread { | 118 class ThreadSafetyStressThread : public mojo::test::SimpleTestThread { |
| 119 public: | 119 public: |
| 120 enum DispatcherOp { | 120 enum DispatcherOp { |
| 121 CLOSE = 0, | 121 CLOSE = 0, |
| 122 WRITE_MESSAGE, | 122 WRITE_MESSAGE, |
| 123 READ_MESSAGE, | 123 READ_MESSAGE, |
| 124 WRITE_DATA, | 124 WRITE_DATA, |
| 125 BEGIN_WRITE_DATA, | 125 BEGIN_WRITE_DATA, |
| 126 END_WRITE_DATA, | 126 END_WRITE_DATA, |
| 127 READ_DATA, | 127 READ_DATA, |
| 128 BEGIN_READ_DATA, | 128 BEGIN_READ_DATA, |
| 129 END_READ_DATA, | 129 END_READ_DATA, |
| 130 DUPLICATE_BUFFER_HANDLE, | 130 DUPLICATE_BUFFER_HANDLE, |
| 131 MAP_BUFFER, | 131 MAP_BUFFER, |
| 132 ADD_WAITER, | 132 ADD_WAITER, |
| 133 REMOVE_WAITER, | 133 REMOVE_WAITER, |
| 134 DISPATCHER_OP_COUNT | 134 DISPATCHER_OP_COUNT |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 ThreadSafetyStressThread(base::WaitableEvent* event, | 137 ThreadSafetyStressThread(base::WaitableEvent* event, |
| 138 scoped_refptr<Dispatcher> dispatcher, | 138 scoped_refptr<Dispatcher> dispatcher, |
| 139 DispatcherOp op) | 139 DispatcherOp op) |
| 140 : base::SimpleThread("thread_safety_stress_thread"), | 140 : event_(event), dispatcher_(dispatcher), op_(op) { |
| 141 event_(event), | |
| 142 dispatcher_(dispatcher), | |
| 143 op_(op) { | |
| 144 CHECK_LE(0, op_); | 141 CHECK_LE(0, op_); |
| 145 CHECK_LT(op_, DISPATCHER_OP_COUNT); | 142 CHECK_LT(op_, DISPATCHER_OP_COUNT); |
| 146 } | 143 } |
| 147 | 144 |
| 148 ~ThreadSafetyStressThread() override { Join(); } | 145 ~ThreadSafetyStressThread() override { Join(); } |
| 149 | 146 |
| 150 private: | 147 private: |
| 151 void Run() override { | 148 void Run() override { |
| 152 event_->Wait(); | 149 event_->Wait(); |
| 153 | 150 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 event.Signal(); | 297 event.Signal(); |
| 301 } // Joins all the threads. | 298 } // Joins all the threads. |
| 302 | 299 |
| 303 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 300 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 304 } | 301 } |
| 305 } | 302 } |
| 306 | 303 |
| 307 } // namespace | 304 } // namespace |
| 308 } // namespace system | 305 } // namespace system |
| 309 } // namespace mojo | 306 } // namespace mojo |
| OLD | NEW |