diff options
Diffstat (limited to 'base/lazy_instance.cc')
-rw-r--r-- | base/lazy_instance.cc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/base/lazy_instance.cc b/base/lazy_instance.cc index 388622a..9923253 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 |