| Index: base/lazy_instance.cc
|
| diff --git a/base/lazy_instance.cc b/base/lazy_instance.cc
|
| index 388622ae83ebf6a11c0a757f1e57c8a6c87c2aef..992325339cfcbabf3babf92dee3488cd55c2f862 100644
|
| --- a/base/lazy_instance.cc
|
| +++ b/base/lazy_instance.cc
|
| @@ -27,7 +27,14 @@ void LazyInstanceHelper::EnsureInstance(void* instance,
|
|
|
| // Instance is created, go from CREATING to CREATED.
|
| base::subtle::Release_Store(&state_, STATE_CREATED);
|
| - // Register the destructor callback with AtExitManager.
|
| +
|
| + // Allow reusing the LazyInstance (reset it to the initial state). This
|
| + // makes possible calling all AtExit callbacks between tests. Assumes that
|
| + // no other threads execute when AtExit callbacks are processed.
|
| + base::AtExitManager::RegisterCallback(&LazyInstanceHelper::ResetState,
|
| + this);
|
| +
|
| + // Make sure that the lazily instantiated object will get destroyed at exit.
|
| base::AtExitManager::RegisterCallback(dtor, instance);
|
| } else {
|
| // It's either in the process of being created, or already created. Spin.
|
| @@ -36,4 +43,9 @@ void LazyInstanceHelper::EnsureInstance(void* instance,
|
| }
|
| }
|
|
|
| +// static
|
| +void LazyInstanceHelper::ResetState(void* helper) {
|
| + reinterpret_cast<LazyInstanceHelper*>(helper)->state_ = STATE_EMPTY;
|
| +}
|
| +
|
| } // namespace base
|
|
|