| 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 // http://code.google.com/p/protobuf/ | 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. |
| 11 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
| 12 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
| 13 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
| (...skipping 22 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; |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| 48 class OnceInitTest : public testing::Test { | 49 class OnceInitTest : public testing::Test { |
| 49 protected: | 50 protected: |
| 50 void SetUp() { | 51 void SetUp() { |
| 51 state_ = INIT_NOT_STARTED; | 52 state_ = INIT_NOT_STARTED; |
| 52 current_test_ = this; | 53 current_test_ = this; |
| 53 } | 54 } |
| 54 | 55 |
| 55 // Since ProtobufOnceType is only allowed to be allocated in static storage, | 56 // Since ProtobufOnceType is only allowed to be allocated in static storage, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 121 } |
| 121 | 122 |
| 122 void Run() { | 123 void Run() { |
| 123 callback_->Run(); | 124 callback_->Run(); |
| 124 MutexLock lock(&done_mutex_); | 125 MutexLock lock(&done_mutex_); |
| 125 done_ = true; | 126 done_ = true; |
| 126 } | 127 } |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 TestThread* RunInitOnceInNewThread() { | 130 TestThread* RunInitOnceInNewThread() { |
| 130 return new TestThread(NewCallback(this, &OnceInitTest::InitOnce)); | 131 return new TestThread(internal::NewCallback(this, &OnceInitTest::InitOnce)); |
| 131 } | 132 } |
| 132 TestThread* RunInitRecursiveOnceInNewThread() { | 133 TestThread* RunInitRecursiveOnceInNewThread() { |
| 133 return new TestThread(NewCallback(this, &OnceInitTest::InitRecursiveOnce)); | 134 return new TestThread( |
| 135 internal::NewCallback(this, &OnceInitTest::InitRecursiveOnce)); |
| 134 } | 136 } |
| 135 | 137 |
| 136 enum State { | 138 enum State { |
| 137 INIT_NOT_STARTED, | 139 INIT_NOT_STARTED, |
| 138 INIT_STARTED, | 140 INIT_STARTED, |
| 139 INIT_DONE | 141 INIT_DONE |
| 140 }; | 142 }; |
| 141 State CurrentState() { | 143 State CurrentState() { |
| 142 MutexLock lock(&mutex_); | 144 MutexLock lock(&mutex_); |
| 143 return state_; | 145 return state_; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 246 |
| 245 for (int i = 0; i < 8; i++) { | 247 for (int i = 0; i < 8; i++) { |
| 246 threads[i]->Join(); | 248 threads[i]->Join(); |
| 247 } | 249 } |
| 248 EXPECT_EQ(INIT_DONE, CurrentState()); | 250 EXPECT_EQ(INIT_DONE, CurrentState()); |
| 249 } | 251 } |
| 250 | 252 |
| 251 } // anonymous namespace | 253 } // anonymous namespace |
| 252 } // namespace protobuf | 254 } // namespace protobuf |
| 253 } // namespace google | 255 } // namespace google |
| OLD | NEW |