| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include <unistd.h> | 36 #include <unistd.h> |
| 37 #include <pthread.h> | 37 #include <pthread.h> |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 #include <google/protobuf/stubs/once.h> | 40 #include <google/protobuf/stubs/once.h> |
| 41 #include <google/protobuf/testing/googletest.h> | 41 #include <google/protobuf/testing/googletest.h> |
| 42 #include <gtest/gtest.h> | 42 #include <gtest/gtest.h> |
| 43 | 43 |
| 44 namespace google { | 44 namespace google { |
| 45 namespace protobuf { | 45 namespace protobuf { |
| 46 using internal::NewCallback; | |
| 47 namespace { | 46 namespace { |
| 48 | 47 |
| 49 class OnceInitTest : public testing::Test { | 48 class OnceInitTest : public testing::Test { |
| 50 protected: | 49 protected: |
| 51 void SetUp() { | 50 void SetUp() { |
| 52 state_ = INIT_NOT_STARTED; | 51 state_ = INIT_NOT_STARTED; |
| 53 current_test_ = this; | 52 current_test_ = this; |
| 54 } | 53 } |
| 55 | 54 |
| 56 // Since ProtobufOnceType is only allowed to be allocated in static storage, | 55 // Since ProtobufOnceType is only allowed to be allocated in static storage, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 120 } |
| 122 | 121 |
| 123 void Run() { | 122 void Run() { |
| 124 callback_->Run(); | 123 callback_->Run(); |
| 125 MutexLock lock(&done_mutex_); | 124 MutexLock lock(&done_mutex_); |
| 126 done_ = true; | 125 done_ = true; |
| 127 } | 126 } |
| 128 }; | 127 }; |
| 129 | 128 |
| 130 TestThread* RunInitOnceInNewThread() { | 129 TestThread* RunInitOnceInNewThread() { |
| 131 return new TestThread(internal::NewCallback(this, &OnceInitTest::InitOnce)); | 130 return new TestThread(NewCallback(this, &OnceInitTest::InitOnce)); |
| 132 } | 131 } |
| 133 TestThread* RunInitRecursiveOnceInNewThread() { | 132 TestThread* RunInitRecursiveOnceInNewThread() { |
| 134 return new TestThread( | 133 return new TestThread( |
| 135 internal::NewCallback(this, &OnceInitTest::InitRecursiveOnce)); | 134 NewCallback(this, &OnceInitTest::InitRecursiveOnce)); |
| 136 } | 135 } |
| 137 | 136 |
| 138 enum State { | 137 enum State { |
| 139 INIT_NOT_STARTED, | 138 INIT_NOT_STARTED, |
| 140 INIT_STARTED, | 139 INIT_STARTED, |
| 141 INIT_DONE | 140 INIT_DONE |
| 142 }; | 141 }; |
| 143 State CurrentState() { | 142 State CurrentState() { |
| 144 MutexLock lock(&mutex_); | 143 MutexLock lock(&mutex_); |
| 145 return state_; | 144 return state_; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 245 |
| 247 for (int i = 0; i < 8; i++) { | 246 for (int i = 0; i < 8; i++) { |
| 248 threads[i]->Join(); | 247 threads[i]->Join(); |
| 249 } | 248 } |
| 250 EXPECT_EQ(INIT_DONE, CurrentState()); | 249 EXPECT_EQ(INIT_DONE, CurrentState()); |
| 251 } | 250 } |
| 252 | 251 |
| 253 } // anonymous namespace | 252 } // anonymous namespace |
| 254 } // namespace protobuf | 253 } // namespace protobuf |
| 255 } // namespace google | 254 } // namespace google |
| OLD | NEW |