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 <stddef.h> | 10 #include <stddef.h> |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 #if !defined(WIN32) | 27 #if !defined(WIN32) |
28 class MessagePipeWriterThread : public mojo::Thread { | 28 class MessagePipeWriterThread : public mojo::Thread { |
29 public: | 29 public: |
30 MessagePipeWriterThread(MojoHandle handle, uint32_t num_bytes) | 30 MessagePipeWriterThread(MojoHandle handle, uint32_t num_bytes) |
31 : handle_(handle), num_bytes_(num_bytes), num_writes_(0) {} | 31 : handle_(handle), num_bytes_(num_bytes), num_writes_(0) {} |
32 virtual ~MessagePipeWriterThread() {} | 32 virtual ~MessagePipeWriterThread() {} |
33 | 33 |
34 virtual void Run() MOJO_OVERRIDE { | 34 virtual void Run() override { |
35 char buffer[10000]; | 35 char buffer[10000]; |
36 assert(num_bytes_ <= sizeof(buffer)); | 36 assert(num_bytes_ <= sizeof(buffer)); |
37 | 37 |
38 // TODO(vtl): Should I throttle somehow? | 38 // TODO(vtl): Should I throttle somehow? |
39 for (;;) { | 39 for (;;) { |
40 MojoResult result = MojoWriteMessage( | 40 MojoResult result = MojoWriteMessage( |
41 handle_, buffer, num_bytes_, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); | 41 handle_, buffer, num_bytes_, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); |
42 if (result == MOJO_RESULT_OK) { | 42 if (result == MOJO_RESULT_OK) { |
43 num_writes_++; | 43 num_writes_++; |
44 continue; | 44 continue; |
(...skipping 17 matching lines...) Expand all Loading... |
62 | 62 |
63 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeWriterThread); | 63 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeWriterThread); |
64 }; | 64 }; |
65 | 65 |
66 class MessagePipeReaderThread : public mojo::Thread { | 66 class MessagePipeReaderThread : public mojo::Thread { |
67 public: | 67 public: |
68 explicit MessagePipeReaderThread(MojoHandle handle) | 68 explicit MessagePipeReaderThread(MojoHandle handle) |
69 : handle_(handle), num_reads_(0) {} | 69 : handle_(handle), num_reads_(0) {} |
70 virtual ~MessagePipeReaderThread() {} | 70 virtual ~MessagePipeReaderThread() {} |
71 | 71 |
72 virtual void Run() MOJO_OVERRIDE { | 72 virtual void Run() override { |
73 char buffer[10000]; | 73 char buffer[10000]; |
74 | 74 |
75 for (;;) { | 75 for (;;) { |
76 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); | 76 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); |
77 MojoResult result = MojoReadMessage( | 77 MojoResult result = MojoReadMessage( |
78 handle_, buffer, &num_bytes, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE); | 78 handle_, buffer, &num_bytes, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE); |
79 if (result == MOJO_RESULT_OK) { | 79 if (result == MOJO_RESULT_OK) { |
80 num_reads_++; | 80 num_reads_++; |
81 continue; | 81 continue; |
82 } | 82 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 DoMessagePipeThreadedTest(1u, 1u, 10000u); | 330 DoMessagePipeThreadedTest(1u, 1u, 10000u); |
331 | 331 |
332 DoMessagePipeThreadedTest(3u, 3u, 10u); | 332 DoMessagePipeThreadedTest(3u, 3u, 10u); |
333 // 100 was done above. | 333 // 100 was done above. |
334 DoMessagePipeThreadedTest(3u, 3u, 1000u); | 334 DoMessagePipeThreadedTest(3u, 3u, 1000u); |
335 DoMessagePipeThreadedTest(3u, 3u, 10000u); | 335 DoMessagePipeThreadedTest(3u, 3u, 10000u); |
336 } | 336 } |
337 #endif // !defined(WIN32) | 337 #endif // !defined(WIN32) |
338 | 338 |
339 } // namespace | 339 } // namespace |
OLD | NEW |