Index: base/threading/thread_local_storage_unittest.cc |
=================================================================== |
--- base/threading/thread_local_storage_unittest.cc (revision 111452) |
+++ base/threading/thread_local_storage_unittest.cc (working copy) |
@@ -22,6 +22,10 @@ |
namespace { |
const int kInitialTlsValue = 0x5555; |
+const int kFinalTlsValue = 0x7777; |
+// How many times must a destructor be called before we really are done. |
+const int kNumberDestructorCallRepetitions = 8; |
+ |
static ThreadLocalStorage::Slot tls_slot(LINKER_INITIALIZED); |
class ThreadLocalStorageRunner : public DelegateSimpleThread::Delegate { |
@@ -43,6 +47,8 @@ |
ptr = static_cast<int*>(tls_slot.Get()); |
EXPECT_EQ(ptr, tls_value_ptr_); |
EXPECT_EQ(*ptr, 0); |
+ |
+ *ptr = kFinalTlsValue + kNumberDestructorCallRepetitions; |
} |
private: |
@@ -53,8 +59,15 @@ |
void ThreadLocalStorageCleanup(void *value) { |
int *ptr = reinterpret_cast<int*>(value); |
- if (ptr) |
- *ptr = kInitialTlsValue; |
+ // Destructors should never be called wit a NULL. |
willchan no longer on Chromium
2011/11/29 01:46:49
s/wit/with/
jar (doing other things)
2011/11/29 02:32:45
Done.
|
+ ASSERT_NE(ptr, reinterpret_cast<int*>(NULL)); |
willchan no longer on Chromium
2011/11/29 01:46:49
Should be ASSERT_OP(expected, actual). You have it
jar (doing other things)
2011/11/29 02:32:45
Done.
|
+ if (*ptr == kFinalTlsValue) |
+ return; // We've been called enough times. |
+ ASSERT_GT(*ptr, kFinalTlsValue); |
+ ASSERT_LE(*ptr, kFinalTlsValue + kNumberDestructorCallRepetitions); |
+ --*ptr; // Move closer to our target. |
+ // Tell tls that we're not done with this thread, and still need destruction. |
+ tls_slot.Set(value); |
} |
} // namespace |
@@ -93,7 +106,7 @@ |
delete thread_delegates[index]; |
// Verify that the destructor was called and that we reset. |
- EXPECT_EQ(values[index], kInitialTlsValue); |
+ EXPECT_EQ(values[index], kFinalTlsValue); |
willchan no longer on Chromium
2011/11/29 01:46:49
Looks like this one was wrong too, can you fix the
jar (doing other things)
2011/11/29 02:32:45
Done.
|
} |
tls_slot.Free(); // Stop doing callbacks to cleanup threads. |
} |