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

Unified Diff: base/threading/thread_local_storage_unittest.cc

Issue 8702014: Make ThreadLocalStorage more posix pthread compliant (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/threading/thread_local_storage.h ('k') | base/threading/thread_local_storage_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/thread_local_storage_unittest.cc
===================================================================
--- base/threading/thread_local_storage_unittest.cc (revision 111815)
+++ 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 = 3;
+
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 with a NULL.
+ ASSERT_NE(reinterpret_cast<int*>(NULL), ptr);
+ if (*ptr == kFinalTlsValue)
+ return; // We've been called enough times.
+ ASSERT_LT(kFinalTlsValue, *ptr);
+ ASSERT_GE(kFinalTlsValue + kNumberDestructorCallRepetitions, *ptr);
+ --*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);
}
tls_slot.Free(); // Stop doing callbacks to cleanup threads.
}
« no previous file with comments | « base/threading/thread_local_storage.h ('k') | base/threading/thread_local_storage_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698