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

Side by Side Diff: third_party/WebKit/Source/platform/heap/HeapTest.cpp

Issue 1881933005: Oilpan: Add ThreadState cleanup callbacks for static thread-specific persistent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unit test Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 volatile int m_gcCount; 490 volatile int m_gcCount;
491 volatile int m_threadsToFinish; 491 volatile int m_threadsToFinish;
492 492
493 private: 493 private:
494 static void threadFunc(void* data) 494 static void threadFunc(void* data)
495 { 495 {
496 reinterpret_cast<ThreadedTesterBase*>(data)->runThread(); 496 reinterpret_cast<ThreadedTesterBase*>(data)->runThread();
497 } 497 }
498 }; 498 };
499 499
500 // Needed to give this variable a definition (the initializer above is only a
501 // declaration), so that subclasses can use it.
502 const int ThreadedTesterBase::numberOfThreads;
503
500 class ThreadedHeapTester : public ThreadedTesterBase { 504 class ThreadedHeapTester : public ThreadedTesterBase {
501 public: 505 public:
502 static void test() 506 static void test()
503 { 507 {
504 ThreadedTesterBase::test(new ThreadedHeapTester); 508 ThreadedTesterBase::test(new ThreadedHeapTester);
505 } 509 }
506 510
507 protected: 511 protected:
508 using GlobalIntWrapperPersistent = CrossThreadPersistent<IntWrapper>; 512 using GlobalIntWrapperPersistent = CrossThreadPersistent<IntWrapper>;
509 513
(...skipping 5966 matching lines...) Expand 10 before | Expand all | Expand 10 after
6476 6480
6477 persistentHeapVectorIntWrapper.append(&intWrapper); 6481 persistentHeapVectorIntWrapper.append(&intWrapper);
6478 heapVectorIntWrapper.append(&intWrapper); 6482 heapVectorIntWrapper.append(&intWrapper);
6479 EXPECT_EQ(1u, persistentHeapVectorIntWrapper.size()); 6483 EXPECT_EQ(1u, persistentHeapVectorIntWrapper.size());
6480 EXPECT_EQ(1u, heapVectorIntWrapper.size()); 6484 EXPECT_EQ(1u, heapVectorIntWrapper.size());
6481 6485
6482 EXPECT_EQ(persistentHeapVectorIntWrapper[0], heapVectorIntWrapper[0]); 6486 EXPECT_EQ(persistentHeapVectorIntWrapper[0], heapVectorIntWrapper[0]);
6483 EXPECT_EQ(33, heapVectorIntWrapper[0]->value()); 6487 EXPECT_EQ(33, heapVectorIntWrapper[0]->value());
6484 } 6488 }
6485 6489
6490 namespace {
6491
6492 class ThreadedClearOnShutdownTester : public ThreadedTesterBase {
6493 public:
6494 static void test()
6495 {
6496 IntWrapper::s_destructorCalls = 0;
6497 ThreadedTesterBase::test(new ThreadedClearOnShutdownTester);
6498 EXPECT_EQ(numberOfThreads, IntWrapper::s_destructorCalls);
6499 }
6500
6501 private:
6502 void runThread() override
6503 {
6504 ThreadState::attach();
6505 EXPECT_EQ(42, threadSpecificIntWrapper().value());
6506 ThreadState::detach();
6507 atomicDecrement(&m_threadsToFinish);
6508 }
6509
6510 static IntWrapper& threadSpecificIntWrapper()
6511 {
6512 DEFINE_THREAD_SAFE_STATIC_LOCAL(
6513 ThreadSpecific<Persistent<IntWrapper>>, intWrapper,
6514 new ThreadSpecific<Persistent<IntWrapper>>);
6515 Persistent<IntWrapper>& handle = *intWrapper;
6516 if (!handle) {
6517 handle = new IntWrapper(42);
6518 handle.clearOnThreadShutdown();
6519 }
6520 return *handle;
6521 }
6522 };
6523
6524 } // namespace
6525
6526 TEST(HeapTest, TestClearOnShutdown)
6527 {
6528 ThreadedClearOnShutdownTester::test();
6529 }
6530
6486 } // namespace blink 6531 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698