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 // This tests the performance of the C API. | 5 // This tests the performance of the C API. |
6 | 6 |
7 #include "mojo/public/c/system/core.h" | 7 #include "mojo/public/c/system/core.h" |
8 | 8 |
9 #include <assert.h> | 9 #include <assert.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/threading/simple_thread.h" | 14 #include "base/threading/simple_thread.h" |
| 15 #include "mojo/public/cpp/system/wait.h" |
15 #include "mojo/public/cpp/test_support/test_support.h" | 16 #include "mojo/public/cpp/test_support/test_support.h" |
16 #include "mojo/public/cpp/test_support/test_utils.h" | 17 #include "mojo/public/cpp/test_support/test_utils.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 #if !defined(WIN32) | 20 #if !defined(WIN32) |
20 #include <time.h> | 21 #include <time.h> |
21 #endif // !defined(WIN32) | 22 #endif // !defined(WIN32) |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 for (;;) { | 79 for (;;) { |
79 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); | 80 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); |
80 MojoResult result = MojoReadMessage(handle_, buffer, &num_bytes, nullptr, | 81 MojoResult result = MojoReadMessage(handle_, buffer, &num_bytes, nullptr, |
81 nullptr, MOJO_READ_MESSAGE_FLAG_NONE); | 82 nullptr, MOJO_READ_MESSAGE_FLAG_NONE); |
82 if (result == MOJO_RESULT_OK) { | 83 if (result == MOJO_RESULT_OK) { |
83 num_reads_++; | 84 num_reads_++; |
84 continue; | 85 continue; |
85 } | 86 } |
86 | 87 |
87 if (result == MOJO_RESULT_SHOULD_WAIT) { | 88 if (result == MOJO_RESULT_SHOULD_WAIT) { |
88 result = MojoWait(handle_, MOJO_HANDLE_SIGNAL_READABLE, | 89 result = mojo::Wait(mojo::Handle(handle_), MOJO_HANDLE_SIGNAL_READABLE); |
89 MOJO_DEADLINE_INDEFINITE, nullptr); | |
90 if (result == MOJO_RESULT_OK) { | 90 if (result == MOJO_RESULT_OK) { |
91 // Go to the top of the loop to read again. | 91 // Go to the top of the loop to read again. |
92 continue; | 92 continue; |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 // We failed to read and possibly failed to wait. | 96 // We failed to read and possibly failed to wait. |
97 // Either |handle_| or its peer was closed. | 97 // Either |handle_| or its peer was closed. |
98 assert(result == MOJO_RESULT_INVALID_ARGUMENT || | 98 assert(result == MOJO_RESULT_INVALID_ARGUMENT || |
99 result == MOJO_RESULT_FAILED_PRECONDITION); | 99 result == MOJO_RESULT_FAILED_PRECONDITION); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 DoMessagePipeThreadedTest(1u, 1u, 10000u); | 320 DoMessagePipeThreadedTest(1u, 1u, 10000u); |
321 | 321 |
322 DoMessagePipeThreadedTest(3u, 3u, 10u); | 322 DoMessagePipeThreadedTest(3u, 3u, 10u); |
323 // 100 was done above. | 323 // 100 was done above. |
324 DoMessagePipeThreadedTest(3u, 3u, 1000u); | 324 DoMessagePipeThreadedTest(3u, 3u, 1000u); |
325 DoMessagePipeThreadedTest(3u, 3u, 10000u); | 325 DoMessagePipeThreadedTest(3u, 3u, 10000u); |
326 } | 326 } |
327 #endif // !defined(WIN32) | 327 #endif // !defined(WIN32) |
328 | 328 |
329 } // namespace | 329 } // namespace |
OLD | NEW |