Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: base/lazy_instance_unittest.cc

Issue 3956003: ThreadRestrictions: leak the thread local variable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better impl Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/atomic_sequence_num.h" 6 #include "base/atomic_sequence_num.h"
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/simple_thread.h" 8 #include "base/simple_thread.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 base::DelegateSimpleThreadPool pool("lazy_instance_cons", 5); 89 base::DelegateSimpleThreadPool pool("lazy_instance_cons", 5);
90 pool.AddWork(&delegate, 20); 90 pool.AddWork(&delegate, 20);
91 EXPECT_EQ(0, SlowConstructor::constructed); 91 EXPECT_EQ(0, SlowConstructor::constructed);
92 92
93 pool.Start(); 93 pool.Start();
94 pool.JoinAll(); 94 pool.JoinAll();
95 EXPECT_EQ(1, SlowConstructor::constructed); 95 EXPECT_EQ(1, SlowConstructor::constructed);
96 } 96 }
97 } 97 }
98
99 namespace {
100
101 // DeleteLogger is an object which sets a flag when it's destroyed.
102 // It accepts a bool* and sets the bool to true when the dtor runs.
103 class DeleteLogger {
104 public:
105 DeleteLogger() : deleted_(NULL) {}
106 ~DeleteLogger() { *deleted_ = true; }
107
108 void SetDeletedPtr(bool* deleted) {
109 deleted_ = deleted;
110 }
111
112 private:
113 bool* deleted_;
114 };
115
116 } // anonymous namespace
willchan no longer on Chromium 2010/10/21 20:26:50 I actually don't understand why this whole file is
117
118 TEST(LazyInstanceTest, LeakyLazyInstance) {
119 // Check that using a plain LazyInstance causes the dtor to run
120 // when the AtExitManager finishes.
121 bool deleted1 = false;
122 {
123 base::ShadowingAtExitManager shadow;
124 static base::LazyInstance<DeleteLogger> test(base::LINKER_INITIALIZED);
125 test.Get().SetDeletedPtr(&deleted1);
126 }
127 EXPECT_TRUE(deleted1);
128
129 // Check that using a *leaky* LazyInstance makes the dtor not run
130 // when the AtExitManager finishes.
131 bool deleted2 = false;
132 {
133 base::ShadowingAtExitManager shadow;
134 static base::LazyInstance<DeleteLogger,
135 base::LeakyLazyInstanceTraits<DeleteLogger> >
136 test(base::LINKER_INITIALIZED);
137 test.Get().SetDeletedPtr(&deleted2);
138 }
139 EXPECT_FALSE(deleted2);
140 }
OLDNEW
« no previous file with comments | « base/lazy_instance.cc ('k') | base/thread_restrictions.cc » ('j') | base/thread_restrictions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698