Mojo: foo_[0-9] -> foo[0-9].

For foolish consistency. I'll never make this mistake again.

R=sky@chromium.org

Review URL: https://codereview.chromium.org/140503005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245573 0039d316-1c4b-4281-b951-d872f2087c98
parent 7c905da0
......@@ -186,17 +186,17 @@ MOJO_COMPILE_ASSERT(sizeof(ScopedMessagePipeHandle) ==
// TODO(vtl): In C++11, we could instead return a pair of
// |ScopedMessagePipeHandle|s.
inline void CreateMessagePipe(ScopedMessagePipeHandle* message_pipe_0,
ScopedMessagePipeHandle* message_pipe_1) {
assert(message_pipe_0);
assert(message_pipe_1);
MessagePipeHandle h_0;
MessagePipeHandle h_1;
inline void CreateMessagePipe(ScopedMessagePipeHandle* message_pipe0,
ScopedMessagePipeHandle* message_pipe1) {
assert(message_pipe0);
assert(message_pipe1);
MessagePipeHandle h0;
MessagePipeHandle h1;
MojoResult result MOJO_ALLOW_UNUSED =
MojoCreateMessagePipe(h_0.mutable_value(), h_1.mutable_value());
MojoCreateMessagePipe(h0.mutable_value(), h1.mutable_value());
assert(result == MOJO_RESULT_OK);
message_pipe_0->reset(h_0);
message_pipe_1->reset(h_1);
message_pipe0->reset(h0);
message_pipe1->reset(h1);
}
class MessagePipe {
......
......@@ -25,24 +25,24 @@ class CorePerftest : public testing::Test {
static void MessagePipe_CreateAndClose(void* closure) {
CorePerftest* self = static_cast<CorePerftest*>(closure);
MojoResult result MOJO_ALLOW_UNUSED;
result = MojoCreateMessagePipe(&self->h_0_, &self->h_1_);
result = MojoCreateMessagePipe(&self->h0_, &self->h1_);
assert(result == MOJO_RESULT_OK);
result = MojoClose(self->h_0_);
result = MojoClose(self->h0_);
assert(result == MOJO_RESULT_OK);
result = MojoClose(self->h_1_);
result = MojoClose(self->h1_);
assert(result == MOJO_RESULT_OK);
}
static void MessagePipe_WriteAndRead(void* closure) {
CorePerftest* self = static_cast<CorePerftest*>(closure);
MojoResult result MOJO_ALLOW_UNUSED;
result = MojoWriteMessage(self->h_0_,
result = MojoWriteMessage(self->h0_,
self->buffer_, self->num_bytes_,
NULL, 0,
MOJO_WRITE_MESSAGE_FLAG_NONE);
assert(result == MOJO_RESULT_OK);
uint32_t read_bytes = self->num_bytes_;
result = MojoReadMessage(self->h_1_,
result = MojoReadMessage(self->h1_,
self->buffer_, &read_bytes,
NULL, NULL,
MOJO_READ_MESSAGE_FLAG_NONE);
......@@ -52,7 +52,7 @@ class CorePerftest : public testing::Test {
static void MessagePipe_EmptyRead(void* closure) {
CorePerftest* self = static_cast<CorePerftest*>(closure);
MojoResult result MOJO_ALLOW_UNUSED;
result = MojoReadMessage(self->h_0_,
result = MojoReadMessage(self->h0_,
NULL, NULL,
NULL, NULL,
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD);
......@@ -60,8 +60,8 @@ class CorePerftest : public testing::Test {
}
protected:
MojoHandle h_0_;
MojoHandle h_1_;
MojoHandle h0_;
MojoHandle h1_;
void* buffer_;
uint32_t num_bytes_;
......@@ -83,7 +83,7 @@ TEST_F(CorePerftest, MessagePipe_CreateAndClose) {
TEST_F(CorePerftest, MessagePipe_WriteAndRead) {
MojoResult result MOJO_ALLOW_UNUSED;
result = MojoCreateMessagePipe(&h_0_, &h_1_);
result = MojoCreateMessagePipe(&h0_, &h1_);
assert(result == MOJO_RESULT_OK);
char buffer[10000] = { 0 };
buffer_ = buffer;
......@@ -103,22 +103,22 @@ TEST_F(CorePerftest, MessagePipe_WriteAndRead) {
mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_10000bytes",
&CorePerftest::MessagePipe_WriteAndRead,
this);
result = MojoClose(h_0_);
result = MojoClose(h0_);
assert(result == MOJO_RESULT_OK);
result = MojoClose(h_1_);
result = MojoClose(h1_);
assert(result == MOJO_RESULT_OK);
}
TEST_F(CorePerftest, MessagePipe_EmptyRead) {
MojoResult result MOJO_ALLOW_UNUSED;
result = MojoCreateMessagePipe(&h_0_, &h_1_);
result = MojoCreateMessagePipe(&h0_, &h1_);
assert(result == MOJO_RESULT_OK);
mojo::test::IterateAndReportPerf("MessagePipe_EmptyRead",
&CorePerftest::MessagePipe_EmptyRead,
this);
result = MojoClose(h_0_);
result = MojoClose(h0_);
assert(result == MOJO_RESULT_OK);
result = MojoClose(h_1_);
result = MojoClose(h1_);
assert(result == MOJO_RESULT_OK);
}
......
......@@ -20,7 +20,7 @@ TEST(CoreTest, GetTimeTicksNow) {
}
TEST(CoreTest, Basic) {
MojoHandle h_0;
MojoHandle h0;
MojoWaitFlags wf;
char buffer[10] = { 0 };
uint32_t buffer_size;
......@@ -29,80 +29,79 @@ TEST(CoreTest, Basic) {
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(MOJO_HANDLE_INVALID));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoWait(MOJO_HANDLE_INVALID, MOJO_WAIT_FLAG_EVERYTHING, 1000000));
h_0 = MOJO_HANDLE_INVALID;
h0 = MOJO_HANDLE_INVALID;
wf = MOJO_WAIT_FLAG_EVERYTHING;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoWaitMany(&h_0, &wf, 1, MOJO_DEADLINE_INDEFINITE));
MojoWaitMany(&h0, &wf, 1, MOJO_DEADLINE_INDEFINITE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoWriteMessage(h_0,
MojoWriteMessage(h0,
buffer, 3,
NULL, 0,
MOJO_WRITE_MESSAGE_FLAG_NONE));
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoReadMessage(h_0,
MojoReadMessage(h0,
buffer, &buffer_size,
NULL, NULL,
MOJO_READ_MESSAGE_FLAG_NONE));
MojoHandle h_1;
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(&h_0, &h_1));
MojoHandle h1;
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(&h0, &h1));
// Shouldn't be readable.
EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
MojoWait(h_0, MOJO_WAIT_FLAG_READABLE, 0));
MojoWait(h0, MOJO_WAIT_FLAG_READABLE, 0));
// Should be writable.
EXPECT_EQ(MOJO_RESULT_OK,
MojoWait(h_0, MOJO_WAIT_FLAG_WRITABLE, 0));
MojoWait(h0, MOJO_WAIT_FLAG_WRITABLE, 0));
// Try to read.
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
MojoReadMessage(h_0,
MojoReadMessage(h0,
buffer, &buffer_size,
NULL, NULL,
MOJO_READ_MESSAGE_FLAG_NONE));
// Write to |h_1|.
// Write to |h1|.
static const char hello[] = "hello";
memcpy(buffer, hello, sizeof(hello));
buffer_size = static_cast<uint32_t>(sizeof(hello));
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(h_1,
MojoWriteMessage(h1,
hello, buffer_size,
NULL, 0,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// |h_0| should be readable.
// |h0| should be readable.
wf = MOJO_WAIT_FLAG_READABLE;
EXPECT_EQ(MOJO_RESULT_OK,
MojoWaitMany(&h_0, &wf, 1, MOJO_DEADLINE_INDEFINITE));
MojoWaitMany(&h0, &wf, 1, MOJO_DEADLINE_INDEFINITE));
// Read from |h_0|.
// Read from |h0|.
memset(buffer, 0, sizeof(buffer));
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
MojoReadMessage(h_0,
MojoReadMessage(h0,
buffer, &buffer_size,
NULL, NULL,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(static_cast<uint32_t>(sizeof(hello)), buffer_size);
EXPECT_EQ(0, memcmp(hello, buffer, sizeof(hello)));
// |h_0| should no longer be readable.
// |h0| should no longer be readable.
EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
MojoWait(h_0, MOJO_WAIT_FLAG_READABLE, 10));
MojoWait(h0, MOJO_WAIT_FLAG_READABLE, 10));
// Close |h_0|.
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h_0));
// Close |h0|.
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0));
// |h_1| should no longer be readable or writable.
// |h1| should no longer be readable or writable.
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
MojoWait(h_1,
MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE,
MojoWait(h1, MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE,
1000));
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h_1));
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1));
}
// TODO(vtl): Add multi-threaded tests.
......
......@@ -155,20 +155,18 @@ MojoResult CoreImpl::CreateMessagePipe(MojoHandle* message_pipe_handle0,
if (!VerifyUserPointer<MojoHandle>(message_pipe_handle1, 1))
return MOJO_RESULT_INVALID_ARGUMENT;
scoped_refptr<MessagePipeDispatcher> dispatcher_0(
new MessagePipeDispatcher());
scoped_refptr<MessagePipeDispatcher> dispatcher_1(
new MessagePipeDispatcher());
scoped_refptr<MessagePipeDispatcher> dispatcher0(new MessagePipeDispatcher());
scoped_refptr<MessagePipeDispatcher> dispatcher1(new MessagePipeDispatcher());
MojoHandle h0, h1;
{
base::AutoLock locker(handle_table_lock_);
h0 = AddDispatcherNoLock(dispatcher_0);
h0 = AddDispatcherNoLock(dispatcher0);
if (h0 == MOJO_HANDLE_INVALID)
return MOJO_RESULT_RESOURCE_EXHAUSTED;
h1 = AddDispatcherNoLock(dispatcher_1);
h1 = AddDispatcherNoLock(dispatcher1);
if (h1 == MOJO_HANDLE_INVALID) {
handle_table_.erase(h0);
return MOJO_RESULT_RESOURCE_EXHAUSTED;
......@@ -176,8 +174,8 @@ MojoResult CoreImpl::CreateMessagePipe(MojoHandle* message_pipe_handle0,
}
scoped_refptr<MessagePipe> message_pipe(new MessagePipe());
dispatcher_0->Init(message_pipe, 0);
dispatcher_1->Init(message_pipe, 1);
dispatcher0->Init(message_pipe, 0);
dispatcher1->Init(message_pipe, 1);
*message_pipe_handle0 = h0;
*message_pipe_handle1 = h1;
......
......@@ -251,11 +251,11 @@ TEST_F(CoreImplTest, InvalidArguments) {
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(0u, info.GetWriteMessageCallCount());
MockHandleInfo info_2;
MojoHandle h_2 = CreateMockHandle(&info_2);
MockHandleInfo info2;
MojoHandle h2 = CreateMockHandle(&info2);
// This is "okay", but |MockDispatcher| doesn't implement it.
handles[0] = h_2;
handles[0] = h2;
EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
core()->WriteMessage(h, NULL, 0, handles, 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
......@@ -275,15 +275,15 @@ TEST_F(CoreImplTest, InvalidArguments) {
EXPECT_EQ(1u, info.GetWriteMessageCallCount());
// Can't send a handle twice in the same message.
handles[1] = h_2;
handles[1] = h2;
EXPECT_EQ(MOJO_RESULT_BUSY,
core()->WriteMessage(h, NULL, 0, handles, 2,
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(1u, info.GetWriteMessageCallCount());
// Note: Since we never successfully sent anything with it, |h_2| should
// Note: Since we never successfully sent anything with it, |h2| should
// still be valid.
EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_2));
EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h2));
EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
}
......
......@@ -15,10 +15,10 @@
namespace mojo {
namespace system {
MessagePipe::MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint_0,
scoped_ptr<MessagePipeEndpoint> endpoint_1) {
endpoints_[0].reset(endpoint_0.release());
endpoints_[1].reset(endpoint_1.release());
MessagePipe::MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint0,
scoped_ptr<MessagePipeEndpoint> endpoint1) {
endpoints_[0].reset(endpoint0.release());
endpoints_[1].reset(endpoint1.release());
}
MessagePipe::MessagePipe() {
......
......@@ -30,8 +30,8 @@ class Waiter;
class MOJO_SYSTEM_IMPL_EXPORT MessagePipe :
public base::RefCountedThreadSafe<MessagePipe> {
public:
MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint_0,
scoped_ptr<MessagePipeEndpoint> endpoint_1);
MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint0,
scoped_ptr<MessagePipeEndpoint> endpoint1);
// Convenience constructor that constructs a |MessagePipe| with two new
// |LocalMessagePipeEndpoint|s.
......
......@@ -146,71 +146,71 @@ TEST(WaiterListTest, BasicAwakeUnsatisfiable) {
}
TEST(WaiterListTest, MultipleWaiters) {
MojoResult result_1;
MojoResult result_2;
MojoResult result_3;
MojoResult result_4;
MojoResult result1;
MojoResult result2;
MojoResult result3;
MojoResult result4;
// Cancel two waiters.
{
WaiterList waiter_list;
test::SimpleWaiterThread thread_1(&result_1);
waiter_list.AddWaiter(thread_1.waiter(), MOJO_WAIT_FLAG_READABLE, 0);
thread_1.Start();
test::SimpleWaiterThread thread_2(&result_2);
waiter_list.AddWaiter(thread_2.waiter(), MOJO_WAIT_FLAG_WRITABLE, 1);
thread_2.Start();
test::SimpleWaiterThread thread1(&result1);
waiter_list.AddWaiter(thread1.waiter(), MOJO_WAIT_FLAG_READABLE, 0);
thread1.Start();
test::SimpleWaiterThread thread2(&result2);
waiter_list.AddWaiter(thread2.waiter(), MOJO_WAIT_FLAG_WRITABLE, 1);
thread2.Start();
base::PlatformThread::Sleep(
base::TimeDelta::FromMicroseconds(2 * kEpsilonMicros));
waiter_list.CancelAllWaiters();
} // Join threads.
EXPECT_EQ(MOJO_RESULT_CANCELLED, result_1);
EXPECT_EQ(MOJO_RESULT_CANCELLED, result_2);
EXPECT_EQ(MOJO_RESULT_CANCELLED, result1);
EXPECT_EQ(MOJO_RESULT_CANCELLED, result2);
// Awake one waiter, cancel other.
{
WaiterList waiter_list;
test::SimpleWaiterThread thread_1(&result_1);
waiter_list.AddWaiter(thread_1.waiter(), MOJO_WAIT_FLAG_READABLE, 2);
thread_1.Start();
test::SimpleWaiterThread thread_2(&result_2);
waiter_list.AddWaiter(thread_2.waiter(), MOJO_WAIT_FLAG_WRITABLE, 3);
thread_2.Start();
test::SimpleWaiterThread thread1(&result1);
waiter_list.AddWaiter(thread1.waiter(), MOJO_WAIT_FLAG_READABLE, 2);
thread1.Start();
test::SimpleWaiterThread thread2(&result2);
waiter_list.AddWaiter(thread2.waiter(), MOJO_WAIT_FLAG_WRITABLE, 3);
thread2.Start();
base::PlatformThread::Sleep(
base::TimeDelta::FromMicroseconds(2 * kEpsilonMicros));
waiter_list.AwakeWaitersForStateChange(MOJO_WAIT_FLAG_READABLE,
MOJO_WAIT_FLAG_READABLE |
MOJO_WAIT_FLAG_WRITABLE);
waiter_list.RemoveWaiter(thread_1.waiter());
waiter_list.RemoveWaiter(thread1.waiter());
waiter_list.CancelAllWaiters();
} // Join threads.
EXPECT_EQ(2, result_1);
EXPECT_EQ(MOJO_RESULT_CANCELLED, result_2);
EXPECT_EQ(2, result1);
EXPECT_EQ(MOJO_RESULT_CANCELLED, result2);
// Cancel one waiter, awake other for unsatisfiability.
{
WaiterList waiter_list;
test::SimpleWaiterThread thread_1(&result_1);
waiter_list.AddWaiter(thread_1.waiter(), MOJO_WAIT_FLAG_READABLE, 4);
thread_1.Start();
test::SimpleWaiterThread thread_2(&result_2);
waiter_list.AddWaiter(thread_2.waiter(), MOJO_WAIT_FLAG_WRITABLE, 5);
thread_2.Start();
test::SimpleWaiterThread thread1(&result1);
waiter_list.AddWaiter(thread1.waiter(), MOJO_WAIT_FLAG_READABLE, 4);
thread1.Start();
test::SimpleWaiterThread thread2(&result2);
waiter_list.AddWaiter(thread2.waiter(), MOJO_WAIT_FLAG_WRITABLE, 5);
thread2.Start();
base::PlatformThread::Sleep(
base::TimeDelta::FromMicroseconds(2 * kEpsilonMicros));
waiter_list.AwakeWaitersForStateChange(0, MOJO_WAIT_FLAG_READABLE);
waiter_list.RemoveWaiter(thread_2.waiter());
waiter_list.RemoveWaiter(thread2.waiter());
waiter_list.CancelAllWaiters();
} // Join threads.
EXPECT_EQ(MOJO_RESULT_CANCELLED, result_1);
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result_2);
EXPECT_EQ(MOJO_RESULT_CANCELLED, result1);
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result2);
// Cancel one waiter, awake other for unsatisfiability.
{
WaiterList waiter_list;
test::SimpleWaiterThread thread_1(&result_1);
waiter_list.AddWaiter(thread_1.waiter(), MOJO_WAIT_FLAG_READABLE, 6);
thread_1.Start();
test::SimpleWaiterThread thread1(&result1);
waiter_list.AddWaiter(thread1.waiter(), MOJO_WAIT_FLAG_READABLE, 6);
thread1.Start();
base::PlatformThread::Sleep(
base::TimeDelta::FromMicroseconds(1 * kEpsilonMicros));
......@@ -220,9 +220,9 @@ TEST(WaiterListTest, MultipleWaiters) {
MOJO_WAIT_FLAG_READABLE |
MOJO_WAIT_FLAG_WRITABLE);
test::SimpleWaiterThread thread_2(&result_2);
waiter_list.AddWaiter(thread_2.waiter(), MOJO_WAIT_FLAG_WRITABLE, 7);
thread_2.Start();
test::SimpleWaiterThread thread2(&result2);
waiter_list.AddWaiter(thread2.waiter(), MOJO_WAIT_FLAG_WRITABLE, 7);
thread2.Start();
base::PlatformThread::Sleep(
base::TimeDelta::FromMicroseconds(1 * kEpsilonMicros));
......@@ -231,34 +231,34 @@ TEST(WaiterListTest, MultipleWaiters) {
waiter_list.AwakeWaitersForStateChange(MOJO_WAIT_FLAG_READABLE,
MOJO_WAIT_FLAG_READABLE |
MOJO_WAIT_FLAG_WRITABLE);
waiter_list.RemoveWaiter(thread_1.waiter());
waiter_list.RemoveWaiter(thread1.waiter());
base::PlatformThread::Sleep(
base::TimeDelta::FromMicroseconds(1 * kEpsilonMicros));
test::SimpleWaiterThread thread_3(&result_3);
waiter_list.AddWaiter(thread_3.waiter(), MOJO_WAIT_FLAG_WRITABLE, 8);
thread_3.Start();
test::SimpleWaiterThread thread3(&result3);
waiter_list.AddWaiter(thread3.waiter(), MOJO_WAIT_FLAG_WRITABLE, 8);
thread3.Start();
test::SimpleWaiterThread thread_4(&result_4);
waiter_list.AddWaiter(thread_4.waiter(), MOJO_WAIT_FLAG_READABLE, 9);
thread_4.Start();
test::SimpleWaiterThread thread4(&result4);
waiter_list.AddWaiter(thread4.waiter(), MOJO_WAIT_FLAG_READABLE, 9);
thread4.Start();
base::PlatformThread::Sleep(
base::TimeDelta::FromMicroseconds(1 * kEpsilonMicros));
// Awake #2 and #3 for unsatisfiability.
waiter_list.AwakeWaitersForStateChange(0, MOJO_WAIT_FLAG_READABLE);
waiter_list.RemoveWaiter(thread_2.waiter());
waiter_list.RemoveWaiter(thread_3.waiter());
waiter_list.RemoveWaiter(thread2.waiter());
waiter_list.RemoveWaiter(thread3.waiter());
// Cancel #4.
waiter_list.CancelAllWaiters();
} // Join threads.
EXPECT_EQ(6, result_1);
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result_2);
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result_3);
EXPECT_EQ(MOJO_RESULT_CANCELLED, result_4);
EXPECT_EQ(6, result1);
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result2);
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result3);
EXPECT_EQ(MOJO_RESULT_CANCELLED, result4);
}
} // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment